You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/01/31 08:20:28 UTC

[mynewt-core] 01/02: kernel/os: Add support for (1MHz/powerof2) cputime

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e57a369870934b60f82b185b3f65c0dfed5b4be3
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 28 15:22:58 2022 +0100

    kernel/os: Add support for (1MHz/powerof2) cputime
    
    This adds support for os_cputime working at frequency of 1MHz divided
    by power of 2. All integral frequencies are supported. This is to allow
    CMAC work at 31250 Hz.
---
 kernel/os/include/os/os_cputime.h | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/kernel/os/include/os/os_cputime.h b/kernel/os/include/os/os_cputime.h
index f0f1869..a6565e7 100644
--- a/kernel/os/include/os/os_cputime.h
+++ b/kernel/os/include/os/os_cputime.h
@@ -44,7 +44,13 @@ extern "C" {
  * definition for OS_CPUTIME_FREQ to the desired frequency in your project,
  * target or bsp.
  */
-#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 1000000)
+#if MYNEWT_VAL(OS_CPUTIME_FREQ) == 15625      ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 31250      ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 62500      ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 125000     ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 250000     ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 500000     ||  \
+    MYNEWT_VAL(OS_CPUTIME_FREQ) == 1000000
 
 #define OS_CPUTIME_FREQ_1MHZ
 
@@ -143,8 +149,19 @@ void os_cputime_delay_nsecs(uint32_t nsecs);
 #endif
 
 #if defined(OS_CPUTIME_FREQ_1MHZ)
-#define os_cputime_usecs_to_ticks(x)    (x)
-#define os_cputime_ticks_to_usecs(x)    (x)
+
+static inline uint32_t
+os_cputime_usecs_to_ticks(uint32_t usecs)
+{
+    return usecs / (1000000 / MYNEWT_VAL(OS_CPUTIME_FREQ));
+}
+
+static inline uint32_t
+os_cputime_ticks_to_usecs(uint32_t ticks)
+{
+    return ticks * (1000000 / MYNEWT_VAL(OS_CPUTIME_FREQ));
+}
+
 #else
 
 /**