summaryrefslogtreecommitdiffhomepage
path: root/digital/ai
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-16 18:58:29 +0100
committerNicolas Schodet2013-03-16 18:58:29 +0100
commit8f7c312ad1fe132c5279a0f5d0101834acf5857d (patch)
tree6884a21c1aa8fa28dac790e0443d0c2a2aee0d9b /digital/ai
parent49f4a007eebbf5bc1ac3a9c2c86d742963547875 (diff)
digital/{ai,asserv,beacon,io,mimot}: change the seq position in i2c status
Diffstat (limited to 'digital/ai')
-rw-r--r--digital/ai/src/twi_master/asserv.c10
-rw-r--r--digital/ai/src/twi_master/asserv.h4
-rw-r--r--digital/ai/src/twi_master/beacon.c2
-rw-r--r--digital/ai/src/twi_master/beacon.h4
-rw-r--r--digital/ai/src/twi_master/mimot.c4
-rw-r--r--digital/ai/src/twi_master/mimot.h4
-rw-r--r--digital/ai/src/twi_master/twi_master.c41
-rw-r--r--digital/ai/src/twi_master/twi_master.h12
8 files changed, 38 insertions, 43 deletions
diff --git a/digital/ai/src/twi_master/asserv.c b/digital/ai/src/twi_master/asserv.c
index cff3587b..cddf12fa 100644
--- a/digital/ai/src/twi_master/asserv.c
+++ b/digital/ai/src/twi_master/asserv.c
@@ -126,12 +126,12 @@ asserv_status_cb (uint8_t *status)
/* Parse received data and store them. */
asserv_status.status = status[0];
asserv_status.input_port = status[1];
- asserv_status.position.x = v8_to_v32 (0, status[3], status[4], status[5]);
- asserv_status.position.y = v8_to_v32 (0, status[6], status[7], status[8]);
- asserv_status.position.a = v8_to_v16 (status[9], status[10]);
+ asserv_status.position.x = v8_to_v32 (0, status[2], status[3], status[4]);
+ asserv_status.position.y = v8_to_v32 (0, status[5], status[6], status[7]);
+ asserv_status.position.a = v8_to_v16 (status[8], status[9]);
#if AC_ASSERV_AUX_NB
- asserv_status.motor0_position = v8_to_v16 (status[11], status[12]);
- asserv_status.motor1_position = v8_to_v16 (status[13], status[14]);
+ asserv_status.motor0_position = v8_to_v16 (status[10], status[11]);
+ asserv_status.motor1_position = v8_to_v16 (status[12], status[13]);
#endif
/* Update moving direction. */
if (asserv_get_moving_direction () != 0)
diff --git a/digital/ai/src/twi_master/asserv.h b/digital/ai/src/twi_master/asserv.h
index ac2ba146..88a3e4ef 100644
--- a/digital/ai/src/twi_master/asserv.h
+++ b/digital/ai/src/twi_master/asserv.h
@@ -35,8 +35,8 @@
/** Asserv TWI address. */
#define ASSERV_TWI_ADDRESS 4
-/** Length of the status buffer (not including CRC). */
-#define ASSERV_STATUS_LENGTH (11 + AC_ASSERV_AUX_NB * 2)
+/** Length of the status payload (not including CRC & seq). */
+#define ASSERV_STATUS_LENGTH (10 + AC_ASSERV_AUX_NB * 2)
/** Use backward movements. */
#define ASSERV_BACKWARD 1
diff --git a/digital/ai/src/twi_master/beacon.c b/digital/ai/src/twi_master/beacon.c
index 88c618c3..6fbb5219 100644
--- a/digital/ai/src/twi_master/beacon.c
+++ b/digital/ai/src/twi_master/beacon.c
@@ -56,7 +56,7 @@ beacon_init (void)
void
beacon_status_cb (uint8_t *status)
{
- uint8_t i, index = 3;
+ uint8_t i, index = 0;
for (i = 0; i < AC_BEACON_POSITION_NB; i++)
{
beacon.position[i].x = v8_to_v16 (status[index], status[index + 1]);
diff --git a/digital/ai/src/twi_master/beacon.h b/digital/ai/src/twi_master/beacon.h
index 767dc21c..3b16b250 100644
--- a/digital/ai/src/twi_master/beacon.h
+++ b/digital/ai/src/twi_master/beacon.h
@@ -31,8 +31,8 @@
/** Beacon TWI address. */
#define BEACON_TWI_ADDRESS 10
-/** Length of status buffer (not including CRC). */
-#define BEACON_STATUS_LENGTH (3 + 5 * AC_BEACON_POSITION_NB)
+/** Length of status payload (not including CRC & seq). */
+#define BEACON_STATUS_LENGTH (5 * AC_BEACON_POSITION_NB)
/** Initialise module. */
void
diff --git a/digital/ai/src/twi_master/mimot.c b/digital/ai/src/twi_master/mimot.c
index ff73fdb7..65bd575e 100644
--- a/digital/ai/src/twi_master/mimot.c
+++ b/digital/ai/src/twi_master/mimot.c
@@ -71,8 +71,8 @@ mimot_status_cb (uint8_t *status)
/* Parse received data and store them. */
mimot_status.status = status[0];
mimot_status.input_port = status[1];
- mimot_status.motor0_position = v8_to_v16 (status[3], status[4]);
- mimot_status.motor1_position = v8_to_v16 (status[5], status[6]);
+ mimot_status.motor0_position = v8_to_v16 (status[2], status[3]);
+ mimot_status.motor1_position = v8_to_v16 (status[4], status[5]);
}
asserv_status_e
diff --git a/digital/ai/src/twi_master/mimot.h b/digital/ai/src/twi_master/mimot.h
index 78f0a8c9..abccd9f6 100644
--- a/digital/ai/src/twi_master/mimot.h
+++ b/digital/ai/src/twi_master/mimot.h
@@ -33,8 +33,8 @@
/** Mimot TWI address. */
#define MIMOT_TWI_ADDRESS 6
-/** Length of status buffer (not including CRC). */
-#define MIMOT_STATUS_LENGTH 7
+/** Length of status payload (not including CRC & seq). */
+#define MIMOT_STATUS_LENGTH 6
/** Initialise module. */
void
diff --git a/digital/ai/src/twi_master/twi_master.c b/digital/ai/src/twi_master/twi_master.c
index d9cc9ac5..6029fd1d 100644
--- a/digital/ai/src/twi_master/twi_master.c
+++ b/digital/ai/src/twi_master/twi_master.c
@@ -42,14 +42,11 @@
/** Interval between retransmissions. */
#define TWI_MASTER_RETRANSMIT_INTERVAL 10
-/** Index of the slave sequence number. */
-#define TWI_MASTER_STATUS_SEQ_INDEX 2
-
/** Maximum command payload size. */
-#define TWI_MASTER_COMMAND_PAYLOAD_MAX 13
+#define TWI_MASTER_COMMAND_PAYLOAD_MAX 12
/** Maximum status payload size. */
-#define TWI_MASTER_STATUS_PAYLOAD_MAX 15
+#define TWI_MASTER_STATUS_PAYLOAD_MAX 14
/** Maximum number of pending commands. */
#define TWI_MASTER_PENDING_MAX 16
@@ -64,9 +61,9 @@ struct twi_master_command_t
{
/** Addressed slave index. */
uint8_t slave;
- /** Command payload with space for CRC. */
- uint8_t command[TWI_MASTER_COMMAND_PAYLOAD_MAX + 1];
- /** Command length not including CRC. */
+ /** Command payload with space for CRC & seq. */
+ uint8_t command[TWI_MASTER_COMMAND_PAYLOAD_MAX + 2];
+ /** Command length including CRC & seq. */
uint8_t length;
};
@@ -87,7 +84,7 @@ struct twi_master_t
} twi_master;
/** Callback called when a slave status has been read.
- * - status: status buffer (without CRC). */
+ * - status: status payload (without CRC & seq). */
typedef void (*twi_master_slave_status_cb) (uint8_t *status);
/** Information on a slave. */
@@ -97,7 +94,7 @@ struct twi_master_slave_t
uint8_t address;
/** Last command sequence number. */
uint8_t seq;
- /** Size of the status buffer not including CRC. */
+ /** Size of the status payload not including CRC & seq. */
uint8_t status_length;
/** Status callback. */
twi_master_slave_status_cb status_cb;
@@ -126,7 +123,7 @@ twi_master_send_head (void)
&twi_master.pending[twi_master.pending_head];
/* Send command. */
twi_master_send (twi_master_slaves[c->slave].address, c->command,
- c->length + 1);
+ c->length);
twi_master_wait ();
/* Reset retransmission counter. */
twi_master.retransmit_counter = TWI_MASTER_RETRANSMIT_INTERVAL;
@@ -137,29 +134,27 @@ twi_master_send_head (void)
static uint8_t
twi_master_update_status (uint8_t slave, uint8_t init)
{
- uint8_t buffer[TWI_MASTER_STATUS_PAYLOAD_MAX + 1];
+ uint8_t buffer[TWI_MASTER_STATUS_PAYLOAD_MAX + 2];
/* Read status. */
twi_master_recv (twi_master_slaves[slave].address, buffer,
- twi_master_slaves[slave].status_length + 1);
+ twi_master_slaves[slave].status_length + 2);
uint8_t ret = twi_master_wait ();
- if (ret != twi_master_slaves[slave].status_length + 1)
+ if (ret != twi_master_slaves[slave].status_length + 2)
return 0;
uint8_t crc = crc_compute (buffer + 1,
- twi_master_slaves[slave].status_length);
+ twi_master_slaves[slave].status_length + 1);
if (crc != buffer[0])
return 0;
if (init)
- twi_master_slaves[slave].seq =
- buffer[1 + TWI_MASTER_STATUS_SEQ_INDEX];
+ twi_master_slaves[slave].seq = buffer[1];
/* Call user callback. */
- twi_master_slaves[slave].status_cb (buffer + 1);
+ twi_master_slaves[slave].status_cb (buffer + 2);
/* Update pending command list. */
if (twi_master.pending_nb)
{
struct twi_master_command_t *c =
&twi_master.pending[twi_master.pending_head];
- if (slave == c->slave
- && buffer[1 + TWI_MASTER_STATUS_SEQ_INDEX] == c->command[1])
+ if (slave == c->slave && buffer[1] == c->command[1])
{
/* Successfully acknowledged. */
twi_master.pending_nb--;
@@ -224,7 +219,7 @@ twi_master_send_buffer (uint8_t length)
/* Fill sequence number, compute CRC, store length. */
c->command[1] = ++twi_master_slaves[c->slave].seq;
c->command[0] = crc_compute (&c->command[1], length + 1);
- c->length = length + 1;
+ c->length = length + 2;
/* Add to the list of pending command. */
twi_master.pending_nb++;
/* Early transmission. */
@@ -241,10 +236,10 @@ twi_master_send_transient_buffer (uint8_t length)
/* Fill sequence number, compute CRC, store length. */
c->command[1] = ++twi_master_slaves[c->slave].seq;
c->command[0] = crc_compute (&c->command[1], length + 1);
- c->length = length + 1;
+ c->length = length + 2;
/* Send right now without acknowledgement. */
twi_master_send (twi_master_slaves[c->slave].address, c->command,
- c->length + 1);
+ c->length);
twi_master_wait ();
}
diff --git a/digital/ai/src/twi_master/twi_master.h b/digital/ai/src/twi_master/twi_master.h
index f2f8dff7..7bf17ebe 100644
--- a/digital/ai/src/twi_master/twi_master.h
+++ b/digital/ai/src/twi_master/twi_master.h
@@ -32,13 +32,13 @@
* - a message sent to the slave with a command to execute,
* - a status read from the slave containing the current slave state.
*
- * The first byte of all messages is a CRC of the following bytes, called the
- * message payload.
+ * The first byte of all messages is a CRC of the following bytes.
*
- * The first byte of payload sent to slave is the command sequence number. It
- * is used by the master to know if its command has been handled. The last
- * handled command sequence number is available in the slave status (third
- * byte).
+ * The next byte is the command sequence number. It is used by the master to
+ * know if its command has been handled. The last handled command sequence
+ * number is available in the slave status.
+ *
+ * All other bytes are the message payload.
*
* As long as the slave last command sequence number is not equal to the last
* sent sequence number, the master can not send any other command. If the