Skip to content

Commit f50417a

Browse files
committed
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.
1 parent ef4fe98 commit f50417a

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,36 @@ CyH4TransportDriver::~CyH4TransportDriver()
5959
}
6060
}
6161

62-
void CyH4TransportDriver::bt_host_wake_irq_handler(void)
62+
void CyH4TransportDriver::bt_host_wake_rise_irq_handler(void)
63+
{
64+
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
65+
if(bt_host_wake_active == true)
66+
{
67+
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
68+
sleep_manager_unlock_deep_sleep();
69+
bt_host_wake_active = false;
70+
}
71+
} else {
72+
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
73+
sleep_manager_lock_deep_sleep();
74+
bt_host_wake_active = true;
75+
}
76+
}
77+
78+
void CyH4TransportDriver::bt_host_wake_fall_irq_handler(void)
6379
{
64-
uart.attach(
65-
callback(this, &CyH4TransportDriver::on_controller_irq),
66-
SerialBase::RxIrq
67-
);
80+
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
81+
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
82+
sleep_manager_lock_deep_sleep();
83+
bt_host_wake_active = true;
84+
} else {
85+
if(bt_host_wake_active == true)
86+
{
87+
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
88+
sleep_manager_unlock_deep_sleep();
89+
bt_host_wake_active = false;
90+
}
91+
}
6892
}
6993

7094
void CyH4TransportDriver::initialize()
@@ -92,17 +116,15 @@ void CyH4TransportDriver::initialize()
92116
SerialBase::RxIrq
93117
);
94118

119+
sleep_manager_unlock_deep_sleep();
120+
95121
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
96122
if (bt_host_wake_name != NC) {
97123
//Register IRQ for Host WAKE
98124
host_wake_pin = new InterruptIn(bt_host_wake_name);
99-
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
100-
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_irq_handler));
101-
} else {
102-
host_wake_pin->rise(callback(this, &CyH4TransportDriver::bt_host_wake_irq_handler));
103-
}
125+
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_fall_irq_handler));
126+
host_wake_pin->rise(callback(this, &CyH4TransportDriver::bt_host_wake_rise_irq_handler));
104127
}
105-
106128
#endif
107129
if (dev_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
108130
if (bt_device_wake_name != NC)
@@ -136,26 +158,15 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
136158
return len;
137159
}
138160

139-
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
140-
void CyH4TransportDriver::on_host_stack_inactivity()
141-
{
142-
if (enabled_powersave) {
143-
uart.attach(NULL, SerialBase::RxIrq);
144-
}
145-
}
146-
#endif
147-
148161
void CyH4TransportDriver::on_controller_irq()
149162
{
150163
sleep_manager_lock_deep_sleep();
151-
assert_bt_dev_wake();
152164

153165
while (uart.readable()) {
154166
uint8_t char_received = uart.getc();
155167
on_data_received(&char_received, 1);
156168
}
157169

158-
deassert_bt_dev_wake();
159170
sleep_manager_unlock_deep_sleep();
160171
}
161172

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/CyH4TransportDriver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class CyH4TransportDriver : public cordio::CordioHCITransportDriver {
6464
*/
6565
virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData);
6666

67-
void bt_host_wake_irq_handler();
67+
void bt_host_wake_rise_irq_handler();
68+
void bt_host_wake_fall_irq_handler();
6869

6970
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
7071
void on_host_stack_inactivity();
@@ -93,6 +94,7 @@ class CyH4TransportDriver : public cordio::CordioHCITransportDriver {
9394

9495
DigitalInOut bt_host_wake;
9596
DigitalInOut bt_device_wake;
97+
bool bt_host_wake_active;
9698

9799
bool enabled_powersave;
98100
uint8_t host_wake_irq_event;

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/HCIDriver.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
171171
// Note: Reset is handled by ack_service_pack.
172172
case HCI_VS_CMD_SET_SLEEP_MODE:
173173
HciWriteLeHostSupport();
174+
sleep_manager_unlock_deep_sleep();
174175
break;
175176

176177
case HCI_OPCODE_WRITE_LE_HOST_SUPPORT:
@@ -318,13 +319,6 @@ class HCIDriver : public cordio::CordioHCIDriver {
318319
}
319320
}
320321

321-
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
322-
virtual void on_host_stack_inactivity(void)
323-
{
324-
cy_transport_driver.on_host_stack_inactivity();
325-
}
326-
#endif
327-
328322
private:
329323

330324
// send pre_brcm_patchram_buf issue hci reset and update baud rate on 43012
@@ -390,7 +384,6 @@ class HCIDriver : public cordio::CordioHCIDriver {
390384
#else /* BT_UART_NO_3M_SUPPORT */
391385
set_sleep_mode();
392386
#endif /* BT_UART_NO_3M_SUPPORT */
393-
sleep_manager_unlock_deep_sleep();
394387
}
395388

396389
void send_service_pack_command(void)
@@ -463,7 +456,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
463456
}
464457
}
465458

466-
// 0x18, 0xFC, 0x06, 0x00, 0x00, 0xC0, 0xC6, 0x2D, 0x00, //update uart baudrate 3 mbp
459+
// 0x18, 0xFC, 0x06, 0x00, 0x00, 0xC0, 0xC6, 0x2D, 0x00, //update uart baudrate 3 mbp
467460
void HciUpdateUartBaudRate()
468461
{
469462
uint8_t *pBuf;

0 commit comments

Comments
 (0)