123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- #ifndef NRF_PPI_H__
- #define NRF_PPI_H__
- #include <nrfx.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum
- {
- NRF_PPI_CHANNEL0 = PPI_CHEN_CH0_Pos,
- NRF_PPI_CHANNEL1 = PPI_CHEN_CH1_Pos,
- NRF_PPI_CHANNEL2 = PPI_CHEN_CH2_Pos,
- NRF_PPI_CHANNEL3 = PPI_CHEN_CH3_Pos,
- NRF_PPI_CHANNEL4 = PPI_CHEN_CH4_Pos,
- NRF_PPI_CHANNEL5 = PPI_CHEN_CH5_Pos,
- NRF_PPI_CHANNEL6 = PPI_CHEN_CH6_Pos,
- NRF_PPI_CHANNEL7 = PPI_CHEN_CH7_Pos,
- NRF_PPI_CHANNEL8 = PPI_CHEN_CH8_Pos,
- NRF_PPI_CHANNEL9 = PPI_CHEN_CH9_Pos,
- NRF_PPI_CHANNEL10 = PPI_CHEN_CH10_Pos,
- NRF_PPI_CHANNEL11 = PPI_CHEN_CH11_Pos,
- NRF_PPI_CHANNEL12 = PPI_CHEN_CH12_Pos,
- NRF_PPI_CHANNEL13 = PPI_CHEN_CH13_Pos,
- NRF_PPI_CHANNEL14 = PPI_CHEN_CH14_Pos,
- NRF_PPI_CHANNEL15 = PPI_CHEN_CH15_Pos,
- #if (PPI_CH_NUM > 16) || defined(__NRFX_DOXYGEN__)
- NRF_PPI_CHANNEL16 = PPI_CHEN_CH16_Pos,
- NRF_PPI_CHANNEL17 = PPI_CHEN_CH17_Pos,
- NRF_PPI_CHANNEL18 = PPI_CHEN_CH18_Pos,
- NRF_PPI_CHANNEL19 = PPI_CHEN_CH19_Pos,
- #endif
- NRF_PPI_CHANNEL20 = PPI_CHEN_CH20_Pos,
- NRF_PPI_CHANNEL21 = PPI_CHEN_CH21_Pos,
- NRF_PPI_CHANNEL22 = PPI_CHEN_CH22_Pos,
- NRF_PPI_CHANNEL23 = PPI_CHEN_CH23_Pos,
- NRF_PPI_CHANNEL24 = PPI_CHEN_CH24_Pos,
- NRF_PPI_CHANNEL25 = PPI_CHEN_CH25_Pos,
- NRF_PPI_CHANNEL26 = PPI_CHEN_CH26_Pos,
- NRF_PPI_CHANNEL27 = PPI_CHEN_CH27_Pos,
- NRF_PPI_CHANNEL28 = PPI_CHEN_CH28_Pos,
- NRF_PPI_CHANNEL29 = PPI_CHEN_CH29_Pos,
- NRF_PPI_CHANNEL30 = PPI_CHEN_CH30_Pos,
- NRF_PPI_CHANNEL31 = PPI_CHEN_CH31_Pos
- } nrf_ppi_channel_t;
- typedef enum
- {
- NRF_PPI_CHANNEL_GROUP0 = 0,
- NRF_PPI_CHANNEL_GROUP1 = 1,
- NRF_PPI_CHANNEL_GROUP2 = 2,
- NRF_PPI_CHANNEL_GROUP3 = 3,
- #if (PPI_GROUP_NUM > 4) || defined(__NRFX_DOXYGEN__)
- NRF_PPI_CHANNEL_GROUP4 = 4,
- NRF_PPI_CHANNEL_GROUP5 = 5
- #endif
- } nrf_ppi_channel_group_t;
- typedef enum
- {
- NRF_PPI_CHANNEL_EXCLUDE = PPI_CHG_CH0_Excluded,
- NRF_PPI_CHANNEL_INCLUDE = PPI_CHG_CH0_Included
- } nrf_ppi_channel_include_t;
- typedef enum
- {
- NRF_PPI_CHANNEL_DISABLED = PPI_CHEN_CH0_Disabled,
- NRF_PPI_CHANNEL_ENABLED = PPI_CHEN_CH0_Enabled
- } nrf_ppi_channel_enable_t;
- typedef enum
- {
- NRF_PPI_TASK_CHG0_EN = offsetof(NRF_PPI_Type, TASKS_CHG[0].EN),
- NRF_PPI_TASK_CHG0_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[0].DIS),
- NRF_PPI_TASK_CHG1_EN = offsetof(NRF_PPI_Type, TASKS_CHG[1].EN),
- NRF_PPI_TASK_CHG1_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[1].DIS),
- NRF_PPI_TASK_CHG2_EN = offsetof(NRF_PPI_Type, TASKS_CHG[2].EN),
- NRF_PPI_TASK_CHG2_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[2].DIS),
- NRF_PPI_TASK_CHG3_EN = offsetof(NRF_PPI_Type, TASKS_CHG[3].EN),
- NRF_PPI_TASK_CHG3_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[3].DIS),
- #if (PPI_GROUP_NUM > 4) || defined(__NRFX_DOXYGEN__)
- NRF_PPI_TASK_CHG4_EN = offsetof(NRF_PPI_Type, TASKS_CHG[4].EN),
- NRF_PPI_TASK_CHG4_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[4].DIS),
- NRF_PPI_TASK_CHG5_EN = offsetof(NRF_PPI_Type, TASKS_CHG[5].EN),
- NRF_PPI_TASK_CHG5_DIS = offsetof(NRF_PPI_Type, TASKS_CHG[5].DIS)
- #endif
- } nrf_ppi_task_t;
- __STATIC_INLINE void nrf_ppi_channel_enable(nrf_ppi_channel_t channel);
- __STATIC_INLINE void nrf_ppi_channel_disable(nrf_ppi_channel_t channel);
- __STATIC_INLINE nrf_ppi_channel_enable_t nrf_ppi_channel_enable_get(nrf_ppi_channel_t channel);
- __STATIC_INLINE void nrf_ppi_channel_disable_all(void);
- __STATIC_INLINE void nrf_ppi_channels_enable(uint32_t mask);
- __STATIC_INLINE void nrf_ppi_channels_disable(uint32_t mask);
- __STATIC_INLINE void nrf_ppi_channel_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep,
- uint32_t tep);
- __STATIC_INLINE void nrf_ppi_event_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep);
- __STATIC_INLINE void nrf_ppi_task_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t tep);
- #if defined(PPI_FEATURE_FORKS_PRESENT) || defined(__NRFX_DOXYGEN__)
- __STATIC_INLINE void nrf_ppi_fork_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t fork_tep);
- __STATIC_INLINE void nrf_ppi_channel_and_fork_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep,
- uint32_t tep,
- uint32_t fork_tep);
- #endif
- __STATIC_INLINE void nrf_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
- nrf_ppi_channel_group_t channel_group);
- __STATIC_INLINE void nrf_ppi_channels_include_in_group(uint32_t channel_mask,
- nrf_ppi_channel_group_t channel_group);
- __STATIC_INLINE void nrf_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
- nrf_ppi_channel_group_t channel_group);
- __STATIC_INLINE void nrf_ppi_channels_remove_from_group(uint32_t channel_mask,
- nrf_ppi_channel_group_t channel_group);
- __STATIC_INLINE void nrf_ppi_channel_group_clear(nrf_ppi_channel_group_t group);
- __STATIC_INLINE void nrf_ppi_group_enable(nrf_ppi_channel_group_t group);
- __STATIC_INLINE void nrf_ppi_group_disable(nrf_ppi_channel_group_t group);
- __STATIC_INLINE void nrf_ppi_task_trigger(nrf_ppi_task_t ppi_task);
- __STATIC_INLINE uint32_t * nrf_ppi_task_address_get(nrf_ppi_task_t ppi_task);
- __STATIC_INLINE uint32_t * nrf_ppi_task_group_enable_address_get(nrf_ppi_channel_group_t group);
- __STATIC_INLINE uint32_t * nrf_ppi_task_group_disable_address_get(nrf_ppi_channel_group_t group);
- __STATIC_INLINE nrf_ppi_task_t nrf_ppi_group_enable_task_get(uint8_t index);
- __STATIC_INLINE nrf_ppi_task_t nrf_ppi_group_disable_task_get(uint8_t index);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE void nrf_ppi_channel_enable(nrf_ppi_channel_t channel)
- {
- NRF_PPI->CHENSET = PPI_CHENSET_CH0_Set << ((uint32_t) channel);
- }
- __STATIC_INLINE void nrf_ppi_channel_disable(nrf_ppi_channel_t channel)
- {
- NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Clear << ((uint32_t) channel);
- }
- __STATIC_INLINE nrf_ppi_channel_enable_t nrf_ppi_channel_enable_get(nrf_ppi_channel_t channel)
- {
- if (NRF_PPI->CHEN & (PPI_CHEN_CH0_Msk << ((uint32_t) channel)))
- {
- return NRF_PPI_CHANNEL_ENABLED;
- }
- else
- {
- return NRF_PPI_CHANNEL_DISABLED;
- }
- }
- __STATIC_INLINE void nrf_ppi_channel_disable_all(void)
- {
- NRF_PPI->CHENCLR = ((uint32_t)0xFFFFFFFFuL);
- }
- __STATIC_INLINE void nrf_ppi_channels_enable(uint32_t mask)
- {
- NRF_PPI->CHENSET = mask;
- }
- __STATIC_INLINE void nrf_ppi_channels_disable(uint32_t mask)
- {
- NRF_PPI->CHENCLR = mask;
- }
- __STATIC_INLINE void nrf_ppi_channel_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep,
- uint32_t tep)
- {
- NRF_PPI->CH[(uint32_t) channel].EEP = eep;
- NRF_PPI->CH[(uint32_t) channel].TEP = tep;
- }
- __STATIC_INLINE void nrf_ppi_event_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep)
- {
- NRF_PPI->CH[(uint32_t) channel].EEP = eep;
- }
- __STATIC_INLINE void nrf_ppi_task_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t tep)
- {
- NRF_PPI->CH[(uint32_t) channel].TEP = tep;
- }
- #if defined(PPI_FEATURE_FORKS_PRESENT)
- __STATIC_INLINE void nrf_ppi_fork_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t fork_tep)
- {
- NRF_PPI->FORK[(uint32_t) channel].TEP = fork_tep;
- }
- __STATIC_INLINE void nrf_ppi_channel_and_fork_endpoint_setup(nrf_ppi_channel_t channel,
- uint32_t eep,
- uint32_t tep,
- uint32_t fork_tep)
- {
- nrf_ppi_channel_endpoint_setup(channel, eep, tep);
- nrf_ppi_fork_endpoint_setup(channel, fork_tep);
- }
- #endif
- __STATIC_INLINE void nrf_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
- nrf_ppi_channel_group_t channel_group)
- {
- NRF_PPI->CHG[(uint32_t) channel_group] =
- NRF_PPI->CHG[(uint32_t) channel_group] | (PPI_CHG_CH0_Included << ((uint32_t) channel));
- }
- __STATIC_INLINE void nrf_ppi_channels_include_in_group(uint32_t channel_mask,
- nrf_ppi_channel_group_t channel_group)
- {
- NRF_PPI->CHG[(uint32_t) channel_group] =
- NRF_PPI->CHG[(uint32_t) channel_group] | (channel_mask);
- }
- __STATIC_INLINE void nrf_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
- nrf_ppi_channel_group_t channel_group)
- {
- NRF_PPI->CHG[(uint32_t) channel_group] =
- NRF_PPI->CHG[(uint32_t) channel_group] & ~(PPI_CHG_CH0_Included << ((uint32_t) channel));
- }
- __STATIC_INLINE void nrf_ppi_channels_remove_from_group(uint32_t channel_mask,
- nrf_ppi_channel_group_t channel_group)
- {
- NRF_PPI->CHG[(uint32_t) channel_group] =
- NRF_PPI->CHG[(uint32_t) channel_group] & ~(channel_mask);
- }
- __STATIC_INLINE void nrf_ppi_channel_group_clear(nrf_ppi_channel_group_t group)
- {
- NRF_PPI->CHG[(uint32_t) group] = 0;
- }
- __STATIC_INLINE void nrf_ppi_group_enable(nrf_ppi_channel_group_t group)
- {
- NRF_PPI->TASKS_CHG[(uint32_t) group].EN = 1UL;
- }
- __STATIC_INLINE void nrf_ppi_group_disable(nrf_ppi_channel_group_t group)
- {
- NRF_PPI->TASKS_CHG[(uint32_t) group].DIS = 1UL;
- }
- __STATIC_INLINE void nrf_ppi_task_trigger(nrf_ppi_task_t ppi_task)
- {
- *((volatile uint32_t *) ((uint8_t *) NRF_PPI_BASE + (uint32_t) ppi_task)) = 1UL;
- }
- __STATIC_INLINE uint32_t * nrf_ppi_task_address_get(nrf_ppi_task_t ppi_task)
- {
- return (uint32_t *) ((uint8_t *) NRF_PPI_BASE + (uint32_t) ppi_task);
- }
- __STATIC_INLINE uint32_t * nrf_ppi_task_group_enable_address_get(nrf_ppi_channel_group_t group)
- {
- return (uint32_t *) &NRF_PPI->TASKS_CHG[(uint32_t) group].EN;
- }
- __STATIC_INLINE uint32_t * nrf_ppi_task_group_disable_address_get(nrf_ppi_channel_group_t group)
- {
- return (uint32_t *) &NRF_PPI->TASKS_CHG[(uint32_t) group].DIS;
- }
- __STATIC_INLINE nrf_ppi_task_t nrf_ppi_group_enable_task_get(uint8_t index)
- {
- NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_PPI->TASKS_CHG));
- return (nrf_ppi_task_t)NRFX_OFFSETOF(NRF_PPI_Type, TASKS_CHG[index].EN);
- }
- __STATIC_INLINE nrf_ppi_task_t nrf_ppi_group_disable_task_get(uint8_t index)
- {
- NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_PPI->TASKS_CHG));
- return (nrf_ppi_task_t)NRFX_OFFSETOF(NRF_PPI_Type, TASKS_CHG[index].DIS);
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|