diff --git a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.cpp b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.cpp index bbfe456b444..99d737db29b 100644 --- a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.cpp @@ -34,6 +34,7 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi dev_wake_irq_event(dev_wake_irq) { enabled_powersave = true; + bt_host_wake_active = false; } CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud) : @@ -46,6 +47,7 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi bt_device_wake(bt_device_wake_name) { enabled_powersave = false; + bt_host_wake_active = false; sleep_manager_lock_deep_sleep(); holding_deep_sleep_lock = true; } @@ -59,12 +61,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 +118,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 +160,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(); } diff --git a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.h b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.h index da94932481f..0cc27aa6e3b 100644 --- a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.h @@ -64,7 +64,8 @@ class CyH4TransportDriver : public cordio::CordioHCITransportDriver { */ 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 @@ class CyH4TransportDriver : public cordio::CordioHCITransportDriver { DigitalInOut bt_host_wake; DigitalInOut bt_device_wake; + bool bt_host_wake_active; bool enabled_powersave; uint8_t host_wake_irq_event; diff --git a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp index 2c1d941f83c..e51294df66c 100644 --- a/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp @@ -171,6 +171,7 @@ class HCIDriver : public cordio::CordioHCIDriver { // 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 @@ class HCIDriver : public cordio::CordioHCIDriver { } } -#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 @@ class HCIDriver : public cordio::CordioHCIDriver { #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 @@ class HCIDriver : public cordio::CordioHCIDriver { } } - // 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;