Update Target Cypress Specific Cordio BT Driver to keep Host MCU active for the duration BT device asserts HOST WAKE. This change fixes race condition in Cypress Cordio driver.

pull/11644/head
Mukund Ghonasgi 2019-10-07 14:42:53 -07:00
parent ef4fe9852f
commit f50417a3a0
3 changed files with 38 additions and 32 deletions

View File

@ -59,12 +59,36 @@ CyH4TransportDriver::~CyH4TransportDriver()
}
}
void CyH4TransportDriver::bt_host_wake_irq_handler(void)
void CyH4TransportDriver::bt_host_wake_rise_irq_handler(void)
{
uart.attach(
callback(this, &CyH4TransportDriver::on_controller_irq),
SerialBase::RxIrq
);
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
if(bt_host_wake_active == true)
{
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
sleep_manager_unlock_deep_sleep();
bt_host_wake_active = false;
}
} else {
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
sleep_manager_lock_deep_sleep();
bt_host_wake_active = true;
}
}
void CyH4TransportDriver::bt_host_wake_fall_irq_handler(void)
{
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
sleep_manager_lock_deep_sleep();
bt_host_wake_active = true;
} else {
if(bt_host_wake_active == true)
{
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
sleep_manager_unlock_deep_sleep();
bt_host_wake_active = false;
}
}
}
void CyH4TransportDriver::initialize()
@ -92,17 +116,15 @@ void CyH4TransportDriver::initialize()
SerialBase::RxIrq
);
sleep_manager_unlock_deep_sleep();
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
if (bt_host_wake_name != NC) {
//Register IRQ for Host WAKE
host_wake_pin = new InterruptIn(bt_host_wake_name);
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_irq_handler));
} else {
host_wake_pin->rise(callback(this, &CyH4TransportDriver::bt_host_wake_irq_handler));
}
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_fall_irq_handler));
host_wake_pin->rise(callback(this, &CyH4TransportDriver::bt_host_wake_rise_irq_handler));
}
#endif
if (dev_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
if (bt_device_wake_name != NC)
@ -136,26 +158,15 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
return len;
}
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
void CyH4TransportDriver::on_host_stack_inactivity()
{
if (enabled_powersave) {
uart.attach(NULL, SerialBase::RxIrq);
}
}
#endif
void CyH4TransportDriver::on_controller_irq()
{
sleep_manager_lock_deep_sleep();
assert_bt_dev_wake();
while (uart.readable()) {
uint8_t char_received = uart.getc();
on_data_received(&char_received, 1);
}
deassert_bt_dev_wake();
sleep_manager_unlock_deep_sleep();
}

View File

@ -64,7 +64,8 @@ public:
*/
virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
void bt_host_wake_irq_handler();
void bt_host_wake_rise_irq_handler();
void bt_host_wake_fall_irq_handler();
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
void on_host_stack_inactivity();
@ -93,6 +94,7 @@ private:
DigitalInOut bt_host_wake;
DigitalInOut bt_device_wake;
bool bt_host_wake_active;
bool enabled_powersave;
uint8_t host_wake_irq_event;

View File

@ -171,6 +171,7 @@ public:
// Note: Reset is handled by ack_service_pack.
case HCI_VS_CMD_SET_SLEEP_MODE:
HciWriteLeHostSupport();
sleep_manager_unlock_deep_sleep();
break;
case HCI_OPCODE_WRITE_LE_HOST_SUPPORT:
@ -318,13 +319,6 @@ public:
}
}
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
virtual void on_host_stack_inactivity(void)
{
cy_transport_driver.on_host_stack_inactivity();
}
#endif
private:
// send pre_brcm_patchram_buf issue hci reset and update baud rate on 43012
@ -390,7 +384,6 @@ private:
#else /* BT_UART_NO_3M_SUPPORT */
set_sleep_mode();
#endif /* BT_UART_NO_3M_SUPPORT */
sleep_manager_unlock_deep_sleep();
}
void send_service_pack_command(void)
@ -463,7 +456,7 @@ private:
}
}
// 0x18, 0xFC, 0x06, 0x00, 0x00, 0xC0, 0xC6, 0x2D, 0x00, //update uart baudrate 3 mbp
// 0x18, 0xFC, 0x06, 0x00, 0x00, 0xC0, 0xC6, 0x2D, 0x00, //update uart baudrate 3 mbp
void HciUpdateUartBaudRate()
{
uint8_t *pBuf;