|  | 
| 8 | 8 | #include "hal/nrf_rtc.h" | 
| 9 | 9 | #include "bs_tracing.h" | 
| 10 | 10 | #include "NRF_RTC.h" | 
|  | 11 | +#if defined(DPPI_PRESENT) | 
|  | 12 | +#include "NRF_DPPI.h" | 
|  | 13 | +#endif | 
| 11 | 14 | 
 | 
| 12 | 15 | static int rtc_number_from_ptr(NRF_RTC_Type const * p_reg){ | 
| 13 | 16 |   int i = ( (int)p_reg - (int)&NRF_RTC_regs[0] ) / sizeof(NRF_RTC_Type); | 
| @@ -35,6 +38,133 @@ void nrf_rtc_int_disable(NRF_RTC_Type * p_reg, uint32_t mask) | 
| 35 | 38 |   nrf_rtc_regw_sideeffect_INTENCLR(i); | 
| 36 | 39 | } | 
| 37 | 40 | 
 | 
|  | 41 | +#if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) | 
|  | 42 | + | 
|  | 43 | +void nrf_rtc_subscriber_add(int rtc_number, nrf_rtc_task_t task, uint8_t channel) | 
|  | 44 | +{ | 
|  | 45 | +  switch(task) | 
|  | 46 | +  { | 
|  | 47 | +    case NRF_RTC_TASK_START: | 
|  | 48 | +      switch(rtc_number) | 
|  | 49 | +      { | 
|  | 50 | +        case 0: | 
|  | 51 | +          nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_START); | 
|  | 52 | +          break; | 
|  | 53 | +        case 1: | 
|  | 54 | +          nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_START); | 
|  | 55 | +          break; | 
|  | 56 | +        case 2: | 
|  | 57 | +          nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_START); | 
|  | 58 | +          break; | 
|  | 59 | +      } | 
|  | 60 | +      break; | 
|  | 61 | +    case NRF_RTC_TASK_STOP: | 
|  | 62 | +      switch(rtc_number) | 
|  | 63 | +      { | 
|  | 64 | +        case 0: | 
|  | 65 | +          nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_STOP); | 
|  | 66 | +          break; | 
|  | 67 | +        case 1: | 
|  | 68 | +          nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_STOP); | 
|  | 69 | +          break; | 
|  | 70 | +        case 2: | 
|  | 71 | +          nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_STOP); | 
|  | 72 | +          break; | 
|  | 73 | +      } | 
|  | 74 | +      break; | 
|  | 75 | +    case NRF_RTC_TASK_CLEAR: | 
|  | 76 | +      switch(rtc_number) | 
|  | 77 | +      { | 
|  | 78 | +        case 0: | 
|  | 79 | +          nrf_dppi_subscriber_add(channel, nrf_rtc0_TASKS_START); | 
|  | 80 | +          break; | 
|  | 81 | +        case 1: | 
|  | 82 | +          nrf_dppi_subscriber_add(channel, nrf_rtc1_TASKS_START); | 
|  | 83 | +          break; | 
|  | 84 | +        case 2: | 
|  | 85 | +          nrf_dppi_subscriber_add(channel, nrf_rtc2_TASKS_START); | 
|  | 86 | +          break; | 
|  | 87 | +      } | 
|  | 88 | +      break; | 
|  | 89 | +    default: | 
|  | 90 | +      break; | 
|  | 91 | +    } | 
|  | 92 | +} | 
|  | 93 | + | 
|  | 94 | +void nrf_rtc_subscriber_remove(int rtc_number, nrf_rtc_task_t task) | 
|  | 95 | +{ | 
|  | 96 | +  switch(rtc_number) | 
|  | 97 | +  { | 
|  | 98 | +    case 0: | 
|  | 99 | +      switch(task) | 
|  | 100 | +      { | 
|  | 101 | +        case NRF_RTC_TASK_START: | 
|  | 102 | +          nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_START); | 
|  | 103 | +          break; | 
|  | 104 | +        case NRF_RTC_TASK_STOP: | 
|  | 105 | +          nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_STOP); | 
|  | 106 | +          break; | 
|  | 107 | +        case NRF_RTC_TASK_CLEAR: | 
|  | 108 | +          nrf_dppi_subscriber_remove(nrf_rtc0_TASKS_CLEAR); | 
|  | 109 | +          break; | 
|  | 110 | +        default: | 
|  | 111 | +          break; | 
|  | 112 | +      } | 
|  | 113 | +      break; | 
|  | 114 | +    case 1: | 
|  | 115 | +    switch(task) | 
|  | 116 | +      { | 
|  | 117 | +        case NRF_RTC_TASK_START: | 
|  | 118 | +          nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_START); | 
|  | 119 | +          break; | 
|  | 120 | +        case NRF_RTC_TASK_STOP: | 
|  | 121 | +          nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_STOP); | 
|  | 122 | +          break; | 
|  | 123 | +        case NRF_RTC_TASK_CLEAR: | 
|  | 124 | +          nrf_dppi_subscriber_remove(nrf_rtc1_TASKS_CLEAR); | 
|  | 125 | +          break; | 
|  | 126 | +        default: | 
|  | 127 | +          break; | 
|  | 128 | +      } | 
|  | 129 | +      break; | 
|  | 130 | +    case 2: | 
|  | 131 | +      switch(task) | 
|  | 132 | +      { | 
|  | 133 | +        case NRF_RTC_TASK_START: | 
|  | 134 | +          nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_START); | 
|  | 135 | +          break; | 
|  | 136 | +        case NRF_RTC_TASK_STOP: | 
|  | 137 | +          nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_STOP); | 
|  | 138 | +          break; | 
|  | 139 | +        case NRF_RTC_TASK_CLEAR: | 
|  | 140 | +          nrf_dppi_subscriber_remove(nrf_rtc2_TASKS_CLEAR); | 
|  | 141 | +          break; | 
|  | 142 | +        default: | 
|  | 143 | +          break; | 
|  | 144 | +      } | 
|  | 145 | +      break; | 
|  | 146 | +    default: | 
|  | 147 | +      break; | 
|  | 148 | +  } | 
|  | 149 | +} | 
|  | 150 | + | 
|  | 151 | +void nrf_rtc_subscribe_set(NRF_RTC_Type * p_reg, | 
|  | 152 | +                           nrf_rtc_task_t task, | 
|  | 153 | +                           uint8_t        channel) | 
|  | 154 | +{ | 
|  | 155 | +  *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = | 
|  | 156 | +            ((uint32_t)channel | RTC_SUBSCRIBE_START_EN_Msk); | 
|  | 157 | +  nrf_rtc_subscriber_add(rtc_number_from_ptr(p_reg), task, channel); | 
|  | 158 | +} | 
|  | 159 | + | 
|  | 160 | +void nrf_rtc_subscribe_clear(NRF_RTC_Type * p_reg, | 
|  | 161 | +                             nrf_rtc_task_t task) | 
|  | 162 | +{ | 
|  | 163 | +  *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0; | 
|  | 164 | +  nrf_rtc_subscriber_remove(rtc_number_from_ptr(p_reg), task); | 
|  | 165 | +} | 
|  | 166 | +#endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__) | 
|  | 167 | + | 
| 38 | 168 | uint32_t nrf_rtc_counter_get(NRF_RTC_Type const * p_reg) | 
| 39 | 169 | { | 
| 40 | 170 |   int i = rtc_number_from_ptr(p_reg); | 
|  | 
0 commit comments