Skip to content

Commit df00ed4

Browse files
authored
Merge pull request #14982 from npal-cy/pr/swintegration-481
CYW43XXX Cordio HCI driver: fixed MCU deep-sleep locking flow
2 parents 9bcc486 + 1d6843e commit df00ed4

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

connectivity/drivers/ble/FEATURE_BLE/COMPONENT_CYW43XXX/CyH4TransportDriver.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
4949
bt_device_wake(bt_device_wake_name, PIN_OUTPUT, PullNone, 1),
5050
host_wake_irq_event(host_wake_irq),
5151
dev_wake_irq_event(dev_wake_irq)
52-
5352
{
5453
enabled_powersave = true;
55-
bt_host_wake_active = false;
5654
}
5755

5856
CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud) :
@@ -70,33 +68,24 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
7068

7169
{
7270
enabled_powersave = false;
73-
bt_host_wake_active = false;
74-
75-
sleep_manager_lock_deep_sleep(); // locking deep sleep because this option
76-
// does not include a host wake pin
77-
holding_deep_sleep_lock = true;
7871
}
7972

8073
CyH4TransportDriver::~CyH4TransportDriver()
8174
{
82-
if (holding_deep_sleep_lock)
83-
{
84-
sleep_manager_unlock_deep_sleep();
85-
holding_deep_sleep_lock = false;
86-
}
75+
8776
}
8877

8978
void CyH4TransportDriver::bt_host_wake_rise_irq_handler(void)
9079
{
9180
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
9281
if(bt_host_wake_active == true)
9382
{
94-
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
83+
/* lock MCU Deep Sleep entry as long as host_wake is asserted */
9584
sleep_manager_unlock_deep_sleep();
9685
bt_host_wake_active = false;
9786
}
9887
} else {
99-
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
88+
/* lock MCU Deep Sleep entry as long as host_wake is asserted */
10089
sleep_manager_lock_deep_sleep();
10190
bt_host_wake_active = true;
10291
}
@@ -105,13 +94,13 @@ void CyH4TransportDriver::bt_host_wake_rise_irq_handler(void)
10594
void CyH4TransportDriver::bt_host_wake_fall_irq_handler(void)
10695
{
10796
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
108-
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
97+
/* lock MCU Deep Sleep entry as long as host_wake is asserted */
10998
sleep_manager_lock_deep_sleep();
11099
bt_host_wake_active = true;
111100
} else {
112101
if(bt_host_wake_active == true)
113102
{
114-
/* lock PSoC 6 DeepSleep entry as long as host_wake is asserted */
103+
/* lock MCU Deep Sleep entry as long as host_wake is asserted */
115104
sleep_manager_unlock_deep_sleep();
116105
bt_host_wake_active = false;
117106
}
@@ -150,6 +139,18 @@ static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
150139

151140
void CyH4TransportDriver::initialize()
152141
{
142+
// Initial MCU Deep Sleep locking. CyH4TransportDriver has the following MCU Deep Sleep locking
143+
// scenarios:
144+
// a) A BT device or MCU does not support Low Power mode (MBED configuration does not include
145+
// MBED_TICKLESS, DEVICE_SLEEP, DEVICE_LPTICKER or CYCFG_BT_LP_ENABLED features).
146+
// In this case, CyH4TransportDriver locks Deep Sleep in the initialize() function and
147+
// unlocks the terminate() function.
148+
// b) A BT device and MCU support Low Power mode.
149+
// In this case, the control of the unlock/lock of the Deep Sleep
150+
// functionality will be done in bt_host_wake_rise_irq_handler and bt_host_wake_fall_irq_handler
151+
// handlers. Finally, CyH4TransportDriver unlocks the Deep Sleep in terminate() function
152+
// (if it was locked before) by checking the bt_host_wake_active flag.
153+
bt_host_wake_active = true;
153154
sleep_manager_lock_deep_sleep();
154155

155156
bt_power = 0;
@@ -202,7 +203,6 @@ void CyH4TransportDriver::initialize()
202203
if (bt_device_wake_name != NC)
203204
bt_device_wake = WAKE_EVENT_ACTIVE_HIGH;
204205
}
205-
sleep_manager_unlock_deep_sleep();
206206
}
207207

208208
void CyH4TransportDriver::terminate()
@@ -236,6 +236,13 @@ void CyH4TransportDriver::terminate()
236236
#else
237237
cyhal_uart_free(&uart);
238238
#endif
239+
240+
// Unlock Deep Sleep if it was locked by CyH4TransportDriver before.
241+
if (bt_host_wake_active == true)
242+
{
243+
sleep_manager_unlock_deep_sleep();
244+
bt_host_wake_active = false;
245+
}
239246
}
240247

241248
uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)

connectivity/drivers/ble/FEATURE_BLE/COMPONENT_CYW43XXX/CyH4TransportDriver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
123123
bool enabled_powersave;
124124
uint8_t host_wake_irq_event;
125125
uint8_t dev_wake_irq_event;
126-
127-
bool holding_deep_sleep_lock;
128126
};
129127

130128
} // namespace cypress

connectivity/drivers/ble/FEATURE_BLE/COMPONENT_CYW43XXX/HCIDriver.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ class HCIDriver : public CordioHCIDriver {
101101

102102
virtual void do_initialize()
103103
{
104-
//Prevent PSoC6 to enter deep-sleep till BT initialization is complete
105-
sleep_manager_lock_deep_sleep();
106104
rtos::ThisThread::sleep_for(500ms);
107105
bt_power = 1;
108106
rtos::ThisThread::sleep_for(500ms);
@@ -175,7 +173,6 @@ class HCIDriver : public CordioHCIDriver {
175173
// Note: Reset is handled by ack_service_pack.
176174
case HCI_VS_CMD_SET_SLEEP_MODE:
177175
HciWriteLeHostSupport();
178-
sleep_manager_unlock_deep_sleep();
179176
break;
180177

181178
case HCI_OPCODE_WRITE_LE_HOST_SUPPORT:

0 commit comments

Comments
 (0)