@@ -49,10 +49,8 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
49
49
bt_device_wake (bt_device_wake_name, PIN_OUTPUT, PullNone, 1 ),
50
50
host_wake_irq_event (host_wake_irq),
51
51
dev_wake_irq_event (dev_wake_irq)
52
-
53
52
{
54
53
enabled_powersave = true ;
55
- bt_host_wake_active = false ;
56
54
}
57
55
58
56
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
70
68
71
69
{
72
70
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 ;
78
71
}
79
72
80
73
CyH4TransportDriver::~CyH4TransportDriver ()
81
74
{
82
- if (holding_deep_sleep_lock)
83
- {
84
- sleep_manager_unlock_deep_sleep ();
85
- holding_deep_sleep_lock = false ;
86
- }
75
+
87
76
}
88
77
89
78
void CyH4TransportDriver::bt_host_wake_rise_irq_handler (void )
90
79
{
91
80
if (host_wake_irq_event == WAKE_EVENT_ACTIVE_LOW) {
92
81
if (bt_host_wake_active == true )
93
82
{
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 */
95
84
sleep_manager_unlock_deep_sleep ();
96
85
bt_host_wake_active = false ;
97
86
}
98
87
} 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 */
100
89
sleep_manager_lock_deep_sleep ();
101
90
bt_host_wake_active = true ;
102
91
}
@@ -105,13 +94,13 @@ void CyH4TransportDriver::bt_host_wake_rise_irq_handler(void)
105
94
void CyH4TransportDriver::bt_host_wake_fall_irq_handler (void )
106
95
{
107
96
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 */
109
98
sleep_manager_lock_deep_sleep ();
110
99
bt_host_wake_active = true ;
111
100
} else {
112
101
if (bt_host_wake_active == true )
113
102
{
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 */
115
104
sleep_manager_unlock_deep_sleep ();
116
105
bt_host_wake_active = false ;
117
106
}
@@ -150,6 +139,18 @@ static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
150
139
151
140
void CyH4TransportDriver::initialize ()
152
141
{
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 ;
153
154
sleep_manager_lock_deep_sleep ();
154
155
155
156
bt_power = 0 ;
@@ -202,7 +203,6 @@ void CyH4TransportDriver::initialize()
202
203
if (bt_device_wake_name != NC)
203
204
bt_device_wake = WAKE_EVENT_ACTIVE_HIGH;
204
205
}
205
- sleep_manager_unlock_deep_sleep ();
206
206
}
207
207
208
208
void CyH4TransportDriver::terminate ()
@@ -236,6 +236,13 @@ void CyH4TransportDriver::terminate()
236
236
#else
237
237
cyhal_uart_free (&uart);
238
238
#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
+ }
239
246
}
240
247
241
248
uint16_t CyH4TransportDriver::write (uint8_t type, uint16_t len, uint8_t *pData)
0 commit comments