Pulse Counter (PCNT) Peripheral API. More...
![]() |
Data Structures | |
struct | PCNT_Init_TypeDef |
Defines | |
#define | PCNT0_CNT_SIZE (16) |
#define | PCNT_INIT_DEFAULT |
Enumerations | |
enum | PCNT_Mode_TypeDef { pcntModeDisable = _PCNT_CTRL_MODE_DISABLE, pcntModeOvsSingle = _PCNT_CTRL_MODE_OVSSINGLE, pcntModeExtSingle = _PCNT_CTRL_MODE_EXTCLKSINGLE, pcntModeExtQuad = _PCNT_CTRL_MODE_EXTCLKQUAD } |
enum | PCNT_CntEvent_TypeDef { pcntCntEventBoth = _PCNT_CTRL_CNTEV_BOTH, pcntCntEventUp = _PCNT_CTRL_CNTEV_UP, pcntCntEventDown = _PCNT_CTRL_CNTEV_DOWN, pcntCntEventNone = _PCNT_CTRL_CNTEV_NONE } |
enum | PCNT_PRSSel_TypeDef { pcntPRSCh0 = 0, pcntPRSCh1 = 1, pcntPRSCh2 = 2, pcntPRSCh3 = 3 } |
enum | PCNT_PRSInput_TypeDef { pcntPRSInputS0 = 0, pcntPRSInputS1 = 1 } |
Functions | |
__STATIC_INLINE uint32_t | PCNT_CounterGet (PCNT_TypeDef *pcnt) |
Get pulse counter value. | |
__STATIC_INLINE uint32_t | PCNT_AuxCounterGet (PCNT_TypeDef *pcnt) |
Get auxiliary counter value. | |
void | PCNT_CounterReset (PCNT_TypeDef *pcnt) |
Reset PCNT counters and TOP register. | |
void | PCNT_CounterTopSet (PCNT_TypeDef *pcnt, uint32_t count, uint32_t top) |
Set counter and top values. | |
__STATIC_INLINE void | PCNT_CounterSet (PCNT_TypeDef *pcnt, uint32_t count) |
Set counter value. | |
void | PCNT_Enable (PCNT_TypeDef *pcnt, PCNT_Mode_TypeDef mode) |
Set PCNT operational mode. | |
void | PCNT_FreezeEnable (PCNT_TypeDef *pcnt, bool enable) |
PCNT register synchronization freeze control. | |
void | PCNT_Init (PCNT_TypeDef *pcnt, const PCNT_Init_TypeDef *init) |
Init pulse counter. | |
void | PCNT_PRSInputEnable (PCNT_TypeDef *pcnt, PCNT_PRSInput_TypeDef prsInput, bool enable) |
Enable/disable the selected PRS input of PCNT. | |
__STATIC_INLINE void | PCNT_IntClear (PCNT_TypeDef *pcnt, uint32_t flags) |
Clear one or more pending PCNT interrupts. | |
__STATIC_INLINE void | PCNT_IntDisable (PCNT_TypeDef *pcnt, uint32_t flags) |
Disable one or more PCNT interrupts. | |
__STATIC_INLINE void | PCNT_IntEnable (PCNT_TypeDef *pcnt, uint32_t flags) |
Enable one or more PCNT interrupts. | |
__STATIC_INLINE uint32_t | PCNT_IntGet (PCNT_TypeDef *pcnt) |
Get pending PCNT interrupt flags. | |
__STATIC_INLINE uint32_t | PCNT_IntGetEnabled (PCNT_TypeDef *pcnt) |
Get enabled and pending PCNT interrupt flags. | |
__STATIC_INLINE void | PCNT_IntSet (PCNT_TypeDef *pcnt, uint32_t flags) |
Set one or more pending PCNT interrupts from SW. | |
void | PCNT_Reset (PCNT_TypeDef *pcnt) |
Reset PCNT to same state as after a HW reset. | |
__STATIC_INLINE uint32_t | PCNT_TopBufferGet (PCNT_TypeDef *pcnt) |
Get pulse counter top buffer value. | |
void | PCNT_TopBufferSet (PCNT_TypeDef *pcnt, uint32_t val) |
Set top buffer value. | |
__STATIC_INLINE uint32_t | PCNT_TopGet (PCNT_TypeDef *pcnt) |
Get pulse counter top value. | |
void | PCNT_TopSet (PCNT_TypeDef *pcnt, uint32_t val) |
Set top value. |
Pulse Counter (PCNT) Peripheral API.
#define PCNT0_CNT_SIZE (16) |
PCNT Counter register sizes.
Definition at line 63 of file em_pcnt.h.
Referenced by PCNT_CounterTopSet(), PCNT_Init(), and PCNT_TopSet().
#define PCNT_INIT_DEFAULT |
{ pcntModeDisable, /* Disabled by default. */ \ _PCNT_CNT_RESETVALUE, /* Default counter HW reset value. */ \ _PCNT_TOP_RESETVALUE, /* Default counter HW reset value. */ \ false, /* Use positive edge. */ \ false, /* Up-counting. */ \ false, /* Filter disabled. */ \ false, /* Hysteresis disabled. */ \ true, /* Counter direction is given by CNTDIR. */ \ pcntCntEventUp, /* Regular counter counts up on upcount events. */ \ pcntCntEventNone, /* Auxiliary counter doesn't respond to events. */ \ pcntPRSCh0, /* PRS channel 0 selected as S0IN. */ \ pcntPRSCh0 /* PRS channel 0 selected as S1IN. */ \ }
Default config for PCNT init structure.
Counter event selection. Note: unshifted values are being used for enumeration because multiple configuration structure members use this type definition.
enum PCNT_Mode_TypeDef |
Mode selection.
enum PCNT_PRSSel_TypeDef |
__STATIC_INLINE uint32_t PCNT_AuxCounterGet | ( | PCNT_TypeDef * | pcnt | ) |
__STATIC_INLINE uint32_t PCNT_CounterGet | ( | PCNT_TypeDef * | pcnt | ) |
void PCNT_CounterReset | ( | PCNT_TypeDef * | pcnt | ) |
Reset PCNT counters and TOP register.
[in] | pcnt | Pointer to PCNT peripheral register block. |
Definition at line 142 of file em_pcnt.c.
References BITBAND_Peripheral().
__STATIC_INLINE void PCNT_CounterSet | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | count | |||
) |
Set counter value.
The pulse counter is disabled while changing counter value, and reenabled (if originally enabled) when counter value has been set.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | count | Value to set in counter register. |
Definition at line 313 of file em_pcnt.h.
References PCNT_CounterTopSet().
void PCNT_CounterTopSet | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | count, | |||
uint32_t | top | |||
) |
Set counter and top values.
The pulse counter is disabled while changing these values, and reenabled (if originally enabled) when values have been set.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | count | Value to set in counter register. |
[in] | top | Value to set in top register. |
Definition at line 178 of file em_pcnt.c.
References PCNT0_CNT_SIZE.
Referenced by PCNT_CounterSet(), and PCNT_Init().
void PCNT_Enable | ( | PCNT_TypeDef * | pcnt, | |
PCNT_Mode_TypeDef | mode | |||
) |
Set PCNT operational mode.
Notice that this function does not do any configuration. Setting operational mode is normally only required after initialization is done, and if not done as part of initialization. Or if requiring to disable/reenable pulse counter.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | mode | Operational mode to use for PCNT. |
void PCNT_FreezeEnable | ( | PCNT_TypeDef * | pcnt, | |
bool | enable | |||
) |
PCNT register synchronization freeze control.
Some PCNT registers require synchronization into the low frequency (LF) domain. The freeze feature allows for several such registers to be modified before passing them to the LF domain simultaneously (which takes place when the freeze mode is disabled).
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | enable |
|
void PCNT_Init | ( | PCNT_TypeDef * | pcnt, | |
const PCNT_Init_TypeDef * | init | |||
) |
Init pulse counter.
This function will configure the pulse counter. The clock selection is configured as follows, depending on operational mode:
Notice that the LFACLK must be enabled in all modes, since some basic setup is done with this clock even if external pin clock usage mode is chosen. The pulse counter clock for the selected instance must also be enabled prior to init.
Notice that pins used by the PCNT module must be properly configured by the user explicitly through setting the ROUTE register, in order for the PCNT to work as intended.
Writing to CNT will not occur in external clock modes (EXTCLKQUAD and EXTCLKSINGLE) because the external clock rate is unknown. The user should handle it manually depending on the application
TOPB is written for all modes but in external clock mode it will take 3 external clock cycles to sync to TOP
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | init | Pointer to initialization structure used to initialize. |
Definition at line 437 of file em_pcnt.c.
References PCNT_Init_TypeDef::auxCntEvent, BITBAND_Peripheral(), CMU_PCNTClockExternalSet(), PCNT_Init_TypeDef::cntEvent, PCNT_Init_TypeDef::countDown, PCNT_Init_TypeDef::counter, PCNT_Init_TypeDef::filter, PCNT_Init_TypeDef::hyst, PCNT_Init_TypeDef::mode, PCNT_Init_TypeDef::negEdge, PCNT0_CNT_SIZE, PCNT_CounterTopSet(), pcntCntEventBoth, pcntCntEventDown, pcntCntEventNone, pcntCntEventUp, pcntModeExtQuad, pcntModeExtSingle, pcntModeOvsSingle, PCNT_Init_TypeDef::s0PRS, PCNT_Init_TypeDef::s1CntDir, PCNT_Init_TypeDef::s1PRS, and PCNT_Init_TypeDef::top.
__STATIC_INLINE void PCNT_IntClear | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | flags | |||
) |
__STATIC_INLINE void PCNT_IntDisable | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | flags | |||
) |
__STATIC_INLINE void PCNT_IntEnable | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | flags | |||
) |
Enable one or more PCNT interrupts.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | flags | PCNT interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
__STATIC_INLINE uint32_t PCNT_IntGet | ( | PCNT_TypeDef * | pcnt | ) |
Get pending PCNT interrupt flags.
[in] | pcnt | Pointer to PCNT peripheral register block. |
__STATIC_INLINE uint32_t PCNT_IntGetEnabled | ( | PCNT_TypeDef * | pcnt | ) |
Get enabled and pending PCNT interrupt flags.
Useful for handling more interrupt sources in the same interrupt handler.
[in] | pcnt | Pointer to PCNT peripheral register block. |
__STATIC_INLINE void PCNT_IntSet | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | flags | |||
) |
Set one or more pending PCNT interrupts from SW.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | flags | PCNT interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
void PCNT_PRSInputEnable | ( | PCNT_TypeDef * | pcnt, | |
PCNT_PRSInput_TypeDef | prsInput, | |||
bool | enable | |||
) |
Enable/disable the selected PRS input of PCNT.
Notice that this function does not do any configuration.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | prsInput | PRS input (S0 or S1) of the selected PCNT module. |
[in] | enable | Set to true to enable, false to disable the selected PRS input. |
Definition at line 312 of file em_pcnt.c.
References BITBAND_Peripheral(), and pcntPRSInputS1.
void PCNT_Reset | ( | PCNT_TypeDef * | pcnt | ) |
Reset PCNT to same state as after a HW reset.
Notice the LFACLK must be enabled, since some basic reset is done with this clock. The pulse counter clock for the selected instance must also be enabled prior to init.
[in] | pcnt | Pointer to PCNT peripheral register block. |
Definition at line 645 of file em_pcnt.c.
References BITBAND_Peripheral(), CMU_PCNTClockExternalSet(), and PCNT_TopBufferSet().
__STATIC_INLINE uint32_t PCNT_TopBufferGet | ( | PCNT_TypeDef * | pcnt | ) |
void PCNT_TopBufferSet | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | val | |||
) |
Set top buffer value.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | val | Value to set in top buffer register. |
Definition at line 698 of file em_pcnt.c.
Referenced by PCNT_Reset().
__STATIC_INLINE uint32_t PCNT_TopGet | ( | PCNT_TypeDef * | pcnt | ) |
void PCNT_TopSet | ( | PCNT_TypeDef * | pcnt, | |
uint32_t | val | |||
) |
Set top value.
[in] | pcnt | Pointer to PCNT peripheral register block. |
[in] | val | Value to set in top register. |
Definition at line 724 of file em_pcnt.c.
References PCNT0_CNT_SIZE.