rp2: Integrate soft_timer using the alarm pool.
The alarm pool is used to schedule the callback to soft_timer_handler(). Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
516cc280e0
commit
c9a9b2e682
|
@ -102,6 +102,7 @@ set(MICROPY_SOURCE_LIB
|
|||
${MICROPY_DIR}/shared/runtime/mpirq.c
|
||||
${MICROPY_DIR}/shared/runtime/pyexec.c
|
||||
${MICROPY_DIR}/shared/runtime/stdout_helpers.c
|
||||
${MICROPY_DIR}/shared/runtime/softtimer.c
|
||||
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
|
||||
${MICROPY_DIR}/shared/timeutils/timeutils.c
|
||||
${MICROPY_DIR}/shared/tinyusb/mp_cdc_common.c
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "shared/readline/readline.h"
|
||||
#include "shared/runtime/gchelper.h"
|
||||
#include "shared/runtime/pyexec.h"
|
||||
#include "shared/runtime/softtimer.h"
|
||||
#include "tusb.h"
|
||||
#include "uart.h"
|
||||
#include "modmachine.h"
|
||||
|
@ -212,6 +213,7 @@ int main(int argc, char **argv) {
|
|||
#if MICROPY_PY_THREAD
|
||||
mp_thread_deinit();
|
||||
#endif
|
||||
soft_timer_deinit();
|
||||
gc_sweep_all();
|
||||
mp_deinit();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
#include "py/mphal.h"
|
||||
#include "extmod/misc.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "shared/runtime/softtimer.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "shared/tinyusb/mp_usbd.h"
|
||||
#include "pendsv.h"
|
||||
#include "tusb.h"
|
||||
#include "uart.h"
|
||||
#include "hardware/rtc.h"
|
||||
|
@ -44,6 +46,8 @@
|
|||
// microseconds since the Epoch.
|
||||
STATIC uint64_t time_us_64_offset_from_epoch;
|
||||
|
||||
static alarm_id_t soft_timer_alarm_id = 0;
|
||||
|
||||
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
|
||||
|
||||
#ifndef MICROPY_HW_STDIN_BUFFER_LEN
|
||||
|
@ -260,3 +264,22 @@ void mp_hal_get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest) {
|
|||
uint32_t storage_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||
panic_unsupported();
|
||||
}
|
||||
|
||||
static int64_t soft_timer_callback(alarm_id_t id, void *user_data) {
|
||||
soft_timer_alarm_id = 0;
|
||||
pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
|
||||
return 0; // don't reschedule this alarm
|
||||
}
|
||||
|
||||
uint32_t soft_timer_get_ms(void) {
|
||||
return mp_hal_ticks_ms();
|
||||
}
|
||||
|
||||
void soft_timer_schedule_at_ms(uint32_t ticks_ms) {
|
||||
if (soft_timer_alarm_id != 0) {
|
||||
cancel_alarm(soft_timer_alarm_id);
|
||||
}
|
||||
int32_t ms = soft_timer_ticks_diff(ticks_ms, mp_hal_ticks_ms());
|
||||
ms = MAX(0, ms);
|
||||
soft_timer_alarm_id = add_alarm_in_ms(ms, soft_timer_callback, NULL, true);
|
||||
}
|
||||
|
|
|
@ -31,10 +31,14 @@
|
|||
#include "hardware/clocks.h"
|
||||
#include "hardware/structs/systick.h"
|
||||
#include "RP2040.h" // cmsis, for __WFI
|
||||
#include "pendsv.h"
|
||||
|
||||
#define SYSTICK_MAX (0xffffff)
|
||||
#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
|
||||
|
||||
#define MICROPY_PY_PENDSV_ENTER pendsv_suspend()
|
||||
#define MICROPY_PY_PENDSV_EXIT pendsv_resume()
|
||||
|
||||
extern int mp_interrupt_char;
|
||||
extern ringbuf_t stdin_ringbuf;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <stddef.h>
|
||||
|
||||
enum {
|
||||
PENDSV_DISPATCH_SOFT_TIMER,
|
||||
#if MICROPY_PY_LWIP
|
||||
PENDSV_DISPATCH_LWIP,
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue