From 5512364835b89c2e2599bd19b76c8b08236fa089 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 6 Apr 2013 15:25:21 +0200 Subject: digital/{ai,asserv,mimot}: reserve sequence number 0 for transient commands --- digital/ai/src/twi_master/twi_master.c | 7 +++++-- digital/asserv/src/asserv/twi_proto.c | 4 ++-- digital/mimot/src/dirty/twi_proto.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'digital') diff --git a/digital/ai/src/twi_master/twi_master.c b/digital/ai/src/twi_master/twi_master.c index 6029fd1d..a0117f6e 100644 --- a/digital/ai/src/twi_master/twi_master.c +++ b/digital/ai/src/twi_master/twi_master.c @@ -217,7 +217,10 @@ twi_master_send_buffer (uint8_t length) struct twi_master_command_t *c = &twi_master.pending[TWI_MASTER_PENDING_TAIL]; /* Fill sequence number, compute CRC, store length. */ - c->command[1] = ++twi_master_slaves[c->slave].seq; + twi_master_slaves[c->slave].seq++; + if (twi_master_slaves[c->slave].seq == 0) + twi_master_slaves[c->slave].seq = 1; + c->command[1] = twi_master_slaves[c->slave].seq; c->command[0] = crc_compute (&c->command[1], length + 1); c->length = length + 2; /* Add to the list of pending command. */ @@ -234,7 +237,7 @@ twi_master_send_transient_buffer (uint8_t length) struct twi_master_command_t *c = &twi_master.pending[TWI_MASTER_PENDING_TAIL]; /* Fill sequence number, compute CRC, store length. */ - c->command[1] = ++twi_master_slaves[c->slave].seq; + c->command[1] = 0; c->command[0] = crc_compute (&c->command[1], length + 1); c->length = length + 2; /* Send right now without acknowledgement. */ diff --git a/digital/asserv/src/asserv/twi_proto.c b/digital/asserv/src/asserv/twi_proto.c index d687be48..686f236b 100644 --- a/digital/asserv/src/asserv/twi_proto.c +++ b/digital/asserv/src/asserv/twi_proto.c @@ -119,8 +119,8 @@ twi_proto_callback (u8 *buf, u8 size) buf += 1; size -= 1; } - - if (buf[0] == twi_proto.seq) + /* Handle sequence number. */ + if (buf[0] == 0 || buf[0] == twi_proto.seq) return; #define c(cmd, size) (cmd) switch (c (buf[1], 0)) diff --git a/digital/mimot/src/dirty/twi_proto.c b/digital/mimot/src/dirty/twi_proto.c index f452fdc4..ceecba5f 100644 --- a/digital/mimot/src/dirty/twi_proto.c +++ b/digital/mimot/src/dirty/twi_proto.c @@ -100,8 +100,8 @@ twi_proto_callback (u8 *buf, u8 size) buf += 1; size -= 1; } - - if (buf[0] == twi_proto.seq) + /* Handle sequence number. */ + if (buf[0] == 0 || buf[0] == twi_proto.seq) return; #define c(cmd, size) (cmd) switch (c (buf[1], 0)) -- cgit v1.2.3