hci: introduce custom chipset pre-init that is run before hci reset

This commit is contained in:
Matthias Ringwald 2023-02-22 11:49:27 +01:00
parent 92ce4e6a2e
commit 6fe16221fb
2 changed files with 50 additions and 4 deletions

View File

@ -1863,10 +1863,12 @@ static void hci_initializing_run(void){
}
break;
}
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
/* fall through */
case HCI_INIT_CUSTOM_INIT:
case HCI_INIT_CUSTOM_PRE_INIT:
// Custom initialization
if (hci_stack->chipset && hci_stack->chipset->next_command){
hci_stack->chipset_result = (*hci_stack->chipset->next_command)(hci_stack->hci_packet_buffer);
@ -1874,7 +1876,17 @@ static void hci_initializing_run(void){
switch (hci_stack->chipset_result){
case BTSTACK_CHIPSET_VALID_COMMAND:
send_cmd = true;
hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT;
switch (hci_stack->substate){
case HCI_INIT_CUSTOM_INIT:
hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT;
break;
case HCI_INIT_CUSTOM_PRE_INIT:
hci_stack->substate = HCI_INIT_W4_CUSTOM_PRE_INIT;
break;
default:
btstack_assert(false);
break;
}
break;
case BTSTACK_CHIPSET_WARMSTART_REQUIRED:
send_cmd = true;
@ -1907,6 +1919,13 @@ static void hci_initializing_run(void){
}
log_info("Init script done");
// Custom Pre-Init complete, start regular init with HCI Reset
if (hci_stack->substate == HCI_INIT_CUSTOM_PRE_INIT){
hci_stack->substate = HCI_INIT_W4_SEND_RESET;
hci_send_cmd(&hci_reset);
break;
}
// Init script download on Broadcom chipsets causes:
if ( (hci_stack->chipset_result != BTSTACK_CHIPSET_NO_INIT_SCRIPT) &&
( (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATION)
@ -2378,6 +2397,10 @@ static void hci_initializing_event_handler(const uint8_t * packet, uint16_t size
// repeat custom init
hci_stack->substate = HCI_INIT_CUSTOM_INIT;
return;
case HCI_INIT_W4_CUSTOM_PRE_INIT:
// repeat custom init
hci_stack->substate = HCI_INIT_CUSTOM_PRE_INIT;
return;
#endif
case HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS:
@ -4650,6 +4673,10 @@ void hci_set_chipset(const btstack_chipset_t *chipset_driver){
}
}
void hci_enable_custom_pre_init(void){
hci_stack->chipset_pre_init = true;
}
/**
* @brief Configure Bluetooth hardware control. Has to be called after hci_init() but before power on.
*/
@ -4906,7 +4933,12 @@ static void hci_power_enter_initializing_state(void){
hci_stack->num_cmd_packets = 1; // assume that one cmd can be sent
hci_stack->hci_packet_buffer_reserved = false;
hci_stack->state = HCI_STATE_INITIALIZING;
hci_stack->substate = HCI_INIT_SEND_RESET;
if (hci_stack->chipset_pre_init) {
hci_stack->substate = HCI_INIT_CUSTOM_PRE_INIT;
} else {
hci_stack->substate = HCI_INIT_SEND_RESET;
}
}
static void hci_power_enter_halting_state(void){

View File

@ -754,10 +754,16 @@ typedef enum hci_init_state{
HCI_INIT_W4_SEND_BAUD_CHANGE,
HCI_INIT_CUSTOM_INIT,
HCI_INIT_W4_CUSTOM_INIT,
HCI_INIT_SEND_RESET_CSR_WARM_BOOT,
HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT,
HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT_LINK_RESET,
HCI_INIT_W4_CUSTOM_INIT_BCM_DELAY,
// Support for Pre-Init before HCI Reset
HCI_INIT_CUSTOM_PRE_INIT,
HCI_INIT_W4_CUSTOM_PRE_INIT,
#endif
HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS,
@ -949,6 +955,9 @@ typedef struct {
// chipset driver
const btstack_chipset_t * chipset;
// chipset driver requires pre-init
bool chipset_pre_init;
// hardware power controller
const btstack_control_t * control;
@ -1284,6 +1293,11 @@ void hci_init(const hci_transport_t *transport, const void *config);
*/
void hci_set_chipset(const btstack_chipset_t *chipset_driver);
/**
* @brief Enable custom init for chipset driver to send HCI commands before HCI Reset
*/
void hci_enable_custom_pre_init(void);
/**
* @brief Configure Bluetooth hardware control. Has to be called before power on.
* @[aram hardware_control implementation
@ -1700,8 +1714,8 @@ uint8_t gap_periodic_advertising_create_sync_cancel(void);
uint8_t gap_periodic_advertising_terminate_sync(uint16_t sync_handle);
/**
* @brief Get Manufactured
* @return manufacturer id
* @brief Get Controller Manufacturer
* @returns company_id - see bluetooth_company_id.h
*/
uint16_t hci_get_manufacturer(void);