8000 stm32/rfcore: Fix flow control for IPCC RX IRQ. · micropython/micropython@0f9a912 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f9a912

Browse files
jimmodpgeorge
authored andcommitted
stm32/rfcore: Fix flow control for IPCC RX IRQ.
Don't clear the IPCC channel flag until we've actually handled the incoming data, or else the wireless firmware may clobber the IPCC buffer if more data arrives. This requires masking the IRQ until the data is handled. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent b8f4c62 commit 0f9a912

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

ports/stm32/rfcore.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,16 @@ STATIC void tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse
434434
// Only call this when IRQs are disabled on this channel.
435435
STATIC void tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) {
436436
if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, ch)) {
437+
// Process new data.
437438
tl_process_msg(head, ch, parse);
438439

439-
// Clear receive channel.
440+
// Clear receive channel (allows RF core to send more data to us).
440441
LL_C1_IPCC_ClearFlag_CHx(IPCC, ch);
442+
443+
if (ch == IPCC_CH_BLE) {
444+
// Renable IRQs for BLE now that we've cleared the flag.
445+
LL_C1_IPCC_EnableReceiveChannel(IPCC, IPCC_CH_BLE);
446+
}
441447
}
442448
}
443449

@@ -495,17 +501,17 @@ STATIC int tl_ble_wait_resp(void) {
495501
}
496502
}
497503

498-
// C2 set IPCC flag.
504+
// C2 set IPCC flag -- process the data, clear the flag, and re-enable IRQs.
499505
tl_check_msg(&ipcc_mem_ble_evt_queue, IPCC_CH_BLE, NULL);
500506
return 0;
501507
}
502508

503509
// Synchronously send a BLE command.
504510
STATIC void tl_ble_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len) {
511+
// Poll for completion rather than wait for IRQ->scheduler.
505512
LL_C1_IPCC_DisableReceiveChannel(IPCC, IPCC_CH_BLE);
506513
tl_hci_cmd(ipcc_membuf_ble_cmd_buf, IPCC_CH_BLE, HCI_KIND_BT_CMD, opcode, buf, len);
507514
tl_ble_wait_resp();
508-
LL_C1_IPCC_EnableReceiveChannel(IPCC, IPCC_CH_BLE);
509515
}
510516

511517
/******************************************************************************/
@@ -632,7 +638,7 @@ void rfcore_ble_hci_cmd(size_t len, const uint8_t *src) {
632638

633639
void rfcore_ble_check_msg(int (*cb)(void *, const uint8_t *, size_t), void *env) {
634640
parse_hci_info_t parse = { cb, env, false };
635-
tl_process_msg(&ipcc_mem_ble_evt_queue, IPCC_CH_BLE, &parse);
641+
tl_check_msg(&ipcc_mem_ble_evt_queue, IPCC_CH_BLE, &parse);
636642

637643
// Intercept HCI_Reset events and reconfigure the controller following the reset
638644
if (parse.was_hci_reset_evt) {
@@ -679,7 +685,8 @@ void IPCC_C1_RX_IRQHandler(void) {
679685
DEBUG_printf("IPCC_C1_RX_IRQHandler\n");
680686

681687
if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) {
682-
LL_C1_IPCC_ClearFlag_CHx(IPCC, IPCC_CH_BLE);
688+
// Disable this IRQ until the incoming data is processed (in tl_check_msg).
689+
LL_C1_IPCC_DisableReceiveChannel(IPCC, IPCC_CH_BLE);
683690

684691
#if MICROPY_PY_BLUETOOTH
685692
// Queue up the scheduler to process UART data and run events.

0 commit comments

Comments
 (0)
0