From 8f7c312ad1fe132c5279a0f5d0101834acf5857d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 16 Mar 2013 18:58:29 +0100 Subject: digital/{ai,asserv,beacon,io,mimot}: change the seq position in i2c status --- digital/ai/src/twi_master/asserv.c | 10 ++++---- digital/ai/src/twi_master/asserv.h | 4 ++-- digital/ai/src/twi_master/beacon.c | 2 +- digital/ai/src/twi_master/beacon.h | 4 ++-- digital/ai/src/twi_master/mimot.c | 4 ++-- digital/ai/src/twi_master/mimot.h | 4 ++-- digital/ai/src/twi_master/twi_master.c | 41 ++++++++++++++------------------ digital/ai/src/twi_master/twi_master.h | 12 +++++----- digital/asserv/src/asserv/twi_proto.c | 6 ++--- digital/beacon/src/stub/simu_stub.host.c | 2 -- digital/beacon/src/twi_specific.c | 2 -- digital/beacon/src/twi_specific.h | 4 +--- digital/io/doc/proto_asserv.txt | 8 +++---- digital/mimot/src/dirty/twi_proto.c | 6 ++--- 14 files changed, 49 insertions(+), 60 deletions(-) (limited to 'digital') 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 diff --git a/digital/asserv/src/asserv/twi_proto.c b/digital/asserv/src/asserv/twi_proto.c index 3d4bf663..d687be48 100644 --- a/digital/asserv/src/asserv/twi_proto.c +++ b/digital/asserv/src/asserv/twi_proto.c @@ -72,7 +72,8 @@ twi_proto_update (void) /* Update status. */ u8 status_with_crc[12 + AC_ASSERV_AUX_NB * 2]; u8 *status = &status_with_crc[1]; - status[0] = 0 + status[0] = twi_proto.seq; + status[1] = 0 #if AC_ASSERV_AUX_NB | (control_state_is_blocked (&cs_aux[1].state) ? (1 << 7) : 0) | (control_state_is_finished (&cs_aux[1].state) ? (1 << 6) : 0) @@ -83,8 +84,7 @@ twi_proto_update (void) | (cs_main.speed_theta.cur_f > 0 ? (1 << 2) : 0) | (control_state_is_blocked (&cs_main.state) ? (1 << 1) : 0) | (control_state_is_finished (&cs_main.state) ? (1 << 0) : 0); - status[1] = PINC; - status[2] = twi_proto.seq; + status[2] = PINC; status[3] = v32_to_v8 (postrack_x, 3); status[4] = v32_to_v8 (postrack_x, 2); status[5] = v32_to_v8 (postrack_x, 1); diff --git a/digital/beacon/src/stub/simu_stub.host.c b/digital/beacon/src/stub/simu_stub.host.c index 38cf93fb..295ba1c5 100644 --- a/digital/beacon/src/stub/simu_stub.host.c +++ b/digital/beacon/src/stub/simu_stub.host.c @@ -78,8 +78,6 @@ simu_twi_proto_update (void) /* Update TWI slave buffer after each position update. */ uint8_t status[4 + 5 * UTILS_COUNT (simu_positions)]; uint8_t i, index = 1; - status[index++] = 0; - status[index++] = 0; status[index++] = simu_seq; for (i = 0; i < UTILS_COUNT (simu_positions); i++) { diff --git a/digital/beacon/src/twi_specific.c b/digital/beacon/src/twi_specific.c index d646546d..9bd35f5e 100644 --- a/digital/beacon/src/twi_specific.c +++ b/digital/beacon/src/twi_specific.c @@ -43,8 +43,6 @@ void twi_task(void) uint8_t RXlen; static uint8_t seq = 0; - TXbuffer[TWI_TX_RFU1_FIELD] = 0; - TXbuffer[TWI_TX_RFU2_FIELD] = 0; TXbuffer[TWI_TX_SEQ_FIELD] = seq; /* Opponent 1 */ diff --git a/digital/beacon/src/twi_specific.h b/digital/beacon/src/twi_specific.h index fc9a06c1..1aac01d0 100644 --- a/digital/beacon/src/twi_specific.h +++ b/digital/beacon/src/twi_specific.h @@ -45,8 +45,6 @@ typedef enum typedef enum { TWI_TX_CRC_FIELD, - TWI_TX_RFU1_FIELD, - TWI_TX_RFU2_FIELD, TWI_TX_SEQ_FIELD, TWI_TX_X1_MSB_FIELD, TWI_TX_X1_LSB_FIELD, @@ -67,4 +65,4 @@ void twi_task(void); /* Initialisze specific TWI */ void twi_init_specific(void); -#endif \ No newline at end of file +#endif diff --git a/digital/io/doc/proto_asserv.txt b/digital/io/doc/proto_asserv.txt index 259b0905..9b9a7451 100644 --- a/digital/io/doc/proto_asserv.txt +++ b/digital/io/doc/proto_asserv.txt @@ -150,10 +150,10 @@ the current position (X, Y, alpha) of the bot and its motors. The buffer is a static 12 bytes length one:: - 0 1 2 3 .. 5 6 .. 8 9 10 11 12 13 14 <-- byte position - +--------+------+-----+- - - -+- - - -+-------+----------+----------+ - | status | PINC | seq | X pos | Y pos | angle | mot0 pos | mot1 pos | - +--------+------+-----+- - - -+- - - -+-------+----------+----------+ + 0 1 2 3 .. 5 6 .. 8 9 10 11 12 13 14 <-- byte position + +-----+--------+------+- - - -+- - - -+-------+----------+----------+ + | seq | status | PINC | X pos | Y pos | angle | mot0 pos | mot1 pos | + +-----+--------+------+- - - -+- - - -+-------+----------+----------+ Status value diff --git a/digital/mimot/src/dirty/twi_proto.c b/digital/mimot/src/dirty/twi_proto.c index 2de2b1a1..f452fdc4 100644 --- a/digital/mimot/src/dirty/twi_proto.c +++ b/digital/mimot/src/dirty/twi_proto.c @@ -70,13 +70,13 @@ twi_proto_update (void) /* Update status. */ u8 status_with_crc[8]; u8 *status = &status_with_crc[1]; - status[0] = 0 + status[0] = twi_proto.seq; + status[1] = 0 | (control_state_is_blocked (&cs_aux[1].state) ? (1 << 3) : 0) | (control_state_is_finished (&cs_aux[1].state) ? (1 << 2) : 0) | (control_state_is_blocked (&cs_aux[0].state) ? (1 << 1) : 0) | (control_state_is_finished (&cs_aux[0].state) ? (1 << 0) : 0); - status[1] = PINC; - status[2] = twi_proto.seq; + status[2] = PINC; status[3] = v16_to_v8 (aux[0].pos, 1); status[4] = v16_to_v8 (aux[0].pos, 0); status[5] = v16_to_v8 (aux[1].pos, 1); -- cgit v1.2.3