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/02/12 11:13:12 UTC

[mynewt-core] branch master updated (6fef283 -> 1d08a37)

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

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


    from 6fef283  hw/nrf53: Add option to use internal load caps for lfxo
     new 68e84aa  hw/bsp/cmac: Switch to 31250Hz cputime
     new 1d08a37  hw/mcu/cmac: Use 31250Hz for hal_timer and os_tick

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/dialog_cmac/syscfg.yml               |   2 +-
 hw/mcu/dialog/cmac/include/mcu/cmac_timer.h | 147 ++++++++++------------------
 hw/mcu/dialog/cmac/src/cmac_sleep.c         |   3 +-
 hw/mcu/dialog/cmac/src/cmac_timer.c         |  66 +++++--------
 hw/mcu/dialog/cmac/src/hal_os_tick.c        |  25 +----
 hw/mcu/dialog/cmac/src/hal_timer.c          |  74 +++-----------
 hw/mcu/dialog/cmac/syscfg.yml               |   2 +-
 7 files changed, 94 insertions(+), 225 deletions(-)

[mynewt-core] 01/02: hw/bsp/cmac: Switch to 31250Hz cputime

Posted by an...@apache.org.
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 68e84aae822e3314eecceb555be38e9d013d704b
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 28 15:23:56 2022 +0100

    hw/bsp/cmac: Switch to 31250Hz cputime
---
 hw/bsp/dialog_cmac/syscfg.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/bsp/dialog_cmac/syscfg.yml b/hw/bsp/dialog_cmac/syscfg.yml
index 5c8dee0..91c0408 100644
--- a/hw/bsp/dialog_cmac/syscfg.yml
+++ b/hw/bsp/dialog_cmac/syscfg.yml
@@ -19,7 +19,7 @@
 
 syscfg.vals:
     MSYS_1_BLOCK_SIZE: 308
-    OS_CPUTIME_FREQ: 32768
+    OS_CPUTIME_FREQ: 31250
     BLE_HCI_TRANSPORT: dialog_cmac
 
 syscfg.restrictions:

[mynewt-core] 02/02: hw/mcu/cmac: Use 31250Hz for hal_timer and os_tick

Posted by an...@apache.org.
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 1d08a3700e3ee45f3876bd3d8d4756fead9b224c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 28 15:24:24 2022 +0100

    hw/mcu/cmac: Use 31250Hz for hal_timer and os_tick
    
    Using 31250 instead of 32768 saves us a lot of time since conversions
    from/to LL timer are much much simpler: we just need to shift by 5 bits
    instead of some time consuming (at least on CM0+) arithmetic that needs
    to be optimized with all sort of nasty workarounds.
    
    Since the difference in frequency is small, we still have pretty much
    the same tick duration (30.5us vs. 32us) so the impact on scheduling
    using os_cputime is negligible.
    
    Using 31250 tps for os_tick does not really matter since we only want
    to support running NimBLE LL on CMAC and that code does not really use
    os_tick anywhere so it will just use larger values (ticks) for sleep.
---
 hw/mcu/dialog/cmac/include/mcu/cmac_timer.h | 147 ++++++++++------------------
 hw/mcu/dialog/cmac/src/cmac_sleep.c         |   3 +-
 hw/mcu/dialog/cmac/src/cmac_timer.c         |  66 +++++--------
 hw/mcu/dialog/cmac/src/hal_os_tick.c        |  25 +----
 hw/mcu/dialog/cmac/src/hal_timer.c          |  74 +++-----------
 hw/mcu/dialog/cmac/syscfg.yml               |   2 +-
 6 files changed, 93 insertions(+), 224 deletions(-)

diff --git a/hw/mcu/dialog/cmac/include/mcu/cmac_timer.h b/hw/mcu/dialog/cmac/include/mcu/cmac_timer.h
index ca93ef7..4d5f5d0 100644
--- a/hw/mcu/dialog/cmac/include/mcu/cmac_timer.h
+++ b/hw/mcu/dialog/cmac/include/mcu/cmac_timer.h
@@ -27,23 +27,6 @@
 extern "C" {
 #endif
 
-/*
- * Equals to LLT value after HAL timer wrapped around,
- * i.e. os_cputime(0xffffffff "+1")
- */
-#define CMAC_TIMER_LLT_AT_HAL_WRAP_AROUND_VAL   (0x1e84800000)
-
-#define CMAC_TIMER_HAL_GT(_t1, _t2)             ((int32_t)((_t1) - (_t2)) > 0)
-#define CMAC_TIMER_HAL_LT(_t1, _t2)             ((int32_t)((_t1) - (_t2)) < 0)
-
-struct cmac_timer_ctrl {
-    uint32_t llt_last_hi_val;
-    uint64_t llt_corr;
-
-    uint32_t hal_last_val;
-    uint64_t hal_to_llt_corr;
-};
-
 typedef void (cmac_timer_int_func_t)(void);
 
 extern volatile uint32_t cm_ll_int_stat_reg;
@@ -84,7 +67,7 @@ cmac_timer_read_hi(void)
     return CMAC->CM_LL_TIMER1_36_10_REG;
 }
 
-/* Reads lsb 32-bit value of LL Timer */
+/* Reads lsb 32-bit value of LL Timer (31..0) */
 static inline uint32_t
 cmac_timer_read32(void)
 {
@@ -99,38 +82,34 @@ cmac_timer_read32(void)
     return (hi << 10) | lo;
 }
 
-/* Reads full 37-bit value of LL Timer */
-static inline uint64_t
-cmac_timer_read64(void)
+/* Reads msb 32-bit value of LL Timer (36..5) */
+static inline uint32_t
+cmac_timer_read32_msb(void)
 {
     uint32_t hi;
     uint32_t lo;
-    uint32_t llt_corr;
 
     do {
         hi = cmac_timer_read_hi();
         lo = cmac_timer_read_lo();
     } while (hi != cmac_timer_read_hi());
 
-    __disable_irq();
-
-    /*
-     * We extend LLT value manually to full 64-bit timer, this gives us plenty
-     * of resolution so we don't really need to care about wrap around. Note
-     * that we keep track of hi-word correction only (bits 63:37) so there is
-     * no need for 64-bit calculations on correction value - final shift by 32
-     * bits is optimized by a compiler to a simple 32-bit operation on hi-word.
-     */
+    return (hi << 5) | lo >> 5;
+}
 
-    if (hi < g_cmac_timer_ctrl.llt_last_hi_val) {
-        g_cmac_timer_ctrl.llt_corr += 1 << 5;
-    }
-    g_cmac_timer_ctrl.llt_last_hi_val = hi;
-    llt_corr = g_cmac_timer_ctrl.llt_corr;
+/* Reads full 37-bit value of LL Timer (36..0) */
+static inline uint64_t
+cmac_timer_read37(void)
+{
+    uint32_t hi;
+    uint32_t lo;
 
-    __enable_irq();
+    do {
+        hi = cmac_timer_read_hi();
+        lo = cmac_timer_read_lo();
+    } while (hi != cmac_timer_read_hi());
 
-    return ((uint64_t)llt_corr << 32) | ((uint64_t)hi << 10) | lo;
+    return ((uint64_t)hi << 10) | lo;
 }
 
 static inline void
@@ -142,10 +121,10 @@ cmac_timer_trigger_hal(void)
 
 /* Write comparator value for hal_timer callback */
 static inline void
-cmac_timer_write_eq_hal_timer(uint64_t val)
+cmac_timer_write_eq_hal_timer(uint32_t val)
 {
-    CMAC->CM_LL_TIMER1_EQ_X_HI_REG = val >> 10;
-    CMAC->CM_LL_TIMER1_EQ_X_LO_REG = val;
+    CMAC->CM_LL_TIMER1_EQ_X_HI_REG = val >> 5;
+    CMAC->CM_LL_TIMER1_EQ_X_LO_REG = val << 5;
     CMAC->CM_LL_INT_MSK_SET_REG = CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_EQ_X_SEL_Msk;
 
     /*
@@ -154,7 +133,7 @@ cmac_timer_write_eq_hal_timer(uint64_t val)
      * comparator as triggered so we just use local variable as a "shadow"
      * register.
      */
-    if ((int64_t)(val - cmac_timer_read64()) <= 0) {
+    if ((int32_t)(val - cmac_timer_read32_msb()) <= 0) {
         cm_ll_int_stat_reg = CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_EQ_X_SEL_Msk;
         NVIC_SetPendingIRQ(LL_TIMER2LLC_IRQn);
     }
@@ -167,69 +146,43 @@ cmac_timer_disable_eq_hal_timer(void)
     CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_EQ_X_SEL_Msk;
 }
 
-/* Write comparator value for hal_os_tick callback */
-static inline void
-cmac_timer_write_eq_hal_os_tick(uint64_t val)
-{
-    uint32_t val_hi;
-
-    val_hi = (val >> 10) & 0x7ffffff;
-
-    CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG = val_hi;
-
-    if ((int32_t)(val_hi - cmac_timer_read_hi()) <= 0) {
-        cm_ll_int_stat_reg = CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
-        NVIC_SetPendingIRQ(LL_TIMER2LLC_IRQn);
-    }
-}
-
-/* Convert ll_timer value to hal_timer value */
-static inline uint64_t
-cmac_timer_convert_llt2hal(uint64_t val)
-{
-    return (val << 9) / 15625;
-}
-
-/* Convert ll_timer value to os_tick value */
 static inline uint32_t
-cmac_timer_convert_llt2tck(uint64_t val)
+cmac_timer_read_eq_hal_os_tick(void)
 {
-    return (val << 1) / 15625;
+    return (CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG << 5) |
+           (CMAC->CM_LL_TIMER1_9_0_EQ_Y_REG >> 5);
 }
 
-/* Convert hal_timer value to ll_timer value */
-static inline uint64_t
-cmac_timer_convert_hal2llt(uint32_t val)
+/* Write comparator value for hal_os_tick callback */
+static inline void
+cmac_timer_write_eq_hal_os_tick(uint32_t val)
 {
-    uint64_t llt;
-    uint32_t v1, v2;
-    int64_t dt;
+    uint32_t val_36_10;
 
-    /*
-     * Use known HAL timer value and LLT value pair as a base, then apply
-     * correction based on delta between known HAL timer value and value being
-     * converted.
-     */
-
-    __disable_irq();
-
-    v1 = g_cmac_timer_ctrl.hal_last_val;
-    v2 = val;
-    llt = g_cmac_timer_ctrl.hal_to_llt_corr;
+    val_36_10 = val >> 5;
+    CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG = val_36_10;
+    CMAC->CM_LL_TIMER1_9_0_EQ_Y_REG = val << 5;
 
-    __enable_irq();
-
-    dt = (int32_t)(v2 - v1);
-    llt += (dt * 15625) / 512;
-
-    return llt;
-}
+    /* If msb comparator is set at least 2 "ticks" ahead, we can enable it here
+     * and then enable lsb comparator on match. Otherwise, we need to enable lsb
+     * comparator here to make sure we do not miss a match in case lsb matches
+     * just after msb (we would not be able to switch from msb to lsb comparator
+     * on time).
+     */
+    if ((int32_t)(val_36_10 - CMAC->CM_LL_TIMER1_36_10_REG) >= 2) {
+        CMAC->CM_LL_INT_MSK_SET_REG = CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+        CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
+    } else {
+        CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+        CMAC->CM_LL_INT_MSK_SET_REG = CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
+    }
 
-/* Convert os_tick value to ll_timer value */
-static inline uint64_t
-cmac_timer_convert_tck2llt(uint32_t val)
-{
-    return ((uint64_t)val * 15625) >> 1;
+    if ((int32_t)(val - cmac_timer_read32_msb()) <= 0) {
+        CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+        CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
+        cm_ll_int_stat_reg = CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
+        NVIC_SetPendingIRQ(LL_TIMER2LLC_IRQn);
+    }
 }
 
 #ifdef __cplusplus
diff --git a/hw/mcu/dialog/cmac/src/cmac_sleep.c b/hw/mcu/dialog/cmac/src/cmac_sleep.c
index 5571722..b3158da 100644
--- a/hw/mcu/dialog/cmac/src/cmac_sleep.c
+++ b/hw/mcu/dialog/cmac/src/cmac_sleep.c
@@ -40,9 +40,10 @@ static __IOM uint32_t * const retained_regs[] = {
     &CMAC->CM_CTRL2_REG,
     &CMAC->CM_LL_INT_MSK_SET_REG,
     &CMAC->CM_LL_INT_SEL_REG,
-    &CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG,
     &CMAC->CM_LL_TIMER1_EQ_X_HI_REG,
     &CMAC->CM_LL_TIMER1_EQ_X_LO_REG,
+    &CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG,
+    &CMAC->CM_LL_TIMER1_9_0_EQ_Y_REG,
     &CMAC->CM_ERROR_DIS_REG,
 #if MYNEWT_VAL(CMAC_DEBUG_DIAG_ENABLE)
     &CMAC->CM_DIAG_PORT0_REG,
diff --git a/hw/mcu/dialog/cmac/src/cmac_timer.c b/hw/mcu/dialog/cmac/src/cmac_timer.c
index 6c51789..0b828f9 100644
--- a/hw/mcu/dialog/cmac/src/cmac_timer.c
+++ b/hw/mcu/dialog/cmac/src/cmac_timer.c
@@ -27,15 +27,6 @@
 #include "os/os.h"
 #include "CMAC.h"
 
-/*
- * Least common multiple for 1/128 (os_tick) and 1/1000000 (ll_timer) is 2s, so
- * we want to use 2s as sync interval to guarantee that synced tick value is not
- * rounded. Any other value effectively disables tick sync and enables full
- * recalculation every time.
- */
-#define SYNC_TICK_VAL_INTERVAL              (2000000)
-#define SYNC_TICK_TICKS_PER_VAL_INTERVAL    ((SYNC_TICK_VAL_INTERVAL) / 1000000 * 128)
-
 #define COMP_TICK_HAS_PASSED(_num) \
     (CMAC->CM_EV_LATCHED_REG & \
      (CMAC_CM_EV_LATCHED_REG_EV1C_CLK_1US_X1_Msk << ((_num) - 1)))
@@ -49,7 +40,6 @@ struct cmac_timer_slp {
 };
 
 static struct cmac_timer_slp g_cmac_timer_slp;
-struct cmac_timer_ctrl g_cmac_timer_ctrl;
 
 static cmac_timer_int_func_t *cmac_timer_int_hal_timer;
 static cmac_timer_int_func_t *cmac_timer_int_hal_os_tick;
@@ -60,6 +50,7 @@ void
 LL_TIMER2LLC_IRQHandler(void)
 {
     uint32_t int_stat;
+    uint32_t val;
 
     /* Clear interrupt now since callback may set comparators again */
     int_stat = CMAC->CM_LL_INT_STAT_REG | cm_ll_int_stat_reg;
@@ -72,7 +63,15 @@ LL_TIMER2LLC_IRQHandler(void)
     }
 
     if (int_stat & CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk) {
-        cmac_timer_int_hal_os_tick();
+        CMAC->CM_LL_INT_MSK_CLR_REG = CMAC_CM_LL_INT_MSK_CLR_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+        CMAC->CM_LL_INT_MSK_SET_REG = CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
+    }
+
+    if (int_stat & CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk) {
+        val = cmac_timer_read_eq_hal_os_tick();
+        if ((int32_t)(val - cmac_timer_read32_msb()) <= 0) {
+            cmac_timer_int_hal_os_tick();
+        }
     }
 }
 
@@ -277,30 +276,7 @@ compensate_ll_timer(uint32_t slept_us)
 uint32_t
 cmac_timer_get_hal_os_tick(void)
 {
-    static uint32_t sync_tick = 0;
-    static uint64_t sync_tick_val = 0;
-    static uint64_t sync_tick_val_next = SYNC_TICK_VAL_INTERVAL;
-    uint64_t val;
-    uint32_t rem_val;
-    uint32_t ret;
-
-    val = cmac_timer_read64();
-
-    if (SYNC_TICK_VAL_INTERVAL == 2000000) {
-        while (val >= sync_tick_val_next) {
-            sync_tick_val = sync_tick_val_next;
-            sync_tick += SYNC_TICK_TICKS_PER_VAL_INTERVAL;
-            sync_tick_val_next += SYNC_TICK_VAL_INTERVAL;
-        }
-
-        rem_val = val - sync_tick_val;
-
-        ret = sync_tick + ((rem_val * 1074) >> 23);
-    } else {
-        ret = (val << 1) / 15625;
-    }
-
-    return ret;
+    return cmac_timer_read32_msb();
 }
 
 void
@@ -309,19 +285,22 @@ cmac_timer_init(void)
     /* Make sure LL Timer does not use limited range */
     assert(CMAC->CM_CTRL2_REG & CMAC_CM_CTRL2_REG_LL_TIMER1_9_0_LIMITED_N_Msk);
 
+    CMAC->CM_LL_TIMER1_EQ_Y_CTRL_REG = 7;
+
     /*
-     * Set EQ_X and 36_10_EQ_Y comparators to trigger LL_TIMER2LLC interrupt.
+     * Set EQ_X and EQ_Y comparators to trigger LL_TIMER2LLC interrupt.
      * They are used for hal_timer and os_tick respectively.
      */
     CMAC->CM_LL_INT_SEL_REG |= CMAC_CM_LL_INT_SEL_REG_LL_TIMER1_EQ_X_SEL_Msk |
-                               CMAC_CM_LL_INT_SEL_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+                               CMAC_CM_LL_INT_SEL_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk |
+                               CMAC_CM_LL_INT_SEL_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
 
     switch_to_llt();
 
-    CMAC->CM_LL_INT_MSK_SET_REG = CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
-    CMAC->CM_LL_INT_STAT_REG = UINT32_MAX;
-
     NVIC_DisableIRQ(LL_TIMER2LLC_IRQn);
+    CMAC->CM_LL_INT_MSK_CLR_REG = UINT32_MAX;
+    CMAC->CM_LL_INT_STAT_REG = UINT32_MAX;
+    NVIC_ClearPendingIRQ(LL_TIMER2LLC_IRQn);
     NVIC_SetPriority(LL_TIMER2LLC_IRQn, 2);
     NVIC_EnableIRQ(LL_TIMER2LLC_IRQn);
 }
@@ -424,7 +403,7 @@ cmac_timer_int_os_tick_register(cmac_timer_int_func_t func)
 void
 cmac_timer_int_os_tick_clear(void)
 {
-    CMAC->CM_LL_INT_STAT_REG = CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk;
+    CMAC->CM_LL_INT_STAT_REG = CMAC_CM_LL_INT_STAT_REG_LL_TIMER1_9_0_EQ_Y_SEL_Msk;
 }
 
 uint32_t
@@ -452,8 +431,9 @@ cmac_timer_next_at(void)
         to_next = min(to_next, reg32 - val32);
     }
 
-    if (mask & CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_36_10_EQ_Y_SEL_Msk) {
-        reg32 = CMAC->CM_LL_TIMER1_36_10_EQ_Y_REG << 10;
+    if (mask & CMAC_CM_LL_INT_MSK_SET_REG_LL_TIMER1_EQ_Y_SEL_Msk) {
+        reg32 = (CMAC->CM_LL_TIMER1_EQ_Y_HI_REG << 10) |
+                CMAC->CM_LL_TIMER1_EQ_Y_LO_REG;
         to_next = min(to_next, reg32 - val32);
     }
 
diff --git a/hw/mcu/dialog/cmac/src/hal_os_tick.c b/hw/mcu/dialog/cmac/src/hal_os_tick.c
index 9eb3046..2b8f8bc 100644
--- a/hw/mcu/dialog/cmac/src/hal_os_tick.c
+++ b/hw/mcu/dialog/cmac/src/hal_os_tick.c
@@ -29,30 +29,11 @@
 #include "cmac_priv.h"
 
 static uint32_t g_os_tick_last;
-static uint32_t g_os_tick_next;
-static uint64_t g_os_tick_next_val;
 
 static void
 os_tick_setup_for_next(uint32_t delta)
 {
-    uint32_t next;
-    uint64_t llt_val;
-
-    next = g_os_tick_last + delta;
-    if (g_os_tick_next == next) {
-        /* Don't waste time calculating the same llt_val again */
-        llt_val = g_os_tick_next_val;
-    } else {
-        /* Round up to next high part ll_timer value */
-        llt_val = cmac_timer_convert_tck2llt(next);
-        llt_val += 1024;
-        llt_val &= ~((uint64_t)0x3ff);
-
-        g_os_tick_next = next;
-        g_os_tick_next_val = llt_val;
-    }
-
-    cmac_timer_write_eq_hal_os_tick(llt_val);
+    cmac_timer_write_eq_hal_os_tick(g_os_tick_last + delta);
 }
 
 static void
@@ -69,7 +50,7 @@ os_tick_handle_tick(void)
     os_time_advance(delta);
 
     g_os_tick_last = cur_tick;
-    os_tick_setup_for_next(1);
+    os_tick_setup_for_next(1024);
 }
 
 static void
@@ -101,7 +82,7 @@ os_tick_idle(os_time_t ticks)
 void
 os_tick_init(uint32_t os_ticks_per_sec, int prio)
 {
-    assert(os_ticks_per_sec == 128);
+    assert(os_ticks_per_sec == 31250);
 
     g_os_tick_last = 0;
 
diff --git a/hw/mcu/dialog/cmac/src/hal_timer.c b/hw/mcu/dialog/cmac/src/hal_timer.c
index 92983eb..c8b64e4 100644
--- a/hw/mcu/dialog/cmac/src/hal_timer.c
+++ b/hw/mcu/dialog/cmac/src/hal_timer.c
@@ -29,51 +29,25 @@
 #include "os/os_arch.h"
 #include "os/util.h"
 
-#define TICKS_GT(_t1, _t2)          ((int64_t)((_t1) - (_t2)) > 0)
-#define TICKS_GTE(_t1, _t2)         ((int64_t)((_t1) - (_t2)) >= 0)
-#define TICKS_LT(_t1, _t2)          ((int64_t)((_t1) - (_t2)) < 0)
-#define TICKS_LTE(_t1, _t2)         ((int64_t)((_t1) - (_t2)) <= 0)
+#define TICKS_GT(_t1, _t2)          ((int32_t)((_t1) - (_t2)) > 0)
+#define TICKS_GTE(_t1, _t2)         ((int32_t)((_t1) - (_t2)) >= 0)
+#define TICKS_LT(_t1, _t2)          ((int32_t)((_t1) - (_t2)) < 0)
+#define TICKS_LTE(_t1, _t2)         ((int32_t)((_t1) - (_t2)) <= 0)
 
 static TAILQ_HEAD(hal_timer_qhead, hal_timer) g_hal_timer_queue;
 
-/*
- * To avoid converting back and forth between uint64_t values returned by
- * cmac_timer and uint32_t representing hal_timer ticks, we compare cmac_timer
- * ticks everywhere. For this we need to store expiry value as uint64_t, so we
- * use bsp_timer (which is not used here since we only have one timer) pointer
- * to store high word of value.
- */
-
-static inline uint64_t
-hal_timer_expiry_get(struct hal_timer *timer)
-{
-    uint64_t ret;
-
-    ret = (uint64_t)POINTER_TO_UINT(timer->bsp_timer) << 32;
-    ret |= timer->expiry;
-
-    return ret;
-}
-
-static inline void
-hal_timer_expiry_set(struct hal_timer *timer, uint64_t val)
-{
-    timer->expiry = val;
-    timer->bsp_timer = UINT_TO_POINTER(val >> 32);
-}
-
 static void
 hal_timer_check_queue(void)
 {
     os_sr_t sr;
     struct hal_timer *e;
-    uint64_t ll_timer_val;
+    uint32_t timer_val;
 
     OS_ENTER_CRITICAL(sr);
 
     while ((e = TAILQ_FIRST(&g_hal_timer_queue)) != NULL) {
-        ll_timer_val = cmac_timer_read64();
-        if (TICKS_GT(hal_timer_expiry_get(e), ll_timer_val)) {
+        timer_val = cmac_timer_read32_msb();
+        if (TICKS_GT(e->expiry, timer_val)) {
             break;
         }
 
@@ -83,7 +57,7 @@ hal_timer_check_queue(void)
     }
 
     if (e != NULL) {
-        cmac_timer_write_eq_hal_timer(hal_timer_expiry_get(e));
+        cmac_timer_write_eq_hal_timer(e->expiry);
     } else {
         cmac_timer_disable_eq_hal_timer();
     }
@@ -115,7 +89,7 @@ int
 hal_timer_config(int timer_num, uint32_t freq_hz)
 {
     assert(timer_num == 0);
-    assert(freq_hz == 32768);
+    assert(freq_hz == 31250);
 
     return 0;
 }
@@ -138,14 +112,12 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
 {
     struct hal_timer *e;
     os_sr_t sr;
-    uint64_t expiry;
 
     assert(timer);
     assert(timer->link.tqe_prev == NULL);
     assert(timer->cb_func);
 
-    expiry = cmac_timer_convert_hal2llt(tick);
-    hal_timer_expiry_set(timer, expiry);
+    timer->expiry = tick;
 
     OS_ENTER_CRITICAL(sr);
 
@@ -153,7 +125,7 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
         TAILQ_INSERT_HEAD(&g_hal_timer_queue, timer, link);
     } else {
         TAILQ_FOREACH(e, &g_hal_timer_queue, link) {
-            if (TICKS_LT(expiry, hal_timer_expiry_get(e))) {
+            if (TICKS_LT(tick, e->expiry)) {
                 TAILQ_INSERT_BEFORE(e, timer, link);
                 break;
             }
@@ -164,7 +136,7 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
     }
 
     if (timer == TAILQ_FIRST(&g_hal_timer_queue)) {
-        cmac_timer_write_eq_hal_timer(expiry);
+        cmac_timer_write_eq_hal_timer(tick);
     }
 
     OS_EXIT_CRITICAL(sr);
@@ -194,7 +166,7 @@ hal_timer_stop(struct hal_timer *timer)
     if (reset_timer) {
         timer = TAILQ_FIRST(&g_hal_timer_queue);
         if (timer != NULL) {
-            cmac_timer_write_eq_hal_timer(hal_timer_expiry_get(timer));
+            cmac_timer_write_eq_hal_timer(timer->expiry);
         } else {
             cmac_timer_disable_eq_hal_timer();
         }
@@ -208,25 +180,7 @@ hal_timer_stop(struct hal_timer *timer)
 uint32_t
 hal_timer_read(int timer_num)
 {
-    uint64_t llt;
-    uint64_t val;
-
     assert(timer_num == 0);
 
-    llt = cmac_timer_read64();
-    val = cmac_timer_convert_llt2hal(llt);
-    llt = (val * 15625) >> 9;
-
-    __disable_irq();
-
-    /*
-     * Store current LLT value and converted HAL timer value, we'll use it as
-     * a base for subsequent HAL->LLT conversions.
-     */
-    g_cmac_timer_ctrl.hal_last_val = val;
-    g_cmac_timer_ctrl.hal_to_llt_corr = llt;
-
-    __enable_irq();
-
-    return val;
+    return cmac_timer_read32_msb();
 }
diff --git a/hw/mcu/dialog/cmac/syscfg.yml b/hw/mcu/dialog/cmac/syscfg.yml
index 7c55188..1385157 100644
--- a/hw/mcu/dialog/cmac/syscfg.yml
+++ b/hw/mcu/dialog/cmac/syscfg.yml
@@ -78,7 +78,7 @@ syscfg.defs:
         range: -1,0..31
 
 syscfg.vals:
-    OS_TICKS_PER_SEC: 128
+    OS_TICKS_PER_SEC: 31250
 
 syscfg.restrictions:
     - BLE_CONTROLLER