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 2019/10/10 09:33:08 UTC

[mynewt-core] branch master updated: hw/mcu/dialog: Improve lpclk notifications

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


The following commit(s) were added to refs/heads/master by this push:
     new e809e7a  hw/mcu/dialog: Improve lpclk notifications
e809e7a is described below

commit e809e7ad0d37a5a3006655183bd825cbb6708773
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Oct 8 18:53:37 2019 +0200

    hw/mcu/dialog: Improve lpclk notifications
    
    lpclk notification is now triggered also for RCX and includes current
    lpclk frequency. If at some point RCX is recalibrated, we can just sent
    another notification with new frequency.
---
 hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h |  8 +++++-
 hw/mcu/dialog/da1469x/src/da1469x_cmac.c          |  4 +--
 hw/mcu/dialog/da1469x/src/da1469x_lpclk.c         | 35 +++++++++++++++++------
 hw/mcu/dialog/da1469x/src/hal_system.c            |  2 ++
 4 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h b/hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h
index e928237..5f0ace4 100644
--- a/hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h
+++ b/hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h
@@ -20,13 +20,19 @@
 #ifndef __MCU_DA1469X_LPCLK_H_
 #define __MCU_DA1469X_LPCLK_H_
 
+#include <stdint.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef void (da1469x_lpclk_cb)(void);
+typedef void (da1469x_lpclk_cb)(uint32_t freq);
 
 void da1469x_lpclk_register_cmac_cb(da1469x_lpclk_cb *cb);
+/* Stable lp clock enabled (e.g. switched to XTAL after settling) */
+void da1469x_lpclk_enabled(void);
+/* Frequency of lp clock changed (e.g. after RCX recalibration) */
+void da1469x_lpclk_updated(void);
 
 #ifdef __cplusplus
 }
diff --git a/hw/mcu/dialog/da1469x/src/da1469x_cmac.c b/hw/mcu/dialog/da1469x/src/da1469x_cmac.c
index 8e01572..961d5ae 100644
--- a/hw/mcu/dialog/da1469x/src/da1469x_cmac.c
+++ b/hw/mcu/dialog/da1469x/src/da1469x_cmac.c
@@ -162,12 +162,12 @@ done:
 }
 
 static void
-da1469x_cmac_lpclk_cb(void)
+da1469x_cmac_lpclk_cb(uint32_t freq)
 {
     struct cmac_config_dynamic *cmac_config_dyn;
 
     cmac_config_dyn = CMAC_SYM_CONFIG_DYN;
-    cmac_config_dyn->enable_sleep = true;
+    cmac_config_dyn->enable_sleep = freq == 32768;
 }
 
 void
diff --git a/hw/mcu/dialog/da1469x/src/da1469x_lpclk.c b/hw/mcu/dialog/da1469x/src/da1469x_lpclk.c
index baa1f89..a185d9b 100644
--- a/hw/mcu/dialog/da1469x/src/da1469x_lpclk.c
+++ b/hw/mcu/dialog/da1469x/src/da1469x_lpclk.c
@@ -37,23 +37,42 @@ static void
 da1469x_lpclk_settle_tmr_cb(void *arg)
 {
     da1469x_clock_lp_xtal32k_switch();
+    da1469x_lpclk_enabled();
+}
+#endif
 
-    g_mcu_lpclk_available = true;
-
-    if (g_da1469x_lpclk_cmac_cb) {
-        g_da1469x_lpclk_cmac_cb();
+static void
+da1469x_lpclk_notify(void)
+{
+    if (!g_da1469x_lpclk_cmac_cb || !g_mcu_lpclk_available) {
+        return;
     }
-}
+
+#if MYNEWT_VAL_CHOICE(MCU_LPCLK_SOURCE, XTAL32K)
+    g_da1469x_lpclk_cmac_cb(32768);
+#elif MYNEWT_VAL_CHOICE(MCU_LPCLK_SOURCE, RCX)
+    g_da1469x_lpclk_cmac_cb(da1469x_clock_lp_rcx_freq_get());
 #endif
+}
 
 void
 da1469x_lpclk_register_cmac_cb(da1469x_lpclk_cb *cb)
 {
     g_da1469x_lpclk_cmac_cb = cb;
+    da1469x_lpclk_notify();
+}
 
-    if (g_mcu_lpclk_available) {
-        cb();
-    }
+void
+da1469x_lpclk_enabled(void)
+{
+    g_mcu_lpclk_available = true;
+    da1469x_lpclk_notify();
+}
+
+void
+da1469x_lpclk_updated(void)
+{
+    da1469x_lpclk_notify();
 }
 
 void
diff --git a/hw/mcu/dialog/da1469x/src/hal_system.c b/hw/mcu/dialog/da1469x/src/hal_system.c
index 7f3fcd1..ae82e67 100644
--- a/hw/mcu/dialog/da1469x/src/hal_system.c
+++ b/hw/mcu/dialog/da1469x/src/hal_system.c
@@ -20,6 +20,7 @@
 #include <assert.h>
 #include "syscfg/syscfg.h"
 #include "mcu/da1469x_clock.h"
+#include "mcu/da1469x_lpclk.h"
 #include "mcu/da1469x_pd.h"
 #include "mcu/da1469x_pdc.h"
 #include "hal/hal_system.h"
@@ -101,6 +102,7 @@ hal_system_clock_start(void)
     da1469x_clock_lp_rcx_enable();
     da1469x_clock_lp_rcx_switch();
     da1469x_clock_lp_rcx_calibrate();
+    da1469x_lpclk_enabled();
 #else
     /*
      * We cannot switch lp_clk to XTAL32K here since it needs some time to