123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- #ifndef NRF_CLOCK_H__
- #define NRF_CLOCK_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(CLOCK_LFCLKSRC_BYPASS_Msk) && defined(CLOCK_LFCLKSRC_EXTERNAL_Msk)
- #define NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES
- #endif
- #if defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
- #define NRF_CLOCK_HAS_CALIBRATION 1
- #else
- #define NRF_CLOCK_HAS_CALIBRATION 0
- #endif
- typedef enum
- {
- #if defined(CLOCK_LFCLKSRC_SRC_RC) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_RC,
- #else
- NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_LFRC,
- #endif
- #if defined(CLOCK_LFCLKSRC_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_Xtal,
- #else
- NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_LFXO,
- #endif
- #if defined(CLOCK_LFCLKSRC_SRC_Synth) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth,
- #endif
- #if defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
-
- NRF_CLOCK_LFCLK_Xtal_Low_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
- (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
-
- NRF_CLOCK_LFCLK_Xtal_Full_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
- (CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos) |
- (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
- #endif
- } nrf_clock_lfclk_t;
- typedef enum
- {
- #if defined(CLOCK_HFCLKSTAT_SRC_RC) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_RC,
- #endif
- #if defined(CLOCK_HFCLKSTAT_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal
- #else
- NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_HFXO
- #endif
- } nrf_clock_hfclk_t;
- typedef enum
- {
- NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered,
- NRF_CLOCK_START_TASK_TRIGGERED = CLOCK_LFCLKRUN_STATUS_Triggered
- } nrf_clock_start_task_status_t;
- typedef enum
- {
- NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk,
- NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk,
- #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_INT_DONE_MASK = CLOCK_INTENSET_DONE_Msk,
- NRF_CLOCK_INT_CTTO_MASK = CLOCK_INTENSET_CTTO_Msk,
- #endif
- #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_INT_CTSTARTED_MASK = CLOCK_INTENSET_CTSTARTED_Msk,
- NRF_CLOCK_INT_CTSTOPPED_MASK = CLOCK_INTENSET_CTSTOPPED_Msk
- #endif
- } nrf_clock_int_mask_t;
- typedef enum
- {
- NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART),
- NRF_CLOCK_TASK_HFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP),
- NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART),
- NRF_CLOCK_TASK_LFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP),
- #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_TASK_CAL = offsetof(NRF_CLOCK_Type, TASKS_CAL),
- NRF_CLOCK_TASK_CTSTART = offsetof(NRF_CLOCK_Type, TASKS_CTSTART),
- NRF_CLOCK_TASK_CTSTOP = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP)
- #endif
- } nrf_clock_task_t;
- typedef enum
- {
- NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED),
- NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED),
- #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_EVENT_DONE = offsetof(NRF_CLOCK_Type, EVENTS_DONE),
- NRF_CLOCK_EVENT_CTTO = offsetof(NRF_CLOCK_Type, EVENTS_CTTO),
- #endif
- #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
- NRF_CLOCK_EVENT_CTSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTARTED),
- NRF_CLOCK_EVENT_CTSTOPPED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTOPPED)
- #endif
- } nrf_clock_event_t;
- __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask);
- __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask);
- __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask);
- __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task);
- __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task);
- __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event);
- __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event);
- __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event);
- __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source);
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void);
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void);
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void);
- __STATIC_INLINE bool nrf_clock_lf_is_running(void);
- __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void);
- __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void);
- __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src);
- __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void);
- #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval);
- #endif
- #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
- uint8_t channel);
- __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task);
- __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
- uint8_t channel);
- __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event);
- #endif
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask)
- {
- NRF_CLOCK->INTENSET = int_mask;
- }
- __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask)
- {
- NRF_CLOCK->INTENCLR = int_mask;
- }
- __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)
- {
- return (bool)(NRF_CLOCK->INTENCLR & int_mask);
- }
- __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task)
- {
- return ((uint32_t )NRF_CLOCK + task);
- }
- __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + task)) = 0x1UL;
- }
- __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event)
- {
- return ((uint32_t)NRF_CLOCK + event);
- }
- __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event)) = 0x0UL;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event)
- {
- return (bool)*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
- }
- __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
- {
- NRF_CLOCK->LFCLKSRC = (uint32_t)(source);
- }
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void)
- {
- return (nrf_clock_lfclk_t)(NRF_CLOCK->LFCLKSRC);
- }
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void)
- {
- return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSTAT &
- CLOCK_LFCLKSTAT_SRC_Msk) >> CLOCK_LFCLKSTAT_SRC_Pos);
- }
- __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void)
- {
- return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRCCOPY &
- CLOCK_LFCLKSRCCOPY_SRC_Msk) >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
- }
- __STATIC_INLINE bool nrf_clock_lf_is_running(void)
- {
- return ((NRF_CLOCK->LFCLKSTAT &
- CLOCK_LFCLKSTAT_STATE_Msk) >> CLOCK_LFCLKSTAT_STATE_Pos);
- }
- __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void)
- {
- return (nrf_clock_start_task_status_t)((NRF_CLOCK->LFCLKRUN &
- CLOCK_LFCLKRUN_STATUS_Msk) >> CLOCK_LFCLKRUN_STATUS_Pos);
- }
- __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void)
- {
- return (nrf_clock_hfclk_t)((NRF_CLOCK->HFCLKSTAT &
- CLOCK_HFCLKSTAT_SRC_Msk) >> CLOCK_HFCLKSTAT_SRC_Pos);
- }
- __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)
- {
- return (NRF_CLOCK->HFCLKSTAT & (CLOCK_HFCLKSTAT_STATE_Msk | CLOCK_HFCLKSTAT_SRC_Msk)) ==
- (CLOCK_HFCLKSTAT_STATE_Msk | (clk_src << CLOCK_HFCLKSTAT_SRC_Pos));
- }
- __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void)
- {
- return (nrf_clock_start_task_status_t)((NRF_CLOCK->HFCLKRUN &
- CLOCK_HFCLKRUN_STATUS_Msk) >> CLOCK_HFCLKRUN_STATUS_Pos);
- }
- #if (NRF_CLOCK_HAS_CALIBRATION)
- __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval)
- {
- NRF_CLOCK->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
- }
- #endif
- #if defined(DPPI_PRESENT)
- __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) =
- ((uint32_t)channel | CLOCK_SUBSCRIBE_HFCLKSTART_EN_Msk);
- }
- __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) = 0;
- }
- __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) =
- ((uint32_t)channel | CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk);
- }
- __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) = 0;
- }
- #endif
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|