Skip to content

Commit

Permalink
Move send() out of interrupt context
Browse files Browse the repository at this point in the history
  • Loading branch information
mkimhj committed Apr 2, 2021
1 parent 180b687 commit 937b083
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions ble_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static uint16_t ringBufferHead = 0;
static uint16_t ringBufferTail = 0;
static uint16_t ringBufferBytesUsed = 0;

static void send(void);

char const * phy_str(ble_gap_phys_t phys)
{
static char const * str[] =
Expand Down Expand Up @@ -386,7 +384,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)

case BLE_GATTS_EVT_HVN_TX_COMPLETE:
transmitDone = true;
send(); // attempt to keep sending remaining bytes in ringBuffer
// send(); // attempt to keep sending remaining bytes in ringBuffer
eventQueuePush(EVENT_BLE_SEND_DATA_DONE); // attempt to requeue mic data if ringBuffer was previously full
NRF_LOG_DEBUG("Handle value notification");
break;
Expand Down Expand Up @@ -516,7 +514,7 @@ void bleInit(void)
NRF_LOG_RAW_INFO("%02X:%02X:%02X:%02X:%02X:%02X\n", address[0], address[1], address[2], address[3], address[4], address[5]);
}

static void send(void)
void send(void)
{
static bool sending = false;
uint16_t length = maxAttMtuBytes;
Expand Down
3 changes: 2 additions & 1 deletion ble_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ void bleAdvertisingStart();
void bleInit(void);
void bleSendData(uint8_t * data, int length);
bool bleCanTransmit(void);
bool bleBufferHasSpace(uint16_t length);
bool bleBufferHasSpace(uint16_t length);
void send(void);
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static void processQueue(void)
if (bleRetry && bleBufferHasSpace(sizeof(dataBuffer) * sizeof(dataBuffer[0]))) {
bleRetry = false;
bleSendData((uint8_t *) dataBuffer, sizeof(dataBuffer) * sizeof(dataBuffer[0]));
} else {
send();
}
break;

Expand Down

0 comments on commit 937b083

Please sign in to comment.