|
30 | 30 | #include "supervisor/port.h" |
31 | 31 | #include "boards/board.h" |
32 | 32 | #include "modules/module.h" |
| 33 | +#include "py/runtime.h" |
33 | 34 |
|
34 | 35 | #include "freertos/FreeRTOS.h" |
35 | 36 | #include "freertos/task.h" |
|
54 | 55 |
|
55 | 56 | uint32_t* heap; |
56 | 57 | uint32_t heap_size; |
| 58 | +extern TaskHandle_t xTaskToNotify; |
57 | 59 |
|
58 | 60 | STATIC esp_timer_handle_t _tick_timer; |
59 | 61 |
|
@@ -188,34 +190,28 @@ void port_disable_tick(void) { |
188 | 190 | esp_timer_stop(_tick_timer); |
189 | 191 | } |
190 | 192 |
|
191 | | -TickType_t sleep_time_set; |
192 | 193 | TickType_t sleep_time_duration; |
| 194 | +uint32_t NotifyValue = 0; |
| 195 | +BaseType_t notify_wait = 0; |
| 196 | + |
193 | 197 | void port_interrupt_after_ticks(uint32_t ticks) { |
194 | | - sleep_time_set = xTaskGetTickCount(); |
195 | | - sleep_time_duration = ticks / portTICK_PERIOD_MS; |
196 | | - // esp_sleep_enable_timer_wakeup(uint64_t time_in_us) |
| 198 | + sleep_time_duration = (ticks * 100)/1024; |
| 199 | + xTaskToNotify = xTaskGetCurrentTaskHandle(); |
197 | 200 | } |
198 | 201 |
|
199 | 202 | void port_sleep_until_interrupt(void) { |
200 | | - // FreeRTOS delay here maybe. |
201 | | - // Light sleep shuts down BLE and wifi. |
202 | | - // esp_light_sleep_start() |
| 203 | + |
203 | 204 | if (sleep_time_duration == 0) { |
204 | 205 | return; |
205 | 206 | } |
206 | | - // Need to run in a loop in order to check if CTRL-C was received |
207 | | - TickType_t start_ticks = 0; |
208 | | - while (sleep_time_duration > start_ticks ) { |
209 | | - vTaskDelayUntil(&sleep_time_set, 1); |
210 | | - if ( mp_hal_is_interrupted() ) { |
211 | | - mp_handle_pending(); |
212 | | - } |
213 | | - start_ticks = start_ticks + 1; |
214 | | - } |
215 | | - |
| 207 | + notify_wait = xTaskNotifyWait(0x01,0x01,&NotifyValue, |
| 208 | + sleep_time_duration ); |
| 209 | + if (NotifyValue == 1) { |
| 210 | + xTaskToNotify = NULL; |
| 211 | + mp_handle_pending(); |
| 212 | + } |
216 | 213 | } |
217 | 214 |
|
218 | | - |
219 | 215 | // Wrap main in app_main that the IDF expects. |
220 | 216 | extern void main(void); |
221 | 217 | void app_main(void) { |
|
0 commit comments