You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/12/28 11:08:38 UTC

[incubator-nuttx] branch master updated: xtensa/esp32: Added driver api to reload counter instantly

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

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 65f39fc  xtensa/esp32: Added driver api to reload counter instantly
65f39fc is described below

commit 65f39fc0c796c95136479d8edfd60219724dee4e
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Thu Dec 24 09:44:59 2020 -0300

    xtensa/esp32: Added driver api to reload counter instantly
---
 arch/xtensa/src/esp32/esp32_tim.c | 35 ++++++++++++++++++++++++++++-------
 arch/xtensa/src/esp32/esp32_tim.h |  2 ++
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_tim.c b/arch/xtensa/src/esp32/esp32_tim.c
index f63fd7d..0ce5205 100644
--- a/arch/xtensa/src/esp32/esp32_tim.c
+++ b/arch/xtensa/src/esp32/esp32_tim.c
@@ -88,6 +88,7 @@ static int esp32_tim_getcounter(FAR struct esp32_tim_dev_s *dev,
                                 uint64_t *value);
 static int esp32_tim_setcounter(FAR struct esp32_tim_dev_s *dev,
                                 uint64_t value);
+static int esp32_tim_reload_now(FAR struct esp32_tim_dev_s *dev);
 static int esp32_tim_getalarmvalue(FAR struct esp32_tim_dev_s *dev,
                                    uint64_t *value);
 static int esp32_tim_setalarmvalue(FAR struct esp32_tim_dev_s *dev,
@@ -119,6 +120,7 @@ struct esp32_tim_ops_s esp32_tim_ops =
   .setpre        = esp32_tim_setpre,
   .getconfig     = esp32_tim_getconfig,
   .setcounter    = esp32_tim_setcounter,
+  .reloadnow     = esp32_tim_reload_now,
   .getalarmvalue = esp32_tim_getalarmvalue,
   .setalarmvalue = esp32_tim_setalarmvalue,
   .setalarm      = esp32_tim_setalarm,
@@ -286,16 +288,13 @@ static int esp32_tim_stop(FAR struct esp32_tim_dev_s *dev)
 
 static int esp32_tim_clear(FAR struct esp32_tim_dev_s *dev)
 {
-  uint32_t clear_value = 0;
+  uint64_t clear_value = 0;
 
   DEBUGASSERT(dev);
 
-  esp32_tim_putreg(dev, TIM_LOAD_LO_OFFSET, clear_value);
-  esp32_tim_putreg(dev, TIM_LOAD_HI_OFFSET, clear_value);
+  esp32_tim_setcounter(dev, clear_value);
 
-  /* Dummy value to trigger reload the counter with the previous value */
-
-  esp32_tim_putreg(dev, TIM_LOAD_OFFSET, BIT(0));
+  esp32_tim_reload_now(dev);
 
   return OK;
 }
@@ -503,7 +502,10 @@ static int esp32_tim_getcounter(FAR struct esp32_tim_dev_s *dev,
  *
  * Description:
  *   Set the value to be loaded to the counter
- *   It may be loaded at an alarm or instantly
+ *   If you want the counter to be loaded at an alarm, enable the alarm and
+ *   the auto-reload before.
+ *   I you want the counter to be loaded instantly, call esp32_tim_reload_now
+ *   after.
  *
  ****************************************************************************/
 
@@ -524,6 +526,25 @@ static int esp32_tim_setcounter(FAR struct esp32_tim_dev_s *dev,
 }
 
 /****************************************************************************
+ * Name: esp32_tim_reload_now
+ *
+ * Description:
+ *   Reloads the counter instantly. May be called after esp32_tim_setcounter.
+ *
+ ****************************************************************************/
+
+static int esp32_tim_reload_now(FAR struct esp32_tim_dev_s *dev)
+{
+  DEBUGASSERT(dev);
+
+  /* Dummy value to trigger reloading  */
+
+  esp32_tim_putreg(dev, TIM_LOAD_OFFSET, BIT(0));
+
+  return OK;
+}
+
+/****************************************************************************
  * Name: esp32_tim_getalarmvalue
  *
  * Description:
diff --git a/arch/xtensa/src/esp32/esp32_tim.h b/arch/xtensa/src/esp32/esp32_tim.h
index 2e3ee5a..ffcf3b8 100644
--- a/arch/xtensa/src/esp32/esp32_tim.h
+++ b/arch/xtensa/src/esp32/esp32_tim.h
@@ -46,6 +46,7 @@
 #define ESP32_TIM_GETCONFIG(d, v)                  ((d)->ops->getconfig(d, v))
 #define ESP32_TIM_GETCTR(d, v)                     ((d)->ops->getcounter(d, v))
 #define ESP32_TIM_SETCTR(d, v)                     ((d)->ops->setcounter(d, v))
+#define ESP32_TIM_RLD_NOW(d)                       ((d)->ops->reloadnow(d))
 #define ESP32_TIM_GETALRVL(d, v)                   ((d)->ops->getalarmvalue(d, v))
 #define ESP32_TIM_SETALRVL(d, v)                   ((d)->ops->setalarmvalue(d, v))
 #define ESP32_TIM_SETALRM(d, e)                    ((d)->ops->setalarm(d, e))
@@ -101,6 +102,7 @@ struct esp32_tim_ops_s
   CODE int (*getconfig)(FAR struct esp32_tim_dev_s *dev, uint32_t *value);
   CODE int (*getcounter)(FAR struct esp32_tim_dev_s *dev, uint64_t *value);
   CODE int (*setcounter)(FAR struct esp32_tim_dev_s *dev, uint64_t value);
+  CODE int (*reloadnow)(FAR struct esp32_tim_dev_s *dev);
   CODE int (*getalarmvalue)(FAR struct esp32_tim_dev_s *dev,
                             uint64_t *value);
   CODE int (*setalarmvalue)(FAR struct esp32_tim_dev_s *dev, uint64_t value);