123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- #ifndef NRFX_TIMER_H__
- #define NRFX_TIMER_H__
- #include <nrfx.h>
- #include <hal/nrf_timer.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_TIMER_Type * p_reg;
- uint8_t instance_id;
- uint8_t cc_channel_count;
- } nrfx_timer_t;
- #define NRFX_TIMER_INSTANCE(id) \
- { \
- .p_reg = NRFX_CONCAT_2(NRF_TIMER, id), \
- .instance_id = NRFX_CONCAT_3(NRFX_TIMER, id, _INST_IDX), \
- .cc_channel_count = NRF_TIMER_CC_CHANNEL_COUNT(id), \
- }
- #ifndef __NRFX_DOXYGEN__
- enum {
- #if NRFX_CHECK(NRFX_TIMER0_ENABLED)
- NRFX_TIMER0_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_TIMER1_ENABLED)
- NRFX_TIMER1_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_TIMER2_ENABLED)
- NRFX_TIMER2_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_TIMER3_ENABLED)
- NRFX_TIMER3_INST_IDX,
- #endif
- #if NRFX_CHECK(NRFX_TIMER4_ENABLED)
- NRFX_TIMER4_INST_IDX,
- #endif
- NRFX_TIMER_ENABLED_COUNT
- };
- #endif
- typedef struct
- {
- nrf_timer_frequency_t frequency;
- nrf_timer_mode_t mode;
- nrf_timer_bit_width_t bit_width;
- uint8_t interrupt_priority;
- void * p_context;
- } nrfx_timer_config_t;
- #define NRFX_TIMER_DEFAULT_CONFIG \
- { \
- .frequency = (nrf_timer_frequency_t)NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY,\
- .mode = (nrf_timer_mode_t)NRFX_TIMER_DEFAULT_CONFIG_MODE, \
- .bit_width = (nrf_timer_bit_width_t)NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH,\
- .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, \
- .p_context = NULL \
- }
- typedef void (* nrfx_timer_event_handler_t)(nrf_timer_event_t event_type,
- void * p_context);
- nrfx_err_t nrfx_timer_init(nrfx_timer_t const * const p_instance,
- nrfx_timer_config_t const * p_config,
- nrfx_timer_event_handler_t timer_event_handler);
- void nrfx_timer_uninit(nrfx_timer_t const * const p_instance);
- void nrfx_timer_enable(nrfx_timer_t const * const p_instance);
- void nrfx_timer_disable(nrfx_timer_t const * const p_instance);
- bool nrfx_timer_is_enabled(nrfx_timer_t const * const p_instance);
- void nrfx_timer_pause(nrfx_timer_t const * const p_instance);
- void nrfx_timer_resume(nrfx_timer_t const * const p_instance);
- void nrfx_timer_clear(nrfx_timer_t const * const p_instance);
- void nrfx_timer_increment(nrfx_timer_t const * const p_instance);
- __STATIC_INLINE uint32_t nrfx_timer_task_address_get(nrfx_timer_t const * const p_instance,
- nrf_timer_task_t timer_task);
- __STATIC_INLINE uint32_t nrfx_timer_capture_task_address_get(nrfx_timer_t const * const p_instance,
- uint32_t channel);
- __STATIC_INLINE uint32_t nrfx_timer_event_address_get(nrfx_timer_t const * const p_instance,
- nrf_timer_event_t timer_event);
- __STATIC_INLINE uint32_t nrfx_timer_compare_event_address_get(nrfx_timer_t const * const p_instance,
- uint32_t channel);
- uint32_t nrfx_timer_capture(nrfx_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel);
- __STATIC_INLINE uint32_t nrfx_timer_capture_get(nrfx_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel);
- void nrfx_timer_compare(nrfx_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel,
- uint32_t cc_value,
- bool enable_int);
- void nrfx_timer_extended_compare(nrfx_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel,
- uint32_t cc_value,
- nrf_timer_short_mask_t timer_short_mask,
- bool enable_int);
- __STATIC_INLINE uint32_t nrfx_timer_us_to_ticks(nrfx_timer_t const * const p_instance,
- uint32_t time_us);
- __STATIC_INLINE uint32_t nrfx_timer_ms_to_ticks(nrfx_timer_t const * const p_instance,
- uint32_t time_ms);
- void nrfx_timer_compare_int_enable(nrfx_timer_t const * const p_instance,
- uint32_t channel);
- void nrfx_timer_compare_int_disable(nrfx_timer_t const * const p_instance,
- uint32_t channel);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE uint32_t nrfx_timer_task_address_get(nrfx_timer_t const * const p_instance,
- nrf_timer_task_t timer_task)
- {
- return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg, timer_task);
- }
- __STATIC_INLINE uint32_t nrfx_timer_capture_task_address_get(nrfx_timer_t const * const p_instance,
- uint32_t channel)
- {
- NRFX_ASSERT(channel < p_instance->cc_channel_count);
- return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg,
- nrf_timer_capture_task_get(channel));
- }
- __STATIC_INLINE uint32_t nrfx_timer_event_address_get(nrfx_timer_t const * const p_instance,
- nrf_timer_event_t timer_event)
- {
- return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg, timer_event);
- }
- __STATIC_INLINE uint32_t nrfx_timer_compare_event_address_get(nrfx_timer_t const * const p_instance,
- uint32_t channel)
- {
- NRFX_ASSERT(channel < p_instance->cc_channel_count);
- return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg,
- nrf_timer_compare_event_get(channel));
- }
- __STATIC_INLINE uint32_t nrfx_timer_capture_get(nrfx_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel)
- {
- return nrf_timer_cc_read(p_instance->p_reg, cc_channel);
- }
- __STATIC_INLINE uint32_t nrfx_timer_us_to_ticks(nrfx_timer_t const * const p_instance,
- uint32_t timer_us)
- {
- return nrf_timer_us_to_ticks(timer_us, nrf_timer_frequency_get(p_instance->p_reg));
- }
- __STATIC_INLINE uint32_t nrfx_timer_ms_to_ticks(nrfx_timer_t const * const p_instance,
- uint32_t timer_ms)
- {
- return nrf_timer_ms_to_ticks(timer_ms, nrf_timer_frequency_get(p_instance->p_reg));
- }
- #endif
- void nrfx_timer_0_irq_handler(void);
- void nrfx_timer_1_irq_handler(void);
- void nrfx_timer_2_irq_handler(void);
- void nrfx_timer_3_irq_handler(void);
- void nrfx_timer_4_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|