123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- #ifndef NRF_RTC_H
- #define NRF_RTC_H
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF_RTC_CC_CHANNEL_COUNT(id) NRFX_CONCAT_3(RTC, id, _CC_NUM)
- #define RTC_INPUT_FREQ 32768
- #define RTC_FREQ_TO_PRESCALER(FREQ) (uint16_t)(((RTC_INPUT_FREQ) / (FREQ)) - 1)
- #define RTC_WRAP(val) ((val) & RTC_COUNTER_COUNTER_Msk)
- #define RTC_CHANNEL_INT_MASK(ch) ((uint32_t)(NRF_RTC_INT_COMPARE0_MASK) << (ch))
- #define RTC_CHANNEL_EVENT_ADDR(ch) (nrf_rtc_event_t)((NRF_RTC_EVENT_COMPARE_0) + (ch) * sizeof(uint32_t))
- typedef enum
- {
- NRF_RTC_TASK_START = offsetof(NRF_RTC_Type,TASKS_START),
- NRF_RTC_TASK_STOP = offsetof(NRF_RTC_Type,TASKS_STOP),
- NRF_RTC_TASK_CLEAR = offsetof(NRF_RTC_Type,TASKS_CLEAR),
- NRF_RTC_TASK_TRIGGER_OVERFLOW = offsetof(NRF_RTC_Type,TASKS_TRIGOVRFLW),
- } nrf_rtc_task_t;
- typedef enum
- {
- NRF_RTC_EVENT_TICK = offsetof(NRF_RTC_Type,EVENTS_TICK),
- NRF_RTC_EVENT_OVERFLOW = offsetof(NRF_RTC_Type,EVENTS_OVRFLW),
- NRF_RTC_EVENT_COMPARE_0 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[0]),
- NRF_RTC_EVENT_COMPARE_1 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[1]),
- NRF_RTC_EVENT_COMPARE_2 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[2]),
- NRF_RTC_EVENT_COMPARE_3 = offsetof(NRF_RTC_Type,EVENTS_COMPARE[3])
- } nrf_rtc_event_t;
- typedef enum
- {
- NRF_RTC_INT_TICK_MASK = RTC_INTENSET_TICK_Msk,
- NRF_RTC_INT_OVERFLOW_MASK = RTC_INTENSET_OVRFLW_Msk,
- NRF_RTC_INT_COMPARE0_MASK = RTC_INTENSET_COMPARE0_Msk,
- NRF_RTC_INT_COMPARE1_MASK = RTC_INTENSET_COMPARE1_Msk,
- NRF_RTC_INT_COMPARE2_MASK = RTC_INTENSET_COMPARE2_Msk,
- NRF_RTC_INT_COMPARE3_MASK = RTC_INTENSET_COMPARE3_Msk
- } nrf_rtc_int_t;
- __STATIC_INLINE void nrf_rtc_cc_set(NRF_RTC_Type * p_reg, uint32_t ch, uint32_t cc_val);
- __STATIC_INLINE uint32_t nrf_rtc_cc_get(NRF_RTC_Type * p_reg, uint32_t ch);
- __STATIC_INLINE void nrf_rtc_int_enable(NRF_RTC_Type * p_reg, uint32_t mask);
- __STATIC_INLINE void nrf_rtc_int_disable(NRF_RTC_Type * p_reg, uint32_t mask);
- __STATIC_INLINE uint32_t nrf_rtc_int_is_enabled(NRF_RTC_Type * p_reg, uint32_t mask);
- __STATIC_INLINE uint32_t nrf_rtc_int_get(NRF_RTC_Type * p_reg);
- #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_rtc_subscribe_set(NRF_RTC_Type * p_reg,
- nrf_rtc_task_t task,
- uint8_t channel);
- __STATIC_INLINE void nrf_rtc_subscribe_clear(NRF_RTC_Type * p_reg,
- nrf_rtc_task_t task);
- __STATIC_INLINE void nrf_rtc_publish_set(NRF_RTC_Type * p_reg,
- nrf_rtc_event_t event,
- uint8_t channel);
- __STATIC_INLINE void nrf_rtc_publish_clear(NRF_RTC_Type * p_reg,
- nrf_rtc_event_t event);
- #endif
- __STATIC_INLINE uint32_t nrf_rtc_event_pending(NRF_RTC_Type * p_reg, nrf_rtc_event_t event);
- __STATIC_INLINE void nrf_rtc_event_clear(NRF_RTC_Type * p_reg, nrf_rtc_event_t event);
- __STATIC_INLINE uint32_t nrf_rtc_counter_get(NRF_RTC_Type * p_reg);
- __STATIC_INLINE void nrf_rtc_prescaler_set(NRF_RTC_Type * p_reg, uint32_t val);
- __STATIC_INLINE uint32_t nrf_rtc_event_address_get(NRF_RTC_Type * p_reg, nrf_rtc_event_t event);
- __STATIC_INLINE uint32_t nrf_rtc_task_address_get(NRF_RTC_Type * p_reg, nrf_rtc_task_t task);
- __STATIC_INLINE void nrf_rtc_task_trigger(NRF_RTC_Type * p_reg, nrf_rtc_task_t task);
- __STATIC_INLINE void nrf_rtc_event_enable(NRF_RTC_Type * p_reg, uint32_t mask);
- __STATIC_INLINE void nrf_rtc_event_disable(NRF_RTC_Type * p_reg, uint32_t event);
- __STATIC_INLINE nrf_rtc_event_t nrf_rtc_compare_event_get(uint8_t index);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_rtc_cc_set(NRF_RTC_Type * p_reg, uint32_t ch, uint32_t cc_val)
- {
- p_reg->CC[ch] = cc_val;
- }
- __STATIC_INLINE uint32_t nrf_rtc_cc_get(NRF_RTC_Type * p_reg, uint32_t ch)
- {
- return p_reg->CC[ch];
- }
- __STATIC_INLINE void nrf_rtc_int_enable(NRF_RTC_Type * p_reg, uint32_t mask)
- {
- p_reg->INTENSET = mask;
- }
- __STATIC_INLINE void nrf_rtc_int_disable(NRF_RTC_Type * p_reg, uint32_t mask)
- {
- p_reg->INTENCLR = mask;
- }
- __STATIC_INLINE uint32_t nrf_rtc_int_is_enabled(NRF_RTC_Type * p_reg, uint32_t mask)
- {
- return (p_reg->INTENSET & mask);
- }
- __STATIC_INLINE uint32_t nrf_rtc_int_get(NRF_RTC_Type * p_reg)
- {
- return p_reg->INTENSET;
- }
- #if defined(DPPI_PRESENT)
- __STATIC_INLINE void nrf_rtc_subscribe_set(NRF_RTC_Type * p_reg,
- nrf_rtc_task_t task,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
- ((uint32_t)channel | RTC_SUBSCRIBE_START_EN_Msk);
- }
- __STATIC_INLINE void nrf_rtc_subscribe_clear(NRF_RTC_Type * p_reg,
- nrf_rtc_task_t task)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
- }
- __STATIC_INLINE void nrf_rtc_publish_set(NRF_RTC_Type * p_reg,
- nrf_rtc_event_t event,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
- ((uint32_t)channel | RTC_PUBLISH_TICK_EN_Msk);
- }
- __STATIC_INLINE void nrf_rtc_publish_clear(NRF_RTC_Type * p_reg,
- nrf_rtc_event_t event)
- {
- *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
- }
- #endif
- __STATIC_INLINE uint32_t nrf_rtc_event_pending(NRF_RTC_Type * p_reg, nrf_rtc_event_t event)
- {
- return *(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
- }
- __STATIC_INLINE void nrf_rtc_event_clear(NRF_RTC_Type * p_reg, nrf_rtc_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE uint32_t nrf_rtc_counter_get(NRF_RTC_Type * p_reg)
- {
- return p_reg->COUNTER;
- }
- __STATIC_INLINE void nrf_rtc_prescaler_set(NRF_RTC_Type * p_reg, uint32_t val)
- {
- NRFX_ASSERT(val <= (RTC_PRESCALER_PRESCALER_Msk >> RTC_PRESCALER_PRESCALER_Pos));
- p_reg->PRESCALER = val;
- }
- __STATIC_INLINE uint32_t rtc_prescaler_get(NRF_RTC_Type * p_reg)
- {
- return p_reg->PRESCALER;
- }
- __STATIC_INLINE uint32_t nrf_rtc_event_address_get(NRF_RTC_Type * p_reg, nrf_rtc_event_t event)
- {
- return (uint32_t)p_reg + event;
- }
- __STATIC_INLINE uint32_t nrf_rtc_task_address_get(NRF_RTC_Type * p_reg, nrf_rtc_task_t task)
- {
- return (uint32_t)p_reg + task;
- }
- __STATIC_INLINE void nrf_rtc_task_trigger(NRF_RTC_Type * p_reg, nrf_rtc_task_t task)
- {
- *(__IO uint32_t *)((uint32_t)p_reg + task) = 1;
- }
- __STATIC_INLINE void nrf_rtc_event_enable(NRF_RTC_Type * p_reg, uint32_t mask)
- {
- p_reg->EVTENSET = mask;
- }
- __STATIC_INLINE void nrf_rtc_event_disable(NRF_RTC_Type * p_reg, uint32_t mask)
- {
- p_reg->EVTENCLR = mask;
- }
- __STATIC_INLINE nrf_rtc_event_t nrf_rtc_compare_event_get(uint8_t index)
- {
- return (nrf_rtc_event_t)NRFX_OFFSETOF(NRF_RTC_Type, EVENTS_COMPARE[index]);
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|