123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- #ifndef NRF_WDT_H__
- #define NRF_WDT_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NRF_WDT_CHANNEL_NUMBER 0x8UL
- #define NRF_WDT_RR_VALUE 0x6E524635UL
- typedef enum
- {
- NRF_WDT_TASK_START = offsetof(NRF_WDT_Type, TASKS_START),
- } nrf_wdt_task_t;
- typedef enum
- {
- NRF_WDT_EVENT_TIMEOUT = offsetof(NRF_WDT_Type, EVENTS_TIMEOUT),
- } nrf_wdt_event_t;
- typedef enum
- {
- NRF_WDT_BEHAVIOUR_RUN_SLEEP = WDT_CONFIG_SLEEP_Msk,
- NRF_WDT_BEHAVIOUR_RUN_HALT = WDT_CONFIG_HALT_Msk,
- NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT = WDT_CONFIG_SLEEP_Msk | WDT_CONFIG_HALT_Msk,
- NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT = 0,
- } nrf_wdt_behaviour_t;
- typedef enum
- {
- NRF_WDT_RR0 = 0,
- NRF_WDT_RR1,
- NRF_WDT_RR2,
- NRF_WDT_RR3,
- NRF_WDT_RR4,
- NRF_WDT_RR5,
- NRF_WDT_RR6,
- NRF_WDT_RR7
- } nrf_wdt_rr_register_t;
- typedef enum
- {
- NRF_WDT_INT_TIMEOUT_MASK = WDT_INTENSET_TIMEOUT_Msk,
- } nrf_wdt_int_mask_t;
- __STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour);
- __STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task);
- __STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event);
- __STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event);
- __STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask);
- __STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask);
- __STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask);
- #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_wdt_subscribe_set(nrf_wdt_task_t task,
- uint8_t channel);
- __STATIC_INLINE void nrf_wdt_subscribe_clear(nrf_wdt_task_t task);
- __STATIC_INLINE void nrf_wdt_publish_set(nrf_wdt_event_t event,
- uint8_t channel);
- __STATIC_INLINE void nrf_wdt_publish_clear(nrf_wdt_event_t event);
- #endif
- __STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task);
- __STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event);
- __STATIC_INLINE bool nrf_wdt_started(void);
- __STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register);
- __STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value);
- __STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void);
- __STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register);
- __STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register);
- __STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register);
- __STATIC_INLINE void nrf_wdt_reload_request_set(nrf_wdt_rr_register_t rr_register);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour)
- {
- NRF_WDT->CONFIG = behaviour;
- }
- __STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)task)) = 0x01UL;
- }
- __STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event)
- {
- *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)) = 0x0UL;
- #if __CORTEX_M == 0x04
- volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event));
- (void)dummy;
- #endif
- }
- __STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event)
- {
- return (bool)*((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event));
- }
- __STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask)
- {
- NRF_WDT->INTENSET = int_mask;
- }
- __STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask)
- {
- return (bool)(NRF_WDT->INTENSET & int_mask);
- }
- __STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask)
- {
- NRF_WDT->INTENCLR = int_mask;
- }
- #if defined(DPPI_PRESENT)
- __STATIC_INLINE void nrf_wdt_subscribe_set(nrf_wdt_task_t task,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_WDT + (uint32_t) task + 0x80uL)) =
- ((uint32_t)channel | WDT_SUBSCRIBE_START_EN_Msk);
- }
- __STATIC_INLINE void nrf_wdt_subscribe_clear(nrf_wdt_task_t task)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_WDT + (uint32_t) task + 0x80uL)) = 0;
- }
- __STATIC_INLINE void nrf_wdt_publish_set(nrf_wdt_event_t event,
- uint8_t channel)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_WDT + (uint32_t) event + 0x80uL)) =
- ((uint32_t)channel | WDT_PUBLISH_TIMEOUT_EN_Msk);
- }
- __STATIC_INLINE void nrf_wdt_publish_clear(nrf_wdt_event_t event)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_WDT + (uint32_t) event + 0x80uL)) = 0;
- }
- #endif
- __STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task)
- {
- return ((uint32_t)NRF_WDT + (uint32_t)task);
- }
- __STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event)
- {
- return ((uint32_t)NRF_WDT + (uint32_t)event);
- }
- __STATIC_INLINE bool nrf_wdt_started(void)
- {
- return (bool)(NRF_WDT->RUNSTATUS);
- }
- __STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register)
- {
- return (bool)(((NRF_WDT->REQSTATUS) >> rr_register) & 0x1UL);
- }
- __STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value)
- {
- NRF_WDT->CRV = reload_value;
- }
- __STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void)
- {
- return (uint32_t)NRF_WDT->CRV;
- }
- __STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register)
- {
- NRF_WDT->RREN |= 0x1UL << rr_register;
- }
- __STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register)
- {
- NRF_WDT->RREN &= ~(0x1UL << rr_register);
- }
- __STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register)
- {
- return (bool)(NRF_WDT->RREN & (0x1UL << rr_register));
- }
- __STATIC_INLINE void nrf_wdt_reload_request_set(nrf_wdt_rr_register_t rr_register)
- {
- NRF_WDT->RR[rr_register] = NRF_WDT_RR_VALUE;
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|