mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
PiOS/USB_HID: When using FreeRTOS use a sempahore to stop multiple tasks
pushing data to the transmit buffer git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2278 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
4ee9cf7aad
commit
ba8351f60a
@ -40,6 +40,10 @@
|
|||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
#if defined(PIOS_INCLUDE_USB_HID)
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||||
|
#define USE_FREERTOS
|
||||||
|
#endif
|
||||||
|
|
||||||
const struct pios_com_driver pios_usb_com_driver = {
|
const struct pios_com_driver pios_usb_com_driver = {
|
||||||
.tx_nb = PIOS_USB_HID_TxBufferPutMoreNonBlocking,
|
.tx_nb = PIOS_USB_HID_TxBufferPutMoreNonBlocking,
|
||||||
.tx = PIOS_USB_HID_TxBufferPutMore,
|
.tx = PIOS_USB_HID_TxBufferPutMore,
|
||||||
@ -60,6 +64,11 @@ t_fifo_buffer rx_pios_fifo_buffer;
|
|||||||
|
|
||||||
uint8_t tx_pios_fifo_buf[1024] __attribute__ ((aligned(4))); // align to 32-bit to try and provide speed improvement
|
uint8_t tx_pios_fifo_buf[1024] __attribute__ ((aligned(4))); // align to 32-bit to try and provide speed improvement
|
||||||
t_fifo_buffer tx_pios_fifo_buffer;
|
t_fifo_buffer tx_pios_fifo_buffer;
|
||||||
|
|
||||||
|
#if defined(USE_FREERTOS)
|
||||||
|
xSemaphoreHandle pios_usb_tx_semaphore;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises USB COM layer
|
* Initialises USB COM layer
|
||||||
* \param[in] mode currently only mode 0 supported
|
* \param[in] mode currently only mode 0 supported
|
||||||
@ -79,6 +88,11 @@ int32_t PIOS_USB_HID_Init(uint32_t mode)
|
|||||||
|
|
||||||
PIOS_USB_HID_Reenumerate();
|
PIOS_USB_HID_Reenumerate();
|
||||||
|
|
||||||
|
/* Create semaphore before enabling interrupts */
|
||||||
|
#if defined(USE_FREERTOS)
|
||||||
|
vSemaphoreCreateBinary(pios_usb_tx_semaphore);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Enable the USB Interrupts */
|
/* Enable the USB Interrupts */
|
||||||
/* 2 bit for pre-emption priority, 2 bits for subpriority */
|
/* 2 bit for pre-emption priority, 2 bits for subpriority */
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
@ -238,8 +252,17 @@ int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t id, const uint8_t * buff
|
|||||||
/* don't check returned bytes because it should always succeed */
|
/* don't check returned bytes because it should always succeed */
|
||||||
/* after previous thread and no meaningful way to deal with the */
|
/* after previous thread and no meaningful way to deal with the */
|
||||||
/* case it only buffers half the bytes */
|
/* case it only buffers half the bytes */
|
||||||
|
#if defined(USE_FREERTOS)
|
||||||
|
if(!xSemaphoreTake(pios_usb_tx_semaphore,10 / portTICK_RATE_MS))
|
||||||
|
return -3;
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = fifoBuf_putData(&tx_pios_fifo_buffer, buffer, len);
|
ret = fifoBuf_putData(&tx_pios_fifo_buffer, buffer, len);
|
||||||
|
|
||||||
|
#if defined(USE_FREERTOS)
|
||||||
|
xSemaphoreGive(pios_usb_tx_semaphore);
|
||||||
|
#endif
|
||||||
|
|
||||||
sendChunk();
|
sendChunk();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user