summaryrefslogtreecommitdiffstats
path: root/tmk_core/common
diff options
context:
space:
mode:
authorpatrickmt <40182064+patrickmt@users.noreply.github.com>2018-12-18 15:21:25 -0500
committerDrashna Jaelre <drashna@live.com>2019-01-07 12:44:55 -0800
commit6e984a8b5e34ba181b0893a929af569a1faef2b6 (patch)
tree3648fd159ef02fe3ed7d8ae80c2755c580cd59ff /tmk_core/common
parent28986998046b4dbdbc228dbb7889836de2a3ee18 (diff)
Update to arm_atsam wait and timer routines
Microsecond (us) delays are now handled by a busy wait loop according to MCU frequency. This replaces the system counter method which had an overhead of around 12us. TC5 device and supporting routines removed as it was the old us delay counter. wait_ms is now properly a macro to CLK_delay_ms. wait_us is now properly a macro to CLK_delay_us. Removed CLK_get_us as it has no use. All calls to CLK_get_ms() have been replaced by timer_read64() with corrected typing. All calls to CLK_delay_ms() have been replaced by wait_ms(). All calls to CLK_delay_us() have been replaced by wait_us() and timings verified or updated as needed after review on scope. Corrected typing of variables using 64bit ms timer readings if needed.
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/arm_atsam/timer.c20
-rw-r--r--tmk_core/common/wait.h4
2 files changed, 6 insertions, 18 deletions
diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c
index bcfe5002c3..6c3905e308 100644
--- a/tmk_core/common/arm_atsam/timer.c
+++ b/tmk_core/common/arm_atsam/timer.c
@@ -9,7 +9,7 @@ void set_time(uint64_t tset)
void timer_init(void)
{
- ms_clk = 0;
+ timer_clear();
}
uint16_t timer_read(void)
@@ -37,23 +37,7 @@ uint32_t timer_elapsed32(uint32_t tlast)
return TIMER_DIFF_32(timer_read32(), tlast);
}
-uint32_t timer_elapsed64(uint32_t tlast)
-{
- uint64_t tnow = timer_read64();
- return (tnow >= tlast ? tnow - tlast : UINT64_MAX - tlast + tnow);
-}
-
void timer_clear(void)
{
- ms_clk = 0;
-}
-
-void wait_ms(uint64_t msec)
-{
- CLK_delay_ms(msec);
-}
-
-void wait_us(uint16_t usec)
-{
- CLK_delay_us(usec);
+ set_time(0);
}
diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h
index a7cded9420..a77840bcef 100644
--- a/tmk_core/common/wait.h
+++ b/tmk_core/common/wait.h
@@ -15,6 +15,10 @@ extern "C" {
# include "ch.h"
# define wait_ms(ms) chThdSleepMilliseconds(ms)
# define wait_us(us) chThdSleepMicroseconds(us)
+#elif defined PROTOCOL_ARM_ATSAM
+# include "clks.h"
+# define wait_ms(ms) CLK_delay_ms(ms)
+# define wait_us(us) CLK_delay_us(us)
#elif defined(__arm__)
# include "wait_api.h"
#else // Unit tests