Skip to content

Commit 0efea30

Browse files
authored
Merge pull request #11644 from MukundGitHub/cypress_cordio_driver_host_wake_logic_changes
Cypress Cordio BT Driver setting Host MCU active during Host Wake assert
2 parents dba8e77 + 352ac5e commit 0efea30

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

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

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
3434
dev_wake_irq_event(dev_wake_irq)
3535
{
3636
enabled_powersave = true;
37+
bt_host_wake_active = false;
3738
}
3839

3940
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
4647
bt_device_wake(bt_device_wake_name)
4748
{
4849
enabled_powersave = false;
50+
bt_host_wake_active = false;
4951
sleep_manager_lock_deep_sleep();
5052
holding_deep_sleep_lock = true;
5153
}
@@ -59,12 +61,36 @@ CyH4TransportDriver::~CyH4TransportDriver()
5961
}
6062
}
6163

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

7096
void CyH4TransportDriver::initialize()
@@ -92,17 +118,15 @@ void CyH4TransportDriver::initialize()
92118
SerialBase::RxIrq
93119
);
94120

121+
sleep_manager_unlock_deep_sleep();
122+
95123
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
96124
if (bt_host_wake_name != NC) {
97125
//Register IRQ for Host WAKE
98126
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-
}
127+
host_wake_pin->fall(callback(this, &CyH4TransportDriver::bt_host_wake_fall_irq_handler));
128+
host_wake_pin->rise(callback(this, &CyH4TransportDriver::bt_host_wake_rise_irq_handler));
104129
}
105-
106130
#endif
107131
if (dev_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
108132
if (bt_device_wake_name != NC)
@@ -136,26 +160,15 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
136160
return len;
137161
}
138162

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-
148163
void CyH4TransportDriver::on_controller_irq()
149164
{
150165
sleep_manager_lock_deep_sleep();
151-
assert_bt_dev_wake();
152166

153167
while (uart.readable()) {
154168
uint8_t char_received = uart.getc();
155169
on_data_received(&char_received, 1);
156170
}
157171

158-
deassert_bt_dev_wake();
159172
sleep_manager_unlock_deep_sleep();
160173
}
161174

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)