mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user