Skip to content

Commit

Permalink
Merge pull request ARMmbed#11644 from MukundGitHub/cypress_cordio_dri…
Browse files Browse the repository at this point in the history
…ver_host_wake_logic_changes

Cypress Cordio BT Driver setting Host MCU active during Host Wake assert
  • Loading branch information
0xc0170 authored Oct 17, 2019
2 parents dba8e77 + 352ac5e commit 0efea30
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand All @@ -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;
}
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0efea30

Please sign in to comment.