Skip to content

Commit 69c8991

Browse files
nimble/phy: Fix tx_late handling
Disabling some errors temporarily to avoid tx_late does not work properly because those errors are not reset when BS is reset and we may still have CMAC error after those errors are enabled. To make things work let's just keep all relevant errors disabled and ignore them since we can use exceptions status to detect tx_late pretty consistently.
1 parent 7b5b5e5 commit 69c8991

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

nimble/drivers/dialog_cmac/src/ble_phy.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,15 @@ ble_phy_init(void)
12421242
g_ble_phy_encrypt_data.ai[0] = 0x01;
12431243
#endif
12441244

1245+
/*
1246+
* Disable FIELD1, FIELD2 and FRAME errors since they can happen
1247+
* sometimes if we are too late on scheduling and trigger CMAC
1248+
* error. We can detect if tx_late happened and recover properly.
1249+
*/
1250+
CMAC->CM_ERROR_DIS_REG |= CMAC_CM_ERROR_DIS_REG_CM_FIELD1_ERR_Msk |
1251+
CMAC_CM_ERROR_DIS_REG_CM_FIELD2_ERR_Msk |
1252+
CMAC_CM_ERROR_DIS_REG_CM_FRAME_ERR_Msk;
1253+
12451254
return 0;
12461255
}
12471256

@@ -1274,8 +1283,6 @@ ble_phy_disable(void)
12741283
os_arch_cmac_bs_ctrl_irq_unblock();
12751284
g_sw_mac_exc = 0;
12761285

1277-
CMAC->CM_ERROR_DIS_REG = 0;
1278-
12791286
ble_rf_stop();
12801287

12811288
/*
@@ -1467,7 +1474,6 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans)
14671474
}
14681475

14691476
/* Now we can handle BS_CTRL */
1470-
CMAC->CM_ERROR_DIS_REG &= ~CMAC_CM_ERROR_DIS_REG_CM_FIELD1_ERR_Msk;
14711477
NVIC_EnableIRQ(FRAME_IRQn);
14721478
NVIC_EnableIRQ(FIELD_IRQn);
14731479

@@ -1499,15 +1505,11 @@ ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
14991505
assert((int32_t)(ll_val32 - cmac_timer_read32()) < 1024);
15001506

15011507
/*
1502-
* We do not want FIELD/FRAME interrupts or FIELD1_ERR until ble_phy_tx()
1503-
* has finished pushing all the fields. Also we do not want premature
1504-
* FRAME_ERR so disable it until we program FRAME1 properly. If we won't
1505-
* make configuration on time, assume tx_late and abort TX.
1508+
* We do not want FIELD/FRAME interrupts until ble_phy_tx() has
1509+
* pushed all fields.
15061510
*/
15071511
NVIC_DisableIRQ(FRAME_IRQn);
15081512
NVIC_DisableIRQ(FIELD_IRQn);
1509-
CMAC->CM_ERROR_DIS_REG |= CMAC_CM_ERROR_DIS_REG_CM_FIELD1_ERR_Msk |
1510-
CMAC_CM_ERROR_DIS_REG_CM_FRAME_ERR_Msk;
15111513

15121514
CMAC->CM_LL_TIMER1_9_0_EQ_X_REG = ll_val32;
15131515
CMAC->CM_EV_LINKUP_REG = CMAC_CM_EV_LINKUP_REG_LU_FRAME_START_2_TMR1_9_0_EQ_X_Msk;
@@ -1532,7 +1534,6 @@ ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
15321534
goto tx_late;
15331535
}
15341536

1535-
CMAC->CM_ERROR_DIS_REG &= ~CMAC_CM_ERROR_DIS_REG_CM_FRAME_ERR_Msk;
15361537
rc = 0;
15371538

15381539
goto done;

0 commit comments

Comments
 (0)