hci transport h4/h5/em9304: ignore block read/sent from UART driver when closed

This commit is contained in:
Matthias Ringwald 2019-08-15 20:57:50 +02:00
parent 9fe804231b
commit c682b8ecdf
3 changed files with 25 additions and 2 deletions

View File

@ -63,6 +63,7 @@ static void em9304_spi_engine_run(void);
// state
static volatile enum {
SPI_EM9304_OFF,
SPI_EM9304_READY_FOR_TX,
SPI_EM9304_READY_FOR_TX_AND_RX,
SPI_EM9304_RX_W4_READ_COMMAND_SENT,
@ -324,6 +325,7 @@ static void em9304_spi_engine_init(void){
}
static void em9304_spi_engine_close(void){
em9304_spi_engine_state = SPI_EM9304_OFF;
btstack_em9304_spi->close();
}

View File

@ -106,6 +106,7 @@ static btstack_timer_source_t ehcill_sleep_ack_timer;
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
typedef enum {
H4_OFF,
H4_W4_PACKET_TYPE,
H4_W4_EVENT_HEADER,
H4_W4_ACL_HEADER,
@ -114,7 +115,8 @@ typedef enum {
} H4_STATE;
typedef enum {
TX_IDLE = 1,
TX_OFF,
TX_IDLE,
TX_W4_PACKET_SENT,
#ifdef ENABLE_EHCILL
TX_W4_WAKEUP,
@ -389,6 +391,10 @@ static void hci_transport_h4_init(const void * transport_config){
uart_config.flowcontrol = hci_transport_config_uart->flowcontrol;
uart_config.device_name = hci_transport_config_uart->device_name;
// set state to off
tx_state = TX_OFF;
h4_state = H4_OFF;
// setup UART driver
btstack_uart->init(&uart_config);
btstack_uart->set_block_received(&hci_transport_h4_block_read);
@ -396,13 +402,15 @@ static void hci_transport_h4_init(const void * transport_config){
}
static int hci_transport_h4_open(void){
// open uart driver
int res = btstack_uart->open();
if (res){
return res;
}
// init rx + tx state machines
hci_transport_h4_reset_statemachine();
hci_transport_h4_trigger_next_read();
tx_state = TX_IDLE;
#ifdef ENABLE_EHCILL
@ -412,6 +420,11 @@ static int hci_transport_h4_open(void){
}
static int hci_transport_h4_close(void){
// set state to off
tx_state = TX_OFF;
h4_state = H4_OFF;
// close uart driver
return btstack_uart->close();
}

View File

@ -728,6 +728,7 @@ static void hci_transport_link_update_resend_timeout(uint32_t baudrate){
/// H5 Interface
static uint8_t hci_transport_link_read_byte;
static int hci_transport_h5_active;
static void hci_transport_h5_read_next_byte(void){
btstack_uart->receive_block(&hci_transport_link_read_byte, 1);
@ -736,6 +737,8 @@ static void hci_transport_h5_read_next_byte(void){
// track time receiving SLIP frame
static uint32_t hci_transport_h5_receive_start;
static void hci_transport_h5_block_received(){
if (hci_transport_h5_active == 0) return;
// track start time when receiving first byte // a bit hackish
if (hci_transport_h5_receive_start == 0 && hci_transport_link_read_byte != BTSTACK_SLIP_SOF){
hci_transport_h5_receive_start = btstack_run_loop_get_time_ms();
@ -757,6 +760,7 @@ static void hci_transport_h5_block_received(){
}
static void hci_transport_h5_block_sent(void){
if (hci_transport_h5_active == 0) return;
// check if more data to send
if (btstack_slip_encoder_has_data()){
@ -793,6 +797,8 @@ static void hci_transport_h5_init(const void * transport_config){
return;
}
hci_transport_h5_active = 0;
// extract UART config from transport config
hci_transport_config_uart_t * hci_transport_config_uart = (hci_transport_config_uart_t*) transport_config;
uart_config.baudrate = hci_transport_config_uart->baudrate_init;
@ -840,12 +846,14 @@ static int hci_transport_h5_open(void){
hci_transport_link_init();
// start receiving
hci_transport_h5_active = 1;
hci_transport_h5_read_next_byte();
return 0;
}
static int hci_transport_h5_close(void){
hci_transport_h5_active = 0;
return btstack_uart->close();
}