Skip to content

Commit

Permalink
[EFR32] RSI_send_error_fix (#23540)
Browse files Browse the repository at this point in the history
* RSI_send_error_fix

* Addressing review comments

Co-authored-by: riwaghe <RiteshGovind.Waghe@silabs.com>
  • Loading branch information
2 people authored and pull[bot] committed Mar 23, 2023
1 parent 3c0ede1 commit 2298624
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
31 changes: 29 additions & 2 deletions examples/platform/efr32/rs911x/hal/efx_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,40 @@ int16_t rsi_spi_transfer(uint8_t * tx_buf, uint8_t * rx_buf, uint16_t xlen, uint
{
transmitDMA(rx_buf, tx_buf, xlen);
}

/*
* Wait for the call-back to complete
* receiveDMA() and transmitDMA() are asynchronous
* Our application design assumes that this function is synchronous
* To make it synchronous, we wait to re-acquire the semaphore before exiting this function
* rx_dma_complete() gives back the semaphore when the SPI transfer is done
*/
if (xSemaphoreTake(spi_sem, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTake(spi_sem, pdMS_TO_TICKS(RSI_SEM_BLOCK_MIN_TIMER_VALUE_MS)) == pdTRUE)
{
// Transfer complete
// Give back the semaphore before exiting, so that it may be re-acquired
// in this function, just before the next transfer
xSemaphoreGive(spi_sem);
}
// Temporary patch
// Sometimes the xSemaphoreTake() above is getting stuck indefinitely
// As a workaround, if the transfer is not done within RSI_SEM_BLOCK_MIN_TIMER_VALUE_MS
// stop and start it again
// No need to re-acquire the semaphore since this is the function that acquired it
// TODO: Remove this after a permanent solution is found to the problem of the transfer getting stuck
else
{
uint32_t ldma_flags = 0;
uint32_t rem_len = 0;
rem_len = LDMA_TransferRemainingCount(RSI_LDMA_TRANSFER_CHANNEL_NUM);
LDMA_StopTransfer(RSI_LDMA_TRANSFER_CHANNEL_NUM);
ldma_flags = LDMA_IntGet();
LDMA_IntClear(ldma_flags);
receiveDMA(rx_buf, rem_len);
if (xSemaphoreTake(spi_sem, portMAX_DELAY) == pdTRUE)
{
xSemaphoreGive(spi_sem);
}
}
}

return RSI_ERROR_NONE;
Expand Down
6 changes: 6 additions & 0 deletions examples/platform/efr32/rs911x/hal/rsi_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
// Macro to drive high value on GPIO
#define RSI_HAL_GPIO_HIGH 1

// Macro to drive LDMA channel number
#define RSI_LDMA_TRANSFER_CHANNEL_NUM 3

// Macro to drive semaphore block minimun timer in milli seconds
#define RSI_SEM_BLOCK_MIN_TIMER_VALUE_MS 50

/******************************************************
* * Function Declarations
* ******************************************************/
Expand Down

0 comments on commit 2298624

Please sign in to comment.