set baudrate during custom init for csr chipssets

This commit is contained in:
Matthias Ringwald 2015-03-31 12:43:26 +02:00
parent 7b0d76671f
commit baf36f076c

View File

@ -55,34 +55,35 @@
// minimal CSR init script
static const uint8_t init_script[] = {
// BCCMD set ANA_Freq PSKEY to 26MHz
0x01, 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x1e, 0x00, 0x03, 0x70, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x90, 0x65,
0x01, 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x01, 0x00, 0x03, 0x70, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x00, 0x00, 0x90, 0x65,
// BCCMD set UART baudrate to 115200
0x01, 0x00, 0xFC, 0x15, 0xc2, 0x02, 0x00, 0x0a, 0x00, 0x02, 0x00, 0x03, 0x70, 0x00, 0x00, 0xea, 0x01, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xc2,
// BCCMD WarmReset
0x01, 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x4d, 0x0e, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x03, 0x0e, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint16_t init_script_size = sizeof(init_script);
//
static uint32_t init_script_offset = 0;
static int16_t init_power_in_dB = 13; // 13 dBm
static int bt_control_csr_on(void *config){
init_script_offset = 0;
return 0;
}
// UART Baud Rate control from: http://e2e.ti.com/support/low_power_rf/f/660/p/134850/484763.aspx
// static int csr_baudrate_cmd(void * config, uint32_t baudrate, uint8_t *hci_cmd_buffer){
// hci_cmd_buffer[0] = 0x36;
// hci_cmd_buffer[1] = 0xFF;
// hci_cmd_buffer[2] = 0x04;
// hci_cmd_buffer[3] = baudrate & 0xff;
// hci_cmd_buffer[4] = (baudrate >> 8) & 0xff;
// hci_cmd_buffer[5] = (baudrate >> 16) & 0xff;
// hci_cmd_buffer[6] = 0;
// return 0;
// }
static void bt_control_csr_update_command(uint8_t *hci_cmd_buffer){
// set baud rate
static void bt_control_csr_update_command(hci_uart_config_t *config, uint8_t *hci_cmd_buffer){
uint16_t varid = READ_BT_16(hci_cmd_buffer, 10);
if (varid != 0x7003) return;
uint16_t key = READ_BT_16(hci_cmd_buffer, 14);
if (key != 0x01ea) return;
uint32_t baudrate = config->baudrate_main;
if (baudrate == 0){
baudrate = config->baudrate_init;
}
// uint32_t is stored as 2 x uint16_t with most important 16 bits first
bt_store_16(hci_cmd_buffer, 20, baudrate >> 16);
bt_store_16(hci_cmd_buffer, 22, baudrate & 0xffff);
}
static int bt_control_csr_next_cmd(void *config, uint8_t *hci_cmd_buffer){
@ -101,7 +102,7 @@ static int bt_control_csr_next_cmd(void *config, uint8_t *hci_cmd_buffer){
memcpy(&hci_cmd_buffer[3], (uint8_t *) &init_script[init_script_offset], payload_len);
// support for on-the-fly configuration updates
bt_control_csr_update_command(hci_cmd_buffer);
bt_control_csr_update_command((hci_uart_config_t*)config, hci_cmd_buffer);
init_script_offset += payload_len;
@ -124,7 +125,7 @@ static const bt_control_t bt_control_csr = {
NULL, // wake
NULL, // valid
NULL, // name
NULL, /* csr_baudrate_cmd, */ // baudrate_cmd
NULL, // baudrate_cmd
bt_control_csr_next_cmd, // next_cmd
NULL, // register_for_power_notifications
NULL, // hw_error
@ -140,7 +141,6 @@ static const hci_uart_config_t hci_uart_config_csr = {
// MARK: public API
void bt_control_csr_set_power(int16_t power_in_dB){
init_power_in_dB = power_in_dB;
}
bt_control_t *bt_control_csr_instance(void){