72 lines
2.2 KiB
Diff
72 lines
2.2 KiB
Diff
From 5e5d5894449dadfadfb1219d792d86bd0e4b16c2 Mon Sep 17 00:00:00 2001
|
|
From: giulcioffi <g.cioffi@arduino.cc>
|
|
Date: Wed, 30 Jun 2021 11:50:21 +0200
|
|
Subject: [PATCH 064/204] RP2040: us_ticker: fix missing interrupts after 32bit
|
|
wrap
|
|
|
|
---
|
|
.../TARGET_RP2040/us_ticker.c | 31 +++++++++++++++++--
|
|
1 file changed, 28 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/us_ticker.c b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/us_ticker.c
|
|
index 00edf82830..b3b8497188 100644
|
|
--- a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/us_ticker.c
|
|
+++ b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/us_ticker.c
|
|
@@ -53,11 +53,18 @@ const ticker_info_t* us_ticker_get_info()
|
|
return &info;
|
|
}
|
|
|
|
-const uint8_t alarm_num = 0;
|
|
+static const uint8_t alarm_num = 0;
|
|
+
|
|
+static void us_ticker_irq_handler_internal(uint alarm_src) {
|
|
+ if (alarm_num == alarm_src) {
|
|
+ us_ticker_irq_handler();
|
|
+ }
|
|
+}
|
|
|
|
void us_ticker_init(void)
|
|
{
|
|
- hardware_alarm_set_callback(alarm_num, us_ticker_irq_handler);
|
|
+ hardware_alarm_claim(alarm_num);
|
|
+ hardware_alarm_set_callback(alarm_num, us_ticker_irq_handler_internal);
|
|
}
|
|
|
|
uint32_t us_ticker_read()
|
|
@@ -68,8 +75,25 @@ uint32_t us_ticker_read()
|
|
void us_ticker_set_interrupt(timestamp_t timestamp)
|
|
{
|
|
core_util_critical_section_enter();
|
|
- absolute_time_t target = {timestamp};
|
|
+
|
|
+ uint64_t _timestamp = (uint64_t)timestamp;
|
|
+
|
|
+ if (timestamp < time_us_32()) {
|
|
+ //32 bit timestamp has been wrapped
|
|
+ //We need to provide a 64 bit timestamp able to fire the irq for this round
|
|
+ _timestamp = (((time_us_64() >> 32) + 1) << 32) + timestamp;
|
|
+ } else {
|
|
+ //Then, at the next round, wrap the 64 bit timer to follow the 32 bit one
|
|
+ if ((time_us_64() >> 32) > 0) {
|
|
+ uint64_t current_time = time_us_64();
|
|
+ uint64_t wrapped_time = current_time - 0xFFFFFFFF;
|
|
+ timer_hw->timelw = (uint32_t)wrapped_time;
|
|
+ timer_hw->timehw = 0;
|
|
+ }
|
|
+ }
|
|
+ absolute_time_t target = { _timestamp };
|
|
hardware_alarm_set_target(alarm_num, target);
|
|
+
|
|
core_util_critical_section_exit();
|
|
}
|
|
|
|
@@ -90,4 +114,5 @@ void us_ticker_clear_interrupt(void)
|
|
|
|
void us_ticker_free(void)
|
|
{
|
|
+ hardware_alarm_unclaim(alarm_num);
|
|
}
|
|
--
|
|
2.39.1
|
|
|