@@ -434,10 +434,16 @@ STATIC void tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse
434
434
// Only call this when IRQs are disabled on this channel.
435
435
STATIC void tl_check_msg (volatile tl_list_node_t * head , unsigned int ch , parse_hci_info_t * parse ) {
436
436
if (LL_C2_IPCC_IsActiveFlag_CHx (IPCC , ch )) {
437
+ // Process new data.
437
438
tl_process_msg (head , ch , parse );
438
439
439
- // Clear receive channel.
440
+ // Clear receive channel (allows RF core to send more data to us) .
440
441
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
+ }
441
447
}
442
448
}
443
449
@@ -495,17 +501,17 @@ STATIC int tl_ble_wait_resp(void) {
495
501
}
496
502
}
497
503
498
- // C2 set IPCC flag.
504
+ // C2 set IPCC flag -- process the data, clear the flag, and re-enable IRQs .
499
505
tl_check_msg (& ipcc_mem_ble_evt_queue , IPCC_CH_BLE , NULL );
500
506
return 0 ;
501
507
}
502
508
503
509
// Synchronously send a BLE command.
504
510
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.
505
512
LL_C1_IPCC_DisableReceiveChannel (IPCC , IPCC_CH_BLE );
506
513
tl_hci_cmd (ipcc_membuf_ble_cmd_buf , IPCC_CH_BLE , HCI_KIND_BT_CMD , opcode , buf , len );
507
514
tl_ble_wait_resp ();
508
- LL_C1_IPCC_EnableReceiveChannel (IPCC , IPCC_CH_BLE );
509
515
}
510
516
511
517
/******************************************************************************/
@@ -632,7 +638,7 @@ void rfcore_ble_hci_cmd(size_t len, const uint8_t *src) {
632
638
633
639
void rfcore_ble_check_msg (int (* cb )(void * , const uint8_t * , size_t ), void * env ) {
634
640
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 );
636
642
637
643
// Intercept HCI_Reset events and reconfigure the controller following the reset
638
644
if (parse .was_hci_reset_evt ) {
@@ -679,7 +685,8 @@ void IPCC_C1_RX_IRQHandler(void) {
679
685
DEBUG_printf ("IPCC_C1_RX_IRQHandler\n" );
680
686
681
687
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 );
683
690
684
691
#if MICROPY_PY_BLUETOOTH
685
692
// Queue up the scheduler to process UART data and run events.
0 commit comments