Timer/Counter (TIMER) Peripheral API. More...
![]() |
Data Structures | |
struct | TIMER_Init_TypeDef |
struct | TIMER_InitCC_TypeDef |
struct | TIMER_InitDTI_TypeDef |
Defines | |
#define | TIMER_INIT_DEFAULT |
#define | TIMER_INITCC_DEFAULT |
#define | TIMER_INITDTI_DEFAULT |
Enumerations | |
enum | TIMER_CCMode_TypeDef { timerCCModeOff = _TIMER_CC_CTRL_MODE_OFF, timerCCModeCapture = _TIMER_CC_CTRL_MODE_INPUTCAPTURE, timerCCModeCompare = _TIMER_CC_CTRL_MODE_OUTPUTCOMPARE, timerCCModePWM = _TIMER_CC_CTRL_MODE_PWM } |
enum | TIMER_ClkSel_TypeDef { timerClkSelHFPerClk = _TIMER_CTRL_CLKSEL_PRESCHFPERCLK, timerClkSelCC1 = _TIMER_CTRL_CLKSEL_CC1, timerClkSelCascade = _TIMER_CTRL_CLKSEL_TIMEROUF } |
enum | TIMER_Edge_TypeDef { timerEdgeRising = _TIMER_CC_CTRL_ICEDGE_RISING, timerEdgeFalling = _TIMER_CC_CTRL_ICEDGE_FALLING, timerEdgeBoth = _TIMER_CC_CTRL_ICEDGE_BOTH, timerEdgeNone = _TIMER_CC_CTRL_ICEDGE_NONE } |
enum | TIMER_Event_TypeDef { timerEventEveryEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYEDGE, timerEventEvery2ndEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYSECONDEDGE, timerEventRising = _TIMER_CC_CTRL_ICEVCTRL_RISING, timerEventFalling = _TIMER_CC_CTRL_ICEVCTRL_FALLING } |
enum | TIMER_InputAction_TypeDef { timerInputActionNone = _TIMER_CTRL_FALLA_NONE, timerInputActionStart = _TIMER_CTRL_FALLA_START, timerInputActionStop = _TIMER_CTRL_FALLA_STOP, timerInputActionReloadStart = _TIMER_CTRL_FALLA_RELOADSTART } |
enum | TIMER_Mode_TypeDef { timerModeUp = _TIMER_CTRL_MODE_UP, timerModeDown = _TIMER_CTRL_MODE_DOWN, timerModeUpDown = _TIMER_CTRL_MODE_UPDOWN, timerModeQDec = _TIMER_CTRL_MODE_QDEC } |
enum | TIMER_OutputAction_TypeDef { timerOutputActionNone = _TIMER_CC_CTRL_CUFOA_NONE, timerOutputActionToggle = _TIMER_CC_CTRL_CUFOA_TOGGLE, timerOutputActionClear = _TIMER_CC_CTRL_CUFOA_CLEAR, timerOutputActionSet = _TIMER_CC_CTRL_CUFOA_SET } |
enum | TIMER_Prescale_TypeDef { timerPrescale1 = _TIMER_CTRL_PRESC_DIV1, timerPrescale2 = _TIMER_CTRL_PRESC_DIV2, timerPrescale4 = _TIMER_CTRL_PRESC_DIV4, timerPrescale8 = _TIMER_CTRL_PRESC_DIV8, timerPrescale16 = _TIMER_CTRL_PRESC_DIV16, timerPrescale32 = _TIMER_CTRL_PRESC_DIV32, timerPrescale64 = _TIMER_CTRL_PRESC_DIV64, timerPrescale128 = _TIMER_CTRL_PRESC_DIV128, timerPrescale256 = _TIMER_CTRL_PRESC_DIV256, timerPrescale512 = _TIMER_CTRL_PRESC_DIV512, timerPrescale1024 = _TIMER_CTRL_PRESC_DIV1024 } |
enum | TIMER_PRSSEL_TypeDef { timerPRSSELCh0 = _TIMER_CC_CTRL_PRSSEL_PRSCH0, timerPRSSELCh1 = _TIMER_CC_CTRL_PRSSEL_PRSCH1, timerPRSSELCh2 = _TIMER_CC_CTRL_PRSSEL_PRSCH2, timerPRSSELCh3 = _TIMER_CC_CTRL_PRSSEL_PRSCH3 } |
Functions | |
__STATIC_INLINE uint32_t | TIMER_CaptureGet (TIMER_TypeDef *timer, unsigned int ch) |
Get capture value for compare/capture channel when operating in capture mode. | |
__STATIC_INLINE void | TIMER_CompareBufSet (TIMER_TypeDef *timer, unsigned int ch, uint32_t val) |
Set compare value buffer for compare/capture channel when operating in compare or PWM mode. | |
__STATIC_INLINE void | TIMER_CompareSet (TIMER_TypeDef *timer, unsigned int ch, uint32_t val) |
Set compare value for compare/capture channel when operating in compare or PWM mode. | |
__STATIC_INLINE uint32_t | TIMER_CounterGet (TIMER_TypeDef *timer) |
Get TIMER counter value. | |
__STATIC_INLINE void | TIMER_CounterSet (TIMER_TypeDef *timer, uint32_t val) |
Set TIMER counter value. | |
__STATIC_INLINE void | TIMER_Enable (TIMER_TypeDef *timer, bool enable) |
Start/stop TIMER. | |
void | TIMER_Init (TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init) |
Initialize TIMER. | |
void | TIMER_InitCC (TIMER_TypeDef *timer, unsigned int ch, const TIMER_InitCC_TypeDef *init) |
Initialize TIMER compare/capture channel. | |
void | TIMER_InitDTI (TIMER_TypeDef *timer, const TIMER_InitDTI_TypeDef *init) |
Initialize the TIMER DTI unit. | |
__STATIC_INLINE void | TIMER_EnableDTI (TIMER_TypeDef *timer, bool enable) |
Enable or disable DTI unit. | |
__STATIC_INLINE uint32_t | TIMER_GetDTIFault (TIMER_TypeDef *timer) |
Get DTI fault source flags status. | |
__STATIC_INLINE void | TIMER_ClearDTIFault (TIMER_TypeDef *timer, uint32_t flags) |
Clear DTI fault source flags. | |
__STATIC_INLINE void | TIMER_IntClear (TIMER_TypeDef *timer, uint32_t flags) |
Clear one or more pending TIMER interrupts. | |
__STATIC_INLINE void | TIMER_IntDisable (TIMER_TypeDef *timer, uint32_t flags) |
Disable one or more TIMER interrupts. | |
__STATIC_INLINE void | TIMER_IntEnable (TIMER_TypeDef *timer, uint32_t flags) |
Enable one or more TIMER interrupts. | |
__STATIC_INLINE uint32_t | TIMER_IntGet (TIMER_TypeDef *timer) |
Get pending TIMER interrupt flags. | |
__STATIC_INLINE uint32_t | TIMER_IntGetEnabled (TIMER_TypeDef *timer) |
Get enabled and pending TIMER interrupt flags. Useful for handling more interrupt sources in the same interrupt handler. | |
__STATIC_INLINE void | TIMER_IntSet (TIMER_TypeDef *timer, uint32_t flags) |
Set one or more pending TIMER interrupts from SW. | |
__STATIC_INLINE void | TIMER_Lock (TIMER_TypeDef *timer) |
Lock some of the TIMER registers in order to protect them from being modified. | |
void | TIMER_Reset (TIMER_TypeDef *timer) |
Reset TIMER to same state as after a HW reset. | |
__STATIC_INLINE void | TIMER_TopBufSet (TIMER_TypeDef *timer, uint32_t val) |
Set top value buffer for timer. | |
__STATIC_INLINE uint32_t | TIMER_TopGet (TIMER_TypeDef *timer) |
Get top value setting for timer. | |
__STATIC_INLINE void | TIMER_TopSet (TIMER_TypeDef *timer, uint32_t val) |
Set top value for timer. | |
__STATIC_INLINE void | TIMER_Unlock (TIMER_TypeDef *timer) |
Unlock the TIMER so that writing to locked registers again is possible. |
Timer/Counter (TIMER) Peripheral API.
The timer module consists of three main parts:
#define TIMER_INIT_DEFAULT |
{ true, /* Enable timer when init complete. */ \ false, /* Stop counter during debug halt. */ \ timerPrescale1, /* No prescaling. */ \ timerClkSelHFPerClk, /* Select HFPER clock. */ \ timerInputActionNone, /* No action on falling input edge. */ \ timerInputActionNone, /* No action on rising input edge. */ \ timerModeUp, /* Up-counting. */ \ false, /* Do not clear DMA requests when DMA channel is active. */ \ false, /* Select X2 quadrature decode mode (if used). */ \ false, /* Disable one shot. */ \ false /* Not started/stopped/reloaded by other timers. */ \ }
Default config for TIMER init structure.
Definition at line 328 of file em_timer.h.
#define TIMER_INITCC_DEFAULT |
{ timerEventEveryEdge, /* Event on every capture. */ \ timerEdgeRising, /* Input capture edge on rising edge. */ \ timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \ timerOutputActionNone, /* No action on underflow. */ \ timerOutputActionNone, /* No action on overflow. */ \ timerOutputActionNone, /* No action on match. */ \ timerCCModeOff, /* Disable compare/capture channel. */ \ false, /* Disable filter. */ \ false, /* Select TIMERnCCx input. */ \ false, /* Clear output when counter disabled. */ \ false /* Do not invert output. */ \ }
Default config for TIMER compare/capture init structure.
Definition at line 390 of file em_timer.h.
#define TIMER_INITDTI_DEFAULT |
{ true, /* Enable the DTI. */ \ false, /* CC[0|1|2] outputs are active high. */ \ false, /* CDTI[0|1|2] outputs are not inverted. */ \ false, /* No auto restart when debugger exits. */ \ false, /* No PRS source selected. */ \ timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \ timerPrescale1, /* No prescaling. */ \ 0, /* No rise time. */ \ 0, /* No fall time. */ \ TIMER_DTOGEN_DTOGCC0EN|TIMER_DTOGEN_DTOGCDTI0EN, /* Enable CC0 and CDTI0 */\ true, /* Enable core lockup as fault source */ \ true, /* Enable debugger as fault source */ \ false, /* Disable PRS fault source 0 */ \ timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \ false, /* Disable PRS fault source 1 */ \ timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \ timerDtiFaultActionInactive, /* No fault action. */ \ }
Default config for TIMER DTI init structure.
Definition at line 467 of file em_timer.h.
enum TIMER_CCMode_TypeDef |
Timer compare/capture mode.
timerCCModeOff |
Channel turned off. |
timerCCModeCapture |
Input capture. |
timerCCModeCompare |
Output compare. |
timerCCModePWM |
Pulse-Width modulation. |
Definition at line 92 of file em_timer.h.
enum TIMER_ClkSel_TypeDef |
Clock select.
timerClkSelHFPerClk |
Prescaled HFPER clock. |
timerClkSelCC1 |
Prescaled HFPER clock. |
timerClkSelCascade |
Cascaded, clocked by underflow (down-counting) or overflow (up-counting) by lower numbered timer. |
Definition at line 102 of file em_timer.h.
enum TIMER_Edge_TypeDef |
Input capture edge select.
timerEdgeRising |
Rising edges detected. |
timerEdgeFalling |
Falling edges detected. |
timerEdgeBoth |
Both edges detected. |
timerEdgeNone |
No edge detection, leave signal as is. |
Definition at line 119 of file em_timer.h.
enum TIMER_Event_TypeDef |
Input capture event control.
Definition at line 136 of file em_timer.h.
Input edge action.
timerInputActionNone |
No action taken. |
timerInputActionStart |
Start counter without reload. |
timerInputActionStop |
Stop counter without reload. |
timerInputActionReloadStart |
Reload and start counter. |
Definition at line 156 of file em_timer.h.
enum TIMER_Mode_TypeDef |
Timer mode.
timerModeUp |
Up-counting. |
timerModeDown |
Down-counting. |
timerModeUpDown |
Up/down-counting. |
timerModeQDec |
Quadrature decoder. |
Definition at line 173 of file em_timer.h.
Compare/capture output action.
timerOutputActionNone |
No action. |
timerOutputActionToggle |
Toggle on event. |
timerOutputActionClear |
Clear on event. |
timerOutputActionSet |
Set on event. |
Definition at line 183 of file em_timer.h.
Prescaler.
Definition at line 200 of file em_timer.h.
enum TIMER_PRSSEL_TypeDef |
Peripheral Reflex System signal.
timerPRSSELCh0 |
PRS channel 0. |
timerPRSSELCh1 |
PRS channel 1. |
timerPRSSELCh2 |
PRS channel 2. |
timerPRSSELCh3 |
PRS channel 3. |
Definition at line 217 of file em_timer.h.
__STATIC_INLINE uint32_t TIMER_CaptureGet | ( | TIMER_TypeDef * | timer, | |
unsigned int | ch | |||
) |
Get capture value for compare/capture channel when operating in capture mode.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
Definition at line 507 of file em_timer.h.
__STATIC_INLINE void TIMER_ClearDTIFault | ( | TIMER_TypeDef * | timer, | |
uint32_t | flags | |||
) |
Clear DTI fault source flags.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | flags | DTI fault source(s) to clear. Use one or more valid DTI fault source flags (TIMER_DTFAULT_nnn) OR'ed together. |
Definition at line 684 of file em_timer.h.
Referenced by TIMER_InitDTI().
__STATIC_INLINE void TIMER_CompareBufSet | ( | TIMER_TypeDef * | timer, | |
unsigned int | ch, | |||
uint32_t | val | |||
) |
Set compare value buffer for compare/capture channel when operating in compare or PWM mode.
The compare value buffer holds the value which will be written to TIMERn_CCx_CCV on an update event if the buffer has been updated since the last event.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
[in] | val | Value to set in compare value buffer register. |
Definition at line 532 of file em_timer.h.
__STATIC_INLINE void TIMER_CompareSet | ( | TIMER_TypeDef * | timer, | |
unsigned int | ch, | |||
uint32_t | val | |||
) |
Set compare value for compare/capture channel when operating in compare or PWM mode.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | ch | Compare/capture channel to access. |
[in] | val | Value to set in compare value register. |
Definition at line 554 of file em_timer.h.
__STATIC_INLINE uint32_t TIMER_CounterGet | ( | TIMER_TypeDef * | timer | ) |
Get TIMER counter value.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 572 of file em_timer.h.
__STATIC_INLINE void TIMER_CounterSet | ( | TIMER_TypeDef * | timer, | |
uint32_t | val | |||
) |
Set TIMER counter value.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | val | Value to set counter to. |
Definition at line 588 of file em_timer.h.
__STATIC_INLINE void TIMER_Enable | ( | TIMER_TypeDef * | timer, | |
bool | enable | |||
) |
Start/stop TIMER.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | enable | true to enable counting, false to disable. |
Definition at line 604 of file em_timer.h.
__STATIC_INLINE void TIMER_EnableDTI | ( | TIMER_TypeDef * | timer, | |
bool | enable | |||
) |
Enable or disable DTI unit.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | enable | true to enable DTI unit, false to disable. |
Definition at line 637 of file em_timer.h.
Referenced by TIMER_InitDTI().
__STATIC_INLINE uint32_t TIMER_GetDTIFault | ( | TIMER_TypeDef * | timer | ) |
Get DTI fault source flags status.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 666 of file em_timer.h.
Referenced by TIMER_InitDTI().
void TIMER_Init | ( | TIMER_TypeDef * | timer, | |
const TIMER_Init_TypeDef * | init | |||
) |
Initialize TIMER.
Notice that counter top must be configured separately with for instance TIMER_TopSet(). In addition, compare/capture and dead-time insertion init must be initialized separately if used. That should probably be done prior to the use of this function if configuring the TIMER to start when initialization is completed.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | init | Pointer to TIMER initialization structure. |
Definition at line 77 of file em_timer.c.
References TIMER_Init_TypeDef::clkSel, TIMER_Init_TypeDef::debugRun, TIMER_Init_TypeDef::dmaClrAct, TIMER_Init_TypeDef::enable, TIMER_Init_TypeDef::fallAction, TIMER_Init_TypeDef::mode, TIMER_Init_TypeDef::oneShot, TIMER_Init_TypeDef::prescale, TIMER_Init_TypeDef::quadModeX4, TIMER_Init_TypeDef::riseAction, and TIMER_Init_TypeDef::sync.
void TIMER_InitCC | ( | TIMER_TypeDef * | timer, | |
unsigned int | ch, | |||
const TIMER_InitCC_TypeDef * | init | |||
) |
Initialize TIMER compare/capture channel.
Notice that if operating channel in compare mode, the CCV and CCVB register must be set separately as required.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | ch | Compare/capture channel to init for. |
[in] | init | Pointer to TIMER initialization structure. |
Definition at line 132 of file em_timer.c.
References TIMER_InitCC_TypeDef::cmoa, TIMER_InitCC_TypeDef::cofoa, TIMER_InitCC_TypeDef::coist, TIMER_InitCC_TypeDef::cufoa, TIMER_InitCC_TypeDef::edge, TIMER_InitCC_TypeDef::eventCtrl, TIMER_InitCC_TypeDef::filter, TIMER_InitCC_TypeDef::mode, TIMER_InitCC_TypeDef::outInvert, TIMER_InitCC_TypeDef::prsInput, and TIMER_InitCC_TypeDef::prsSel.
void TIMER_InitDTI | ( | TIMER_TypeDef * | timer, | |
const TIMER_InitDTI_TypeDef * | init | |||
) |
Initialize the TIMER DTI unit.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | init | Pointer to TIMER DTI initialization structure. |
Definition at line 165 of file em_timer.c.
References TIMER_InitDTI_TypeDef::activeLowOut, TIMER_InitDTI_TypeDef::autoRestart, TIMER_InitDTI_TypeDef::enable, TIMER_InitDTI_TypeDef::enableFaultSourceCoreLockup, TIMER_InitDTI_TypeDef::enableFaultSourceDebugger, TIMER_InitDTI_TypeDef::enableFaultSourcePrsSel0, TIMER_InitDTI_TypeDef::enableFaultSourcePrsSel1, TIMER_InitDTI_TypeDef::enablePrsSource, TIMER_InitDTI_TypeDef::fallTime, TIMER_InitDTI_TypeDef::faultAction, TIMER_InitDTI_TypeDef::faultSourcePrsSel0, TIMER_InitDTI_TypeDef::faultSourcePrsSel1, TIMER_InitDTI_TypeDef::invertComplementaryOut, TIMER_InitDTI_TypeDef::outputsEnableMask, TIMER_InitDTI_TypeDef::prescale, TIMER_InitDTI_TypeDef::prsSel, TIMER_InitDTI_TypeDef::riseTime, TIMER_ClearDTIFault(), TIMER_EnableDTI(), and TIMER_GetDTIFault().
__STATIC_INLINE void TIMER_IntClear | ( | TIMER_TypeDef * | timer, | |
uint32_t | flags | |||
) |
Clear one or more pending TIMER interrupts.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | flags | Pending TIMER interrupt source(s) to clear. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
Definition at line 704 of file em_timer.h.
__STATIC_INLINE void TIMER_IntDisable | ( | TIMER_TypeDef * | timer, | |
uint32_t | flags | |||
) |
Disable one or more TIMER interrupts.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to disable. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
Definition at line 721 of file em_timer.h.
__STATIC_INLINE void TIMER_IntEnable | ( | TIMER_TypeDef * | timer, | |
uint32_t | flags | |||
) |
Enable one or more TIMER interrupts.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to enable. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
Definition at line 743 of file em_timer.h.
__STATIC_INLINE uint32_t TIMER_IntGet | ( | TIMER_TypeDef * | timer | ) |
Get pending TIMER interrupt flags.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 763 of file em_timer.h.
__STATIC_INLINE uint32_t TIMER_IntGetEnabled | ( | TIMER_TypeDef * | timer | ) |
Get enabled and pending TIMER interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 788 of file em_timer.h.
__STATIC_INLINE void TIMER_IntSet | ( | TIMER_TypeDef * | timer, | |
uint32_t | flags | |||
) |
Set one or more pending TIMER interrupts from SW.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | flags | TIMER interrupt source(s) to set to pending. Use one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together. |
Definition at line 812 of file em_timer.h.
__STATIC_INLINE void TIMER_Lock | ( | TIMER_TypeDef * | timer | ) |
Lock some of the TIMER registers in order to protect them from being modified.
Please refer to the reference manual for TIMER registers that will be locked.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 834 of file em_timer.h.
void TIMER_Reset | ( | TIMER_TypeDef * | timer | ) |
Reset TIMER to same state as after a HW reset.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 220 of file em_timer.c.
__STATIC_INLINE void TIMER_TopBufSet | ( | TIMER_TypeDef * | timer, | |
uint32_t | val | |||
) |
Set top value buffer for timer.
When the top value buffer register is updated, the value is loaded into the top value register at the next wrap around. This feature is useful in order to update the top value safely when the timer is running.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | val | Value to set in top value buffer register. |
Definition at line 859 of file em_timer.h.
__STATIC_INLINE uint32_t TIMER_TopGet | ( | TIMER_TypeDef * | timer | ) |
Get top value setting for timer.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 875 of file em_timer.h.
__STATIC_INLINE void TIMER_TopSet | ( | TIMER_TypeDef * | timer, | |
uint32_t | val | |||
) |
Set top value for timer.
[in] | timer | Pointer to TIMER peripheral register block. |
[in] | val | Value to set in top value register. |
Definition at line 891 of file em_timer.h.
__STATIC_INLINE void TIMER_Unlock | ( | TIMER_TypeDef * | timer | ) |
Unlock the TIMER so that writing to locked registers again is possible.
[in] | timer | Pointer to TIMER peripheral register block. |
Definition at line 905 of file em_timer.h.