add tx power to cordio hci driver

pull/13040/head
Paul Szczeanek 2020-05-29 18:22:44 +01:00
parent 698fc09b4c
commit 056f46d629
4 changed files with 55 additions and 13 deletions

View File

@ -364,6 +364,10 @@ ble_error_t CordioHCIDriver::rf_test_end()
return BLE_ERROR_NO_MEM;
}
ble_error_t CordioHCIDriver::set_tx_power(int8_t level_db) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
} // namespace cordio
} // namespace vendor
} // namespace ble

View File

@ -187,6 +187,16 @@ public:
*/
ble_error_t rf_test_end();
/**
* Set desired transmit power. Value equal or bigger will be used from available levels.
* Consult chip documentation for available values. Actual TX power is not guaranteed
* and is down to the implementation.
*
* @param level_db Signal level in dBm.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t set_tx_power(int8_t level_db);
protected:
/**
* Return a default set of memory pool that the Cordio stack can use.

View File

@ -67,6 +67,10 @@
"route_unhandled_command_complete_events": {
"help": "If enabled the stack will forward to the user all HCI events not handled by the stack.",
"value": 1
},
"preferred-tx-power": {
"help": "Preferred value of tx power in dbm (-128,127). This value is not guaranteed and relies on existing support in the HCI driver.",
"value": 0
}
}
}

View File

@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include "ble/blecommon.h"
#include "CordioBLE.h"
#include "CordioHCIDriver.h"
#include "CordioHCITransportDriver.h"
@ -131,6 +132,39 @@ public:
HciResetCmd();
}
static uint8_t convert_db_to_tx_power_index(int8_t level_db) {
const int8_t conversion[] = {
-40, -21, -20, -19,
-18, -16, -15, -14,
-13, -12, -11, -10,
-9, -8, -7, -6,
-5, -4, -3, -2,
-1, -1, -1, -1,
0, 0, 1, 2,
3, 4, 5, 6
};
uint8_t index;
for (index = 0; index < sizeof(conversion); ++index) {
if (level_db <= conversion[index]) {
break;
}
}
return index;
}
virtual ble_error_t set_tx_power(int8_t level_db) {
uint8_t buf[2];
buf[0] = 0x1; // Enable high power mode - deprecated and ignored on STM32WB
buf[1] = convert_db_to_tx_power_index(level_db);
HciVendorSpecificCmd(ACI_HAL_SET_TX_POWER_LEVEL, 2, buf);
return BLE_ERROR_NONE;
}
/**
* @see CordioHCIDriver::handle_reset_sequence
*/
@ -177,7 +211,7 @@ public:
} else {
tr_info("could not find BDaddr");
/* Skip to next step */
aciSetTxPowerLevel();
set_tx_power(MBED_CONF_CORDIO_PREFERRED_TX_POWER);
}
break;
@ -185,7 +219,7 @@ public:
tr_debug("Bluetooth Device address set");
/* set the event mask to control which events are generated by the
* controller for the host */
aciSetTxPowerLevel();
set_tx_power(MBED_CONF_CORDIO_PREFERRED_TX_POWER);
break;
@ -359,16 +393,6 @@ public:
private:
uint8_t bd_addr[6];
void aciSetTxPowerLevel()
{
uint8_t *pBuf = hciCmdAlloc(ACI_HAL_SET_TX_POWER_LEVEL, 2);
if (!pBuf) {
return;
}
pBuf[HCI_CMD_HDR_LEN] = 0x1;
pBuf[HCI_CMD_HDR_LEN + 1] = 0x18;
hciCmdSend(pBuf);
}
void aciReadConfigParameter(uint8_t offset)
{