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

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

commit fa6bb5411de8695193eb44ddb11227ed47cd12e7
Author: Matias N <[email protected]>
AuthorDate: Fri Jul 24 22:59:05 2020 -0300

    nrf52 RTC: add event handling support
---
 arch/arm/src/nrf52/nrf52_rtc.c | 125 ++++++++++++++++++++++++++++++++++++++++-
 arch/arm/src/nrf52/nrf52_rtc.h |  21 ++++++-
 2 files changed, 143 insertions(+), 3 deletions(-)

diff --git a/arch/arm/src/nrf52/nrf52_rtc.c b/arch/arm/src/nrf52/nrf52_rtc.c
index 51f9b99..d52da8f 100644
--- a/arch/arm/src/nrf52/nrf52_rtc.c
+++ b/arch/arm/src/nrf52/nrf52_rtc.c
@@ -68,6 +68,8 @@ static void nrf52_rtc_putreg(FAR struct nrf52_rtc_dev_s *dev,
 
 static uint32_t nrf52_rtc_irq2reg(FAR struct nrf52_rtc_dev_s *dev,
                                   uint8_t s);
+static uint32_t nrf52_rtc_evt2reg(FAR struct nrf52_rtc_dev_s *dev,
+                                  uint8_t evt);
 
 /* RTC operations ***********************************************************/
 
@@ -86,6 +88,8 @@ static int nrf52_rtc_enableint(FAR struct nrf52_rtc_dev_s 
*dev, uint8_t s);
 static int nrf52_rtc_disableint(FAR struct nrf52_rtc_dev_s *dev, uint8_t s);
 static int nrf52_rtc_checkint(FAR struct nrf52_rtc_dev_s *dev, uint8_t s);
 static int nrf52_rtc_ackint(FAR struct nrf52_rtc_dev_s *dev, uint8_t s);
+static int nrf52_rtc_enableevt(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt);
+static int nrf52_rtc_disableevt(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt);
 
 /****************************************************************************
  * Private Data
@@ -106,7 +110,9 @@ struct nrf52_rtc_ops_s nrf52_rtc_ops =
   .enableint  = nrf52_rtc_enableint,
   .disableint = nrf52_rtc_disableint,
   .checkint   = nrf52_rtc_checkint,
-  .ackint     = nrf52_rtc_ackint
+  .ackint     = nrf52_rtc_ackint,
+  .enableevt  = nrf52_rtc_enableevt,
+  .disableevt = nrf52_rtc_disableevt,
 };
 
 #ifdef CONFIG_NRF52_RTC0
@@ -189,7 +195,7 @@ static void nrf52_rtc_putreg(FAR struct nrf52_rtc_dev_s 
*dev,
  * Name: nrf52_rtc_irq2reg
  *
  * Description:
- *   Get the vaule of the interrupt register corresponding to the given
+ *   Get the value of the interrupt register corresponding to the given
  *   interrupt source
  *
  ****************************************************************************/
@@ -249,6 +255,69 @@ errout:
 }
 
 /****************************************************************************
+ * Name: nrf52_rtc_evt2reg
+ *
+ * Description:
+ *   Get the offset of the event register corresponding to the given event
+ *
+ ****************************************************************************/
+
+static uint32_t nrf52_rtc_evt2reg(FAR struct nrf52_rtc_dev_s *dev,
+                                  uint8_t evt)
+{
+  uint32_t regval;
+
+  switch (evt)
+    {
+      case NRF52_RTC_EVT_TICK:
+        {
+          regval = RTC_EVTEN_TICK;
+          break;
+        }
+
+      case NRF52_RTC_EVT_OVRFLW:
+        {
+          regval = RTC_EVTEN_OVRFLW;
+          break;
+        }
+
+      case NRF52_RTC_EVT_COMPARE0:
+        {
+          regval = RTC_EVTEN_COMPARE(0);
+          break;
+        }
+
+      case NRF52_RTC_EVT_COMPARE1:
+        {
+          regval = RTC_EVTEN_COMPARE(1);
+          break;
+        }
+
+      case NRF52_RTC_EVT_COMPARE2:
+        {
+          regval = RTC_EVTEN_COMPARE(2);
+          break;
+        }
+
+      case NRF52_RTC_EVT_COMPARE3:
+        {
+          regval = RTC_EVTEN_COMPARE(3);
+          break;
+        }
+
+      default:
+        {
+          rtcerr("ERROR: unsupported EVENT %d\n", evt);
+          regval = 0;
+          goto errout;
+        }
+    }
+
+errout:
+  return regval;
+}
+
+/****************************************************************************
  * Name: nrf52_rtc_start
  ****************************************************************************/
 
@@ -589,6 +658,58 @@ errout:
 }
 
 /****************************************************************************
+ * Name: nrf52_rtc_enableevt
+ ****************************************************************************/
+
+static int nrf52_rtc_enableevt(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt)
+{
+  uint32_t regval = 0;
+  int      ret    = OK;
+
+  DEBUGASSERT(dev);
+
+  /* Get register value for given event */
+
+  regval = nrf52_rtc_evt2reg(dev, evt);
+  if (regval == 0)
+    {
+      ret = -EINVAL;
+      goto errout;
+    }
+
+  nrf52_rtc_putreg(dev, NRF52_RTC_EVTENSET_OFFSET, regval);
+
+errout:
+  return ret;
+}
+
+/****************************************************************************
+ * Name: nrf52_rtc_disableevt
+ ****************************************************************************/
+
+static int nrf52_rtc_disableevt(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt)
+{
+  uint32_t regval = 0;
+  int      ret    = OK;
+
+  DEBUGASSERT(dev);
+
+  /* Get register value for given event */
+
+  regval = nrf52_rtc_evt2reg(dev, evt);
+  if (regval == 0)
+    {
+      ret = -EINVAL;
+      goto errout;
+    }
+
+  nrf52_rtc_putreg(dev, NRF52_RTC_EVTENCLR_OFFSET, regval);
+
+errout:
+  return ret;
+}
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
diff --git a/arch/arm/src/nrf52/nrf52_rtc.h b/arch/arm/src/nrf52/nrf52_rtc.h
index 03dbb26..2b89c5a 100644
--- a/arch/arm/src/nrf52/nrf52_rtc.h
+++ b/arch/arm/src/nrf52/nrf52_rtc.h
@@ -42,11 +42,13 @@
 #define NRF52_RTC_SETCC(d, i, cc)         ((d)->ops->setcc(d, i, cc))
 #define NRF52_RTC_GETCC(d, i, cc)         ((d)->ops->setcc(d, i, cc))
 #define NRF52_RTC_SETPRE(d, pre)          ((d)->ops->setpre(d, pre))
-#define NRF52_RTC_SETISR(d, hnd, arg, s)  ((d)->ops->setisr(d, hnd, arg, s))
+#define NRF52_RTC_SETISR(d, hnd, arg)     ((d)->ops->setisr(d, hnd, arg))
 #define NRF52_RTC_ENABLEINT(d, s)         ((d)->ops->enableint(d, s))
 #define NRF52_RTC_DISABLEINT(d, s)        ((d)->ops->disableint(d, s))
 #define NRF52_RTC_CHECKINT(d, s)          ((d)->ops->checkint(d, s))
 #define NRF52_RTC_ACKINT(d, s)            ((d)->ops->ackint(d, s))
+#define NRF52_RTC_ENABLEEVT(d, s)         ((d)->ops->enableevt(d, s))
+#define NRF52_RTC_DISABLEEVT(d, s)        ((d)->ops->disableevt(d, s))
 
 /****************************************************************************
  * Public Types
@@ -74,6 +76,18 @@ enum nrf52_rtc_irq_e
   NRF52_RTC_INT_COMPARE3 = 5,
 };
 
+/* RTC Events */
+
+enum nrf52_rtc_evt_e
+{
+  NRF52_RTC_EVT_TICK     = 0,
+  NRF52_RTC_EVT_OVRFLW   = 1,
+  NRF52_RTC_EVT_COMPARE0 = 2,
+  NRF52_RTC_EVT_COMPARE1 = 3,
+  NRF52_RTC_EVT_COMPARE2 = 4,
+  NRF52_RTC_EVT_COMPARE3 = 5,
+};
+
 /* NRF52 RTC device */
 
 struct nrf52_rtc_dev_s
@@ -107,6 +121,11 @@ struct nrf52_rtc_ops_s
   CODE int (*disableint)(FAR struct nrf52_rtc_dev_s *dev, uint8_t source);
   CODE int (*checkint)(FAR struct nrf52_rtc_dev_s *dev, uint8_t source);
   CODE int (*ackint)(FAR struct nrf52_rtc_dev_s *dev, uint8_t source);
+
+  /* RTC events */
+
+  CODE int (*enableevt)(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt);
+  CODE int (*disableevt)(FAR struct nrf52_rtc_dev_s *dev, uint8_t evt);
 };
 
 /****************************************************************************

Reply via email to