Changes to handle Ctrl-C during sleep
This commit is contained in:
parent
c2aa54ae66
commit
d948e6570f
@ -30,6 +30,7 @@
|
|||||||
#include "supervisor/port.h"
|
#include "supervisor/port.h"
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "modules/module.h"
|
#include "modules/module.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
@ -54,6 +55,7 @@
|
|||||||
|
|
||||||
uint32_t* heap;
|
uint32_t* heap;
|
||||||
uint32_t heap_size;
|
uint32_t heap_size;
|
||||||
|
extern TaskHandle_t xTaskToNotify;
|
||||||
|
|
||||||
STATIC esp_timer_handle_t _tick_timer;
|
STATIC esp_timer_handle_t _tick_timer;
|
||||||
|
|
||||||
@ -188,34 +190,28 @@ void port_disable_tick(void) {
|
|||||||
esp_timer_stop(_tick_timer);
|
esp_timer_stop(_tick_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TickType_t sleep_time_set;
|
|
||||||
TickType_t sleep_time_duration;
|
TickType_t sleep_time_duration;
|
||||||
|
uint32_t NotifyValue = 0;
|
||||||
|
BaseType_t notify_wait = 0;
|
||||||
|
|
||||||
void port_interrupt_after_ticks(uint32_t ticks) {
|
void port_interrupt_after_ticks(uint32_t ticks) {
|
||||||
sleep_time_set = xTaskGetTickCount();
|
sleep_time_duration = (ticks * 100)/1024;
|
||||||
sleep_time_duration = ticks / portTICK_PERIOD_MS;
|
xTaskToNotify = xTaskGetCurrentTaskHandle();
|
||||||
// esp_sleep_enable_timer_wakeup(uint64_t time_in_us)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void port_sleep_until_interrupt(void) {
|
void port_sleep_until_interrupt(void) {
|
||||||
// FreeRTOS delay here maybe.
|
|
||||||
// Light sleep shuts down BLE and wifi.
|
|
||||||
// esp_light_sleep_start()
|
|
||||||
if (sleep_time_duration == 0) {
|
if (sleep_time_duration == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Need to run in a loop in order to check if CTRL-C was received
|
notify_wait = xTaskNotifyWait(0x01,0x01,&NotifyValue,
|
||||||
TickType_t start_ticks = 0;
|
sleep_time_duration );
|
||||||
while (sleep_time_duration > start_ticks ) {
|
if (NotifyValue == 1) {
|
||||||
vTaskDelayUntil(&sleep_time_set, 1);
|
xTaskToNotify = NULL;
|
||||||
if ( mp_hal_is_interrupted() ) {
|
|
||||||
mp_handle_pending();
|
mp_handle_pending();
|
||||||
}
|
}
|
||||||
start_ticks = start_ticks + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Wrap main in app_main that the IDF expects.
|
// Wrap main in app_main that the IDF expects.
|
||||||
extern void main(void);
|
extern void main(void);
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
||||||
StaticTask_t usb_device_taskdef;
|
StaticTask_t usb_device_taskdef;
|
||||||
|
|
||||||
|
TaskHandle_t xTaskToNotify = NULL;
|
||||||
|
|
||||||
// USB Device Driver task
|
// USB Device Driver task
|
||||||
// This top level thread process all usb events and invoke callbacks
|
// This top level thread process all usb events and invoke callbacks
|
||||||
void usb_device_task(void* param)
|
void usb_device_task(void* param)
|
||||||
@ -114,3 +116,21 @@ void init_usb_hardware(void) {
|
|||||||
usb_device_stack,
|
usb_device_stack,
|
||||||
&usb_device_taskdef);
|
&usb_device_taskdef);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Callback invoked when received an "wanted" char.
|
||||||
|
* @param itf Interface index (for multiple cdc interfaces)
|
||||||
|
* @param wanted_char The wanted char (set previously)
|
||||||
|
*/
|
||||||
|
void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
|
||||||
|
{
|
||||||
|
(void) itf; // not used
|
||||||
|
// Workaround for using lib/utils/interrupt_char.c
|
||||||
|
// Compare mp_interrupt_char with wanted_char and ignore if not matched
|
||||||
|
if (mp_interrupt_char == wanted_char) {
|
||||||
|
tud_cdc_read_flush(); // flush read fifo
|
||||||
|
mp_keyboard_interrupt();
|
||||||
|
if (xTaskToNotify != NULL) {
|
||||||
|
xTaskNotifyGive(xTaskToNotify);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user