Hi,
I am studying examples of race condition in real embedded systems.
From the commit log of paparazzi, I found the following "race condition" description between revision 5348 and 5349.
Can someone explain more detailed information about what this problem is?
Thanks
------------------------------------------------------------------------
r5349 | poine | 2010-08-12 16:36:29 -0500 (Thu, 12 Aug 2010) | 2 lines
removed a race condition in the timeout detection of the overo_link
------------------------------------------------------------------------
Index: sw/airborne/lisa/lisa_overo_link.c
===================================================================
--- sw/airborne/lisa/lisa_overo_link.c (revision 5348)
+++ sw/airborne/lisa/lisa_overo_link.c (revision 5349)
@@ -4,10 +4,11 @@
void overo_link_init(void) {
overo_link.status = IDLE;
- overo_link.timeout = OVERO_LINK_TIMEOUT-1;
+ overo_link.timeout_cnt = OVERO_LINK_TIMEOUT-1;
overo_link.msg_cnt = 0;
overo_link.crc_err_cnt = 0;
overo_link.crc_error = FALSE;
+ overo_link.timeout = FALSE;
overo_link_arch_init();
}
Index: sw/airborne/lisa/lisa_overo_link.h
===================================================================
--- sw/airborne/lisa/lisa_overo_link.h (revision 5348)
+++ sw/airborne/lisa/lisa_overo_link.h (revision 5349)
@@ -21,8 +21,10 @@
struct OVERO_LINK_MSG_DOWN msg;
uint8_t array[sizeof(union AutopilotMessage)];
} down;
+ uint8_t timeout_cnt;
+ /* flags used to reset hardware */
+ uint8_t crc_error;
uint8_t timeout;
- uint8_t crc_error;
};
extern struct LisaOveroLink overo_link;
@@ -36,21 +38,44 @@
#include "lisa_overo_link_arch.h"
+#if 0 /* that doesn't work yet */
#define OveroLinkPeriodic(_timeout_handler) { \
- if (overo_link.timeout < OVERO_LINK_TIMEOUT) \
- overo_link.timeout++; \
+ if (overo_link.timeout_cnt < OVERO_LINK_TIMEOUT) \
+ overo_link.timeout_cnt++; \
else { \
if (overo_link.status != LOST && overo_link.status != DATA_AVAILABLE ) { \
+ SPI_Cmd(SPI1, DISABLE); \
overo_link.status = LOST; \
LED_OFF(OVERO_LINK_LED_OK); \
LED_ON(OVERO_LINK_LED_KO); \
+ overo_link.timeout = TRUE; \
_timeout_handler(); \
} \
} \
}
+#else /* this one does */
+#define OveroLinkPeriodic(_timeout_handler) { \
+ if (overo_link.timeout_cnt < OVERO_LINK_TIMEOUT) \
+ overo_link.timeout_cnt++; \
+ else { \
+ __disable_irq(); \
+ if (overo_link.status != LOST && overo_link.status != DATA_AVAILABLE ) { \
+ overo_link.status = LOST; \
+ __enable_irq(); \
+ LED_OFF(OVERO_LINK_LED_OK); \
+ LED_ON(OVERO_LINK_LED_KO); \
+ _timeout_handler(); \
+ } \
+ __enable_irq(); \
+ } \
+ }
+#endif
+
+
+
/*
*
* Passing telemetry through Overo Link
Index: sw/airborne/lisa/arch/stm32/lisa_overo_link_arch.h
===================================================================
--- sw/airborne/lisa/arch/stm32/lisa_overo_link_arch.h (revision 5348)
+++ sw/airborne/lisa/arch/stm32/lisa_overo_link_arch.h (revision 5349)
@@ -5,11 +5,11 @@
#define OveroLinkEvent(_data_received_handler, _crc_failed_handler) { \
- if (overo_link.status == DATA_AVAILABLE) { /* set by DMA interrupt */ \
+ if (overo_link.status == DATA_AVAILABLE) { /* set by DMA interrupt */ \
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)==RESET); \
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) ==RESET); \
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) ==SET); \
- overo_link.timeout = 0; \
+ overo_link.timeout_cnt = 0; \
if((SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_CRCERR)) == RESET) { \
LED_ON(OVERO_LINK_LED_OK); \
LED_OFF(OVERO_LINK_LED_KO); \
@@ -32,6 +32,11 @@
overo_link_arch_prepare_next_transfert(); \
overo_link.crc_error = FALSE; \
} \
+ if (overo_link.timeout && /* if we've had a timeout */ \
+ !GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)) { /* and we're not selected anymore */ \
+ overo_link_arch_prepare_next_transfert(); \
+ overo_link.timeout = FALSE; \
+ } \
}
--
Heechul
_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel