From 21b0049a68ddb0a4e81335864cb68a693004b1c0 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Tue, 11 Feb 2014 16:51:56 +0100 Subject: [PATCH 1/3] OP-1218 fix missing "ret =" --- flight/modules/RadioComBridge/RadioComBridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/modules/RadioComBridge/RadioComBridge.c b/flight/modules/RadioComBridge/RadioComBridge.c index 55fb1f1e4..c9aa96c39 100644 --- a/flight/modules/RadioComBridge/RadioComBridge.c +++ b/flight/modules/RadioComBridge/RadioComBridge.c @@ -518,7 +518,7 @@ static void serialRxTask(__attribute__((unused)) void *parameters) int32_t ret = -2; uint8_t count = 5; while(count-- > 0 && ret < -1){ - PIOS_COM_SendBufferNonBlocking(PIOS_COM_RADIO, data->serialRxBuf, bytes_to_process); + ret = PIOS_COM_SendBufferNonBlocking(PIOS_COM_RADIO, data->serialRxBuf, bytes_to_process); } } } else { From 8cd5cfe2ebb424eb1b48f1b563c39ef1d3b85a25 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 15 Feb 2014 17:20:45 +0100 Subject: [PATCH 2/3] OP-1218 format/consmetic/comments fixes --- .../modules/RadioComBridge/RadioComBridge.c | 14 ++--- flight/pios/common/pios_com.c | 57 ++++++++++--------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/flight/modules/RadioComBridge/RadioComBridge.c b/flight/modules/RadioComBridge/RadioComBridge.c index c9aa96c39..be3eae65b 100644 --- a/flight/modules/RadioComBridge/RadioComBridge.c +++ b/flight/modules/RadioComBridge/RadioComBridge.c @@ -415,9 +415,9 @@ static void radioRxTask(__attribute__((unused)) void *parameters) // Send the data straight to the telemetry port. // FIXME following call can fail (with -2 error code) if buffer is full // it is the caller responsibility to retry in such cases... - int32_t ret = -2; + int32_t ret = -2; uint8_t count = 5; - while(count-- > 0 && ret < -1){ + while (count-- > 0 && ret < -1) { ret = PIOS_COM_SendBufferNonBlocking(PIOS_COM_TELEMETRY, serial_data, bytes_to_process); } } @@ -515,9 +515,9 @@ static void serialRxTask(__attribute__((unused)) void *parameters) // Send the data over the radio link. // FIXME following call can fail (with -2 error code) if buffer is full // it is the caller responsibility to retry in such cases... - int32_t ret = -2; + int32_t ret = -2; uint8_t count = 5; - while(count-- > 0 && ret < -1){ + while (count-- > 0 && ret < -1) { ret = PIOS_COM_SendBufferNonBlocking(PIOS_COM_RADIO, data->serialRxBuf, bytes_to_process); } } @@ -551,7 +551,7 @@ static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length) // it is the caller responsibility to retry in such cases... ret = -2; uint8_t count = 5; - while(count-- > 0 && ret < -1){ + while (count-- > 0 && ret < -1) { ret = PIOS_COM_SendBufferNonBlocking(outputPort, buf, length); } } else { @@ -579,9 +579,9 @@ static int32_t RadioSendHandler(uint8_t *buf, int32_t length) if (outputPort && PIOS_COM_Available(outputPort)) { // FIXME following call can fail (with -2 error code) if buffer is full // it is the caller responsibility to retry in such cases... - int32_t ret = -2; + int32_t ret = -2; uint8_t count = 5; - while(count-- > 0 && ret < -1){ + while (count-- > 0 && ret < -1) { ret = PIOS_COM_SendBufferNonBlocking(outputPort, buf, length); } return ret; diff --git a/flight/pios/common/pios_com.c b/flight/pios/common/pios_com.c index 31f67176a..a467aad28 100644 --- a/flight/pios/common/pios_com.c +++ b/flight/pios/common/pios_com.c @@ -274,35 +274,35 @@ int32_t PIOS_COM_ChangeBaud(uint32_t com_id, uint32_t baud) static int32_t PIOS_COM_SendBufferNonBlockingInternal(struct pios_com_dev *com_dev, const uint8_t *buffer, uint16_t len) { -PIOS_Assert(com_dev); -PIOS_Assert(com_dev->has_tx); -if (com_dev->driver->available && !com_dev->driver->available(com_dev->lower_id)) { - /* - * Underlying device is down/unconnected. - * Dump our fifo contents and act like an infinite data sink. - * Failure to do this results in stale data in the fifo as well as - * possibly having the caller block trying to send to a device that's - * no longer accepting data. - */ - fifoBuf_clearData(&com_dev->tx); - return len; -} - -if (len > fifoBuf_getFree(&com_dev->tx)) { - /* Buffer cannot accept all requested bytes (retry) */ - return -2; -} - -uint16_t bytes_into_fifo = fifoBuf_putData(&com_dev->tx, buffer, len); - -if (bytes_into_fifo > 0) { - /* More data has been put in the tx buffer, make sure the tx is started */ - if (com_dev->driver->tx_start) { - com_dev->driver->tx_start(com_dev->lower_id, - fifoBuf_getUsed(&com_dev->tx)); + PIOS_Assert(com_dev); + PIOS_Assert(com_dev->has_tx); + if (com_dev->driver->available && !com_dev->driver->available(com_dev->lower_id)) { + /* + * Underlying device is down/unconnected. + * Dump our fifo contents and act like an infinite data sink. + * Failure to do this results in stale data in the fifo as well as + * possibly having the caller block trying to send to a device that's + * no longer accepting data. + */ + fifoBuf_clearData(&com_dev->tx); + return len; } -} -return bytes_into_fifo; + + if (len > fifoBuf_getFree(&com_dev->tx)) { + /* Buffer cannot accept all requested bytes (retry) */ + return -2; + } + + uint16_t bytes_into_fifo = fifoBuf_putData(&com_dev->tx, buffer, len); + + if (bytes_into_fifo > 0) { + /* More data has been put in the tx buffer, make sure the tx is started */ + if (com_dev->driver->tx_start) { + com_dev->driver->tx_start(com_dev->lower_id, + fifoBuf_getUsed(&com_dev->tx)); + } + } + return bytes_into_fifo; } /** @@ -346,6 +346,7 @@ int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, u * \param[in] len buffer length * \return -1 if port not available * \return -2 if mutex can't be taken; + * \return -3 if data cannot be sent in the max allotted time of 5000msec * \return number of bytes transmitted on success */ int32_t PIOS_COM_SendBuffer(uint32_t com_id, const uint8_t *buffer, uint16_t len) From da5ef3b3ccfdfdf00ac7ba6298b9c46853de7717 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 15 Feb 2014 22:01:00 +0100 Subject: [PATCH 3/3] OP-1218 Raise time PIOS_COM_SendBuffer waits to acquire sendbuffer semaphore --- flight/pios/common/pios_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/pios/common/pios_com.c b/flight/pios/common/pios_com.c index a467aad28..e80ad9a91 100644 --- a/flight/pios/common/pios_com.c +++ b/flight/pios/common/pios_com.c @@ -359,7 +359,7 @@ int32_t PIOS_COM_SendBuffer(uint32_t com_id, const uint8_t *buffer, uint16_t len } PIOS_Assert(com_dev->has_tx); #if defined(PIOS_INCLUDE_FREERTOS) - if (xSemaphoreTake(com_dev->sendbuffer_sem, 0) != pdTRUE) { + if (xSemaphoreTake(com_dev->sendbuffer_sem, 5) != pdTRUE) { return -2; } #endif /* PIOS_INCLUDE_FREERTOS */