Skip to content

Commit

Permalink
nimble/phy/cmac: Fix setting TX power level
Browse files Browse the repository at this point in the history
TX power is now configured using ble_ll_tx_power_set (instead of
ble_phy_tx_power_set) which uses ble_phy_tx_power_round to calculate
proper TX power level.

This adds missing implementation for that function in CMAC PHY driver so
power level can be properly set.
  • Loading branch information
andrzej-kaczmarek committed Aug 11, 2024
1 parent a908b5e commit 49db784
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions nimble/drivers/dialog_cmac/src/ble_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,26 +1655,46 @@ ble_phy_encrypt_disable(void)
}
#endif

static int8_t
phy_txpower_round(int8_t dbm)
{
static const int8_t supported_pwr_levels[] = {-18, -12, -8, -6, -3, -2,
-1, 0, 1, 2, 3, 4, 5, 6 };
int i;

for (i = 0; i < ARRAY_SIZE(supported_pwr_levels); i++) {
if (dbm <= supported_pwr_levels[i]) {
dbm = supported_pwr_levels[i];
break;
}
}

if (i == ARRAY_SIZE(supported_pwr_levels)) {
dbm = supported_pwr_levels[ARRAY_SIZE(supported_pwr_levels) - 1];
}

return dbm;
}

int
ble_phy_tx_power_set(int dbm)
{
#if MYNEWT_VAL(CMAC_DEBUG_DATA_ENABLE)
if (g_cmac_shm_debugdata.tx_power_ovr_enable) {
ble_rf_set_tx_power(g_cmac_shm_debugdata.tx_power_ovr);
} else {
ble_rf_set_tx_power(dbm);
dbm = g_cmac_shm_debugdata.tx_power_ovr;
}
#else
ble_rf_set_tx_power(dbm);
#endif

dbm = phy_txpower_round(dbm);
ble_rf_set_tx_power(dbm);

return 0;
}

int
ble_phy_tx_power_round(int dbm)
{
return 0;
return phy_txpower_round(dbm);
}

int
Expand Down

0 comments on commit 49db784

Please sign in to comment.