From c957172f8f2abfbf9b319152aefb86855fcf124c Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 14 Feb 2012 11:05:48 -0600 Subject: [PATCH] In the case of swapping in userspace due to the buffer being blocked during ISR, make sure the latency is less than 50 us to avoid framesync errors. Still seeing a few nonsense packets on Overo side but fairly few. Probably need to add CRC to whole packet now and call it done. --- flight/Modules/OveroSync/overosync.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flight/Modules/OveroSync/overosync.c b/flight/Modules/OveroSync/overosync.c index 9d7bdf90e..bafb58ffa 100644 --- a/flight/Modules/OveroSync/overosync.c +++ b/flight/Modules/OveroSync/overosync.c @@ -48,6 +48,7 @@ static xQueueHandle queue; static UAVTalkConnection uavTalkCon; static xTaskHandle overoSyncTaskHandle; volatile bool buffer_swap_failed; +volatile uint32_t buffer_swap_timeval; // Private functions static void overoSyncTask(void *parameters); @@ -281,6 +282,7 @@ static void transmitDataDone(bool crc_ok, uint8_t crc_val) * \return -1 on failure * \return number of bytes transmitted on success */ +uint32_t too_long = 0; static int32_t packData(uint8_t * data, int32_t length) { uint8_t *tx_buffer; @@ -312,9 +314,12 @@ static int32_t packData(uint8_t * data, int32_t length) // When the NSS line rises while we are packing data then a transaction doesn't start // because that means we will be here very shortly afterwards (priority of task making that // not always perfectly true) schedule the transaction here. - if (buffer_swap_failed) { + if (buffer_swap_failed && (PIOS_DELAY_DiffuS(buffer_swap_timeval) < 50)) { buffer_swap_failed = false; transmitData(); + } else if (buffer_swap_failed) { + buffer_swap_failed = false; + too_long++; } return length; @@ -335,6 +340,7 @@ static int32_t transmitData() xSemaphoreGiveFromISR(overosync->transaction_lock, &xHigherPriorityTaskWoken); portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); buffer_swap_failed = true; + buffer_swap_timeval = PIOS_DELAY_GetRaw(); return -2; }