Skip to content

Commit 26ab03d

Browse files
authored
Merge pull request apache#910 from andrzej-kaczmarek/cmac-tx-late-one-more-attempt
nimble/phy: Fix tx_late handling
2 parents ab53154 + 04dc9e9 commit 26ab03d

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

nimble/drivers/dialog_cmac/src/ble_phy.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ STATS_SECT_START(ble_phy_stats)
4646
STATS_SECT_ENTRY(tx_good)
4747
STATS_SECT_ENTRY(tx_fail)
4848
STATS_SECT_ENTRY(tx_late)
49+
STATS_SECT_ENTRY(tx_late_sched)
50+
STATS_SECT_ENTRY(tx_late_frame)
51+
STATS_SECT_ENTRY(tx_late_field)
4952
STATS_SECT_ENTRY(tx_bytes)
5053
STATS_SECT_ENTRY(rx_starts)
5154
STATS_SECT_ENTRY(rx_aborts)
@@ -63,6 +66,9 @@ STATS_NAME_START(ble_phy_stats)
6366
STATS_NAME(ble_phy_stats, tx_good)
6467
STATS_NAME(ble_phy_stats, tx_fail)
6568
STATS_NAME(ble_phy_stats, tx_late)
69+
STATS_NAME(ble_phy_stats, tx_late_sched)
70+
STATS_NAME(ble_phy_stats, tx_late_frame)
71+
STATS_NAME(ble_phy_stats, tx_late_field)
6672
STATS_NAME(ble_phy_stats, tx_bytes)
6773
STATS_NAME(ble_phy_stats, rx_starts)
6874
STATS_NAME(ble_phy_stats, rx_aborts)
@@ -1242,6 +1248,15 @@ ble_phy_init(void)
12421248
g_ble_phy_encrypt_data.ai[0] = 0x01;
12431249
#endif
12441250

1251+
/*
1252+
* Disable FIELD1, FIELD2 and FRAME errors since they can happen
1253+
* sometimes if we are too late on scheduling and trigger CMAC
1254+
* error. We can detect if tx_late happened and recover properly.
1255+
*/
1256+
CMAC->CM_ERROR_DIS_REG |= CMAC_CM_ERROR_DIS_REG_CM_FIELD1_ERR_Msk |
1257+
CMAC_CM_ERROR_DIS_REG_CM_FIELD2_ERR_Msk |
1258+
CMAC_CM_ERROR_DIS_REG_CM_FRAME_ERR_Msk;
1259+
12451260
return 0;
12461261
}
12471262

@@ -1274,8 +1289,6 @@ ble_phy_disable(void)
12741289
os_arch_cmac_bs_ctrl_irq_unblock();
12751290
g_sw_mac_exc = 0;
12761291

1277-
CMAC->CM_ERROR_DIS_REG = 0;
1278-
12791292
ble_rf_stop();
12801293

12811294
/*
@@ -1455,6 +1468,7 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans)
14551468
if (CMAC->CM_EXC_STAT_REG & CMAC_CM_EXC_STAT_REG_EXC_FIELD_ON_THR_EXP_Msk) {
14561469
ble_phy_disable();
14571470
g_ble_phy_data.end_transition = BLE_PHY_TRANSITION_NONE;
1471+
STATS_INC(ble_phy_stats, tx_late_field);
14581472
STATS_INC(ble_phy_stats, tx_late);
14591473
rc = BLE_PHY_ERR_RADIO_STATE;
14601474
} else {
@@ -1467,7 +1481,6 @@ ble_phy_tx(ble_phy_tx_pducb_t pducb, void *pducb_arg, uint8_t end_trans)
14671481
}
14681482

14691483
/* Now we can handle BS_CTRL */
1470-
CMAC->CM_ERROR_DIS_REG &= ~CMAC_CM_ERROR_DIS_REG_CM_FIELD1_ERR_Msk;
14711484
NVIC_EnableIRQ(FRAME_IRQn);
14721485
NVIC_EnableIRQ(FIELD_IRQn);
14731486

@@ -1499,20 +1512,17 @@ ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
14991512
assert((int32_t)(ll_val32 - cmac_timer_read32()) < 1024);
15001513

15011514
/*
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.
1515+
* We do not want FIELD/FRAME interrupts until ble_phy_tx() has
1516+
* pushed all fields.
15061517
*/
15071518
NVIC_DisableIRQ(FRAME_IRQn);
15081519
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;
15111520

15121521
CMAC->CM_LL_TIMER1_9_0_EQ_X_REG = ll_val32;
15131522
CMAC->CM_EV_LINKUP_REG = CMAC_CM_EV_LINKUP_REG_LU_FRAME_START_2_TMR1_9_0_EQ_X_Msk;
15141523

15151524
if ((int32_t)(ll_val32 - cmac_timer_read32()) < 0) {
1525+
STATS_INC(ble_phy_stats, tx_late_sched);
15161526
goto tx_late;
15171527
}
15181528

@@ -1529,10 +1539,10 @@ ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs)
15291539
* need to assume tx_late and abort.
15301540
*/
15311541
if (CMAC->CM_EXC_STAT_REG & CMAC_CM_EXC_STAT_REG_EXC_FRAME_START_Msk) {
1542+
STATS_INC(ble_phy_stats, tx_late_frame);
15321543
goto tx_late;
15331544
}
15341545

1535-
CMAC->CM_ERROR_DIS_REG &= ~CMAC_CM_ERROR_DIS_REG_CM_FRAME_ERR_Msk;
15361546
rc = 0;
15371547

15381548
goto done;

0 commit comments

Comments
 (0)