summaryrefslogtreecommitdiff
path: root/digital/io/src/asserv.c
diff options
context:
space:
mode:
authorJérémy Dufour2008-04-14 11:59:50 +0200
committerJérémy Dufour2008-04-14 11:59:50 +0200
commit344378dbe88fef666e0577cdbf57498f3800172f (patch)
treea26f5108ccae90afb0f7825f7ef02a90c291267b /digital/io/src/asserv.c
parent866e9ecb695b0a797ee7854cd3113abcd04ded6f (diff)
* digital/io/src
- manage command retransmission (when not acknowledge by the asserv) ; - integrate retransmission and update of the asserv into the main.
Diffstat (limited to 'digital/io/src/asserv.c')
-rw-r--r--digital/io/src/asserv.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/digital/io/src/asserv.c b/digital/io/src/asserv.c
index 97cd2650..66f407a8 100644
--- a/digital/io/src/asserv.c
+++ b/digital/io/src/asserv.c
@@ -73,6 +73,21 @@ typedef struct asserv_struct_s
asserv_struct_s asserv_status;
/**
+ * Retransmit counter initial value.
+ */
+#define ASSERV_RETRANSMIT_COUNT 10
+
+/**
+ * Retransmit counter.
+ */
+static uint8_t asserv_retransmit_counter;
+
+/**
+ * Length of the last transmitted command.
+ */
+static uint8_t asserv_retransmit_length;
+
+/**
* Update TWI module until request (send or receive) is finished.
* This functions is blocking.
*/
@@ -93,6 +108,20 @@ asserv_twi_update (void);
static inline uint8_t
asserv_twi_send_command (uint8_t command, uint8_t length);
+/**
+ * Send a prepared command to the asserv board using TWI module.
+ * It will reset the counter retransmission value and store the length for
+ * future retransmission.
+ * In comparison with \a asserv_twi_send_command this function is internal and
+ * used by \a asserv_twi_send_command.
+ * @param length th length of the complete command with parameters.
+ * @return
+ * - 0 if no error occurred.
+ * - 1 if TWI transmission failed.
+ */
+static inline uint8_t
+asserv_twi_send (uint8_t length);
+
/* Update TWI module until request (send or receive) is finished. */
static inline void
asserv_twi_update (void)
@@ -114,12 +143,26 @@ asserv_twi_send_command (uint8_t command, uint8_t length)
/* Put the sequence number */
asserv_twi_buffer[1] = ++asserv_twi_seq;
+ /* Send the prepared command */
+ return asserv_twi_send (length + 2);
+}
+
+/* Send a prepared command to the asserv board using TWI module. */
+static inline uint8_t
+asserv_twi_send (uint8_t length)
+{
/* Send command to the asserv */
- if (twi_ms_send (AC_ASSERV_TWI_ADDRESS, asserv_twi_buffer, length + 2) != 0)
+ if (twi_ms_send (AC_ASSERV_TWI_ADDRESS, asserv_twi_buffer, length) != 0)
return 1;
/* Update until the command is sent */
asserv_twi_update ();
+
+ /* Reset retransmit counter */
+ asserv_retransmit_counter = ASSERV_RETRANSMIT_COUNT;
+ /* Store length for retransmission */
+ asserv_retransmit_length = length;
+
return 0;
}
/** @} */
@@ -164,6 +207,23 @@ asserv_last_cmd_ack (void)
return (asserv_status.seq == asserv_twi_seq);
}
+/**
+ * Re-send command if not acknowledged.
+ */
+uint8_t
+asserv_retransmit (void)
+{
+ /* Check if we have reached the maximum number of check before
+ * retransmission */
+ if (--asserv_retransmit_counter == 0)
+ {
+ /* Retransmit! */
+ asserv_twi_send (asserv_retransmit_length);
+ return 1;
+ }
+ return 0;
+}
+
/* Is last move class command has successfully ended? */
asserv_status_e
asserv_move_cmd_status (void)