Skip to content

Commit

Permalink
fix(PeriphDrivers): fix potential no callback execution using atomic …
Browse files Browse the repository at this point in the history
…variable in DMA-based SPI transaction
  • Loading branch information
JeonChangmin committed Jul 2, 2024
1 parent 129d1f2 commit b88bd29
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Libraries/PeriphDrivers/Source/SPI/spi_reva1.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
******************************************************************************/

#include <stdatomic.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
Expand All @@ -43,7 +44,7 @@ typedef struct {
int mtMode;
int mtFirstTrans;
bool txrx_req;
uint8_t req_done;
atomic_uint_fast8_t req_done;
uint8_t async;
bool hw_ss_control;
} spi_req_reva_state_t;
Expand Down Expand Up @@ -1301,9 +1302,9 @@ void MXC_SPI_RevA1_DMACallback(int ch, int error)
for (int i = 0; i < MXC_SPI_INSTANCES; i++) {
if (states[i].req != NULL) {
if (states[i].channelTx == ch) {
req_done = states[i].req_done++;
req_done = atomic_fetch_add(&states[i].req_done, 1);
} else if (states[i].channelRx == ch) {
req_done = states[i].req_done++;
req_done = atomic_fetch_add(&states[i].req_done, 1);
//save the request
temp_req = states[i].req;

Expand Down

0 comments on commit b88bd29

Please sign in to comment.