8000 stm32/rfcore: Enable RX IRQ on BLE IPCC channel for better performance. · tve/micropython@e2390d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2390d5

Browse files
jimmodpgeorge
authored andcommitted
stm32/rfcore: Enable RX IRQ on BLE IPCC channel for better performance.
Before this change there was up to a 128ms delay on incoming payloads from CPU2 as it was polled by SysTick. Now the RX IRQ immediately schedules the PendSV.
1 parent 8b4ebd7 commit e2390d5

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

ports/stm32/rfcore.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ STATIC uint8_t ipcc_membuf_ble_cs_buf[272]; // mem2
164164
STATIC tl_list_node_t ipcc_mem_ble_evt_queue; // mem1
165165
STATIC uint8_t ipcc_membuf_ble_hci_acl_data_buf[272]; // mem2
166166

167+
// Set by the RX IRQ handler on incoming HCI payload.
168+
STATIC volatile bool had_ble_irq = false;
169+
167170
/******************************************************************************/
168171
// Transport layer linked list
169172

@@ -209,6 +212,13 @@ void ipcc_init(uint32_t irq_pri) {
209212
// Start IPCC peripheral
210213
__HAL_RCC_IPCC_CLK_ENABLE();
211214

215+
// Enable receive IRQ on the BLE channel.
216+
LL_C1_IPCC_EnableIT_RXO(IPCC);
217+
LL_C1_IPCC_DisableReceiveChannel(IPCC, LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6);
218+
LL_C1_IPCC_EnableReceiveChannel(IPCC, IPCC_CH_BLE);
219+
NVIC_SetPriority(IPCC_C1_RX_IRQn, irq_pri);
220+
HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn);
221+
212222
// Device info table will be populated by FUS/WS on CPU2 boot.
213223

214224
// Populate system table
@@ -360,10 +370,10 @@ STATIC void tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_h
360370
}
361371

362372
STATIC void tl_check_msg_ble(volatile tl_list_node_t *head, parse_hci_info_t *parse) {
363-
if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) {
373+
if (had_ble_irq) {
364374
tl_process_msg(head, IPCC_CH_BLE, parse);
365375

366-
LL_C1_IPCC_ClearFlag_CHx(IPCC, IPCC_CH_BLE);
376+
had_ble_irq = false;
367377
}
368378
}
369379

@@ -404,7 +414,7 @@ STATIC void tl_sys_hci_cmd_resp(uint16_t opcode, size_t len, const uint8_t *buf)
404414

405415
STATIC int tl_ble_wait_resp(void) {
406416
uint32_t t0 = mp_hal_ticks_ms();
407-
while (!LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) {
417+
while (!had_ble_irq) {
408418
if (mp_hal_ticks_ms() - t0 > BLE_ACK_TIMEOUT_MS) {
409419
printf("tl_ble_wait_resp: timeout\n");
410420
return -MP_ETIMEDOUT;
@@ -553,4 +563,26 @@ void rfcore_ble_set_txpower(uint8_t level) {
553563
tl_ble_hci_cmd_resp(HCI_OPCODE(OGF_VENDOR, OCF_SET_TX_POWER), 2, buf);
554564
}
555565

566+
// IPCC IRQ Handlers
567+
void IPCC_C1_TX_IRQHandler(void) {
568+
IRQ_ENTER(IPCC_C1_TX_IRQn);
569+
IRQ_EXIT(IPCC_C1_TX_IRQn);
570+
}
571+
572+
void IPCC_C1_RX_IRQHandler(void) {
573+
IRQ_ENTER(IPCC_C1_RX_IRQn);
574+
575+
if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) {
576+
had_ble_irq = true;
577+
578+
LL_C1_IPCC_ClearFlag_CHx(IPCC, IPCC_CH_BLE);
579+
580+
// Schedule PENDSV to process incoming HCI payload.
581+
extern void mp_bluetooth_hci_poll_wrapper(uint32_t ticks_ms);
582+
mp_bluetooth_hci_poll_wrapper(0);
583+
}
584+
585+
IRQ_EXIT(IPCC_C1_RX_IRQn);
586+
}
587+
556588
#endif // defined(STM32WB)

0 commit comments

Comments
 (0)
0