TIMER
Detailed Description
Timer/Counter (TIMER) Peripheral API.
The timer module consists of three main parts:
- General timer configuration and enable control.
- Compare/capture control.
- Dead time insertion control (may not be available for all timers).
Data Structures |
|
struct | TIMER_Init_TypeDef |
struct | TIMER_InitCC_TypeDef |
Macros |
|
#define | TIMER_INIT_DEFAULT |
#define | TIMER_INITCC_DEFAULT |
#define | timerPRSSELCh0 0UL |
#define | timerPRSSELCh1 1UL |
#define | timerPRSSELCh10 10UL |
#define | timerPRSSELCh11 11UL |
#define | timerPRSSELCh2 2UL |
#define | timerPRSSELCh3 3UL |
#define | timerPRSSELCh4 4UL |
#define | timerPRSSELCh5 5UL |
#define | timerPRSSELCh6 6UL |
#define | timerPRSSELCh7 7UL |
#define | timerPRSSELCh8 8UL |
#define | timerPRSSELCh9 9UL |
Typedefs |
|
typedef uint8_t | TIMER_PRSSEL_TypeDef |
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_PrsOutput_t
{
timerPrsOutputPulse = 0, timerPrsOutputLevel = 1, timerPrsOutputDefault = timerPrsOutputPulse } |
Functions |
|
__STATIC_INLINE uint32_t | TIMER_CaptureBufGet (TIMER_TypeDef *timer, unsigned int ch) |
Get buffered compare/capture value for compare/capture channel.
|
|
__STATIC_INLINE uint32_t | TIMER_CaptureGet (TIMER_TypeDef *timer, unsigned int ch) |
Get compare/capture value for compare/capture channel.
|
|
__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 the TIMER compare/capture channel.
|
|
__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 uint32_t | TIMER_MaxCount (const TIMER_TypeDef *ref) |
Get the Max count of the timer.
|
|
void | TIMER_Reset (TIMER_TypeDef *timer) |
Reset the TIMER to the same state that it was in after a hardware 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 bool | TIMER_Valid (const TIMER_TypeDef *ref) |
Validate TIMER register block pointer.
|
|
Macro Definition Documentation
#define TIMER_INIT_DEFAULT |
Default configuration for TIMER initialization structure.
Definition at line
315
of file
em_timer.h
.
Referenced by BOARD_init() , and USTIMER_Init() .
#define TIMER_INITCC_DEFAULT |
Default configuration for TIMER compare/capture initialization structure.
Definition at line
431
of file
em_timer.h
.
Referenced by BOARD_init() , and USTIMER_Init() .
#define timerPRSSELCh0Â Â Â 0UL |
Deprecated PRS channel selector. New code should use an integer instead of using these deprecated enum values.
Definition at line
224
of file
em_timer.h
.
Typedef Documentation
typedef uint8_t TIMER_PRSSEL_TypeDef |
Peripheral Reflex System signal.
Definition at line
220
of file
em_timer.h
.
Enumeration Type Documentation
enum TIMER_CCMode_TypeDef |
enum TIMER_ClkSel_TypeDef |
enum TIMER_Edge_TypeDef |
enum TIMER_Event_TypeDef |
Input capture event control.
Definition at line
126
of file
em_timer.h
.
enum TIMER_Mode_TypeDef |
Prescaler.
Definition at line
190
of file
em_timer.h
.
enum TIMER_PrsOutput_t |
Function Documentation
__STATIC_INLINE uint32_t TIMER_CaptureBufGet | ( | TIMER_TypeDef * |
timer,
|
unsigned int |
ch
|
||
) |
Get buffered compare/capture value for compare/capture channel.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] ch
Compare/capture channel to access.
- Returns
- Current buffered capture value.
Definition at line
656
of file
em_timer.h
.
__STATIC_INLINE uint32_t TIMER_CaptureGet | ( | TIMER_TypeDef * |
timer,
|
unsigned int |
ch
|
||
) |
Get compare/capture value for compare/capture channel.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] ch
Compare/capture channel to access.
- Returns
- Current capture value.
Definition at line
630
of file
em_timer.h
.
__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.
- Parameters
-
[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
688
of file
em_timer.h
.
References TIMER_MaxCount() .
Referenced by BOARD_rgbledSetRawColor() .
__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.
- Parameters
-
[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
715
of file
em_timer.h
.
References TIMER_MaxCount() .
__STATIC_INLINE uint32_t TIMER_CounterGet | ( | TIMER_TypeDef * |
timer
|
) |
Get TIMER counter value.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block.
- Returns
- Current TIMER counter value.
Definition at line
738
of file
em_timer.h
.
__STATIC_INLINE void TIMER_CounterSet | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
val
|
||
) |
Set TIMER counter value.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] val
Value to set counter to.
Definition at line
753
of file
em_timer.h
.
References TIMER_MaxCount() .
__STATIC_INLINE void TIMER_Enable | ( | TIMER_TypeDef * |
timer,
|
bool |
enable
|
||
) |
Start/stop TIMER.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] enable
Set to true to enable counting; set to false otherwise.
Definition at line
779
of file
em_timer.h
.
Referenced by BOARD_rgbledSetRawColor() , and USTIMER_DeInit() .
void TIMER_Init | ( | TIMER_TypeDef * |
timer,
|
const TIMER_Init_TypeDef * |
init
|
||
) |
Initialize TIMER.
Notice that the counter top must be configured separately with, for instance TIMER_TopSet() . In addition, compare/capture and dead-time insertion initialization must be initialized separately if used, which should probably be done prior to using this function if configuring the TIMER to start when initialization is completed.
- Parameters
-
[in] timer
A pointer to the TIMER peripheral register block. [in] init
A pointer to the TIMER initialization structure.
Definition at line
157
of file
em_timer.c
.
References TIMER_Init_TypeDef::ati , TIMER_Init_TypeDef::clkSel , TIMER_Init_TypeDef::count2x , 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 .
Referenced by BOARD_init() , and USTIMER_Init() .
void TIMER_InitCC | ( | TIMER_TypeDef * |
timer,
|
unsigned int |
ch,
|
||
const TIMER_InitCC_TypeDef * |
init
|
||
) |
Initialize the TIMER compare/capture channel.
Notice that if operating the channel in compare mode, the CCV and CCVB register must be set separately, as required.
- Parameters
-
[in] timer
A pointer to the TIMER peripheral register block. [in] ch
A compare/capture channel to initialize for. [in] init
A pointer to the TIMER initialization structure.
Definition at line
231
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 , TIMER_InitCC_TypeDef::prsOutput , and TIMER_InitCC_TypeDef::prsSel .
Referenced by BOARD_init() , and USTIMER_Init() .
__STATIC_INLINE void TIMER_IntClear | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
flags
|
||
) |
Clear one or more pending TIMER interrupts.
- Parameters
-
[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
885
of file
em_timer.h
.
Referenced by USTIMER_DeInit() .
__STATIC_INLINE void TIMER_IntDisable | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
flags
|
||
) |
Disable one or more TIMER interrupts.
- Parameters
-
[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
905
of file
em_timer.h
.
Referenced by USTIMER_DeInit() , and USTIMER_Init() .
__STATIC_INLINE void TIMER_IntEnable | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
flags
|
||
) |
Enable one or more TIMER interrupts.
- Note
- Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using TIMER_IntClear() prior to enabling the interrupt.
- Parameters
-
[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
927
of file
em_timer.h
.
__STATIC_INLINE uint32_t TIMER_IntGet | ( | TIMER_TypeDef * |
timer
|
) |
Get pending TIMER interrupt flags.
- Note
- Event bits are not cleared by this function.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block.
- Returns
- TIMER interrupt source(s) pending. Returns one or more valid interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Definition at line
946
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.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block.
- Note
- Interrupt flags are not cleared by this function.
- Returns
-
Pending and enabled TIMER interrupt sources. The return value is the bitwise AND combination of
- the OR combination of enabled interrupt sources in TIMERx_IEN_nnn register (TIMERx_IEN_nnn) and
- the OR combination of valid interrupt flags of the TIMER module (TIMERx_IF_nnn).
Definition at line
970
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.
- Parameters
-
[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
993
of file
em_timer.h
.
__STATIC_INLINE uint32_t TIMER_MaxCount | ( | const TIMER_TypeDef * |
ref
|
) |
Get the Max count of the timer.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block.
- Returns
- The max count value of the timer. This is 0xFFFF for 16 bit timers and 0xFFFFFFFF for 32 bit timers.
Definition at line
595
of file
em_timer.h
.
Referenced by TIMER_CompareBufSet() , TIMER_CompareSet() , TIMER_CounterSet() , TIMER_TopBufSet() , and TIMER_TopSet() .
void TIMER_Reset | ( | TIMER_TypeDef * |
timer
|
) |
Reset the TIMER to the same state that it was in after a hardware reset.
- Note
- The ROUTE register is NOT reset by this function to allow for a centralized setup of this feature.
- Parameters
-
[in] timer
A pointer to the TIMER peripheral register block.
Definition at line
389
of file
em_timer.c
.
__STATIC_INLINE void TIMER_TopBufSet | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
val
|
||
) |
Set top value buffer for timer.
When top value buffer register is updated, value is loaded into top value register at the next wrap around. This feature is useful in order to update top value safely when timer is running.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] val
Value to set in top value buffer register.
Definition at line
1046
of file
em_timer.h
.
References TIMER_MaxCount() .
__STATIC_INLINE uint32_t TIMER_TopGet | ( | TIMER_TypeDef * |
timer
|
) |
Get top value setting for timer.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block.
- Returns
- Current top value.
Definition at line
1066
of file
em_timer.h
.
__STATIC_INLINE void TIMER_TopSet | ( | TIMER_TypeDef * |
timer,
|
uint32_t |
val
|
||
) |
Set top value for timer.
- Parameters
-
[in] timer
Pointer to TIMER peripheral register block. [in] val
Value to set in top value register.
Definition at line
1081
of file
em_timer.h
.
References TIMER_MaxCount() .
Referenced by BOARD_init() , and USTIMER_Init() .
__STATIC_INLINE bool TIMER_Valid | ( | const TIMER_TypeDef * |
ref
|
) |
Validate TIMER register block pointer.
- Parameters
-
[in] ref
Pointer to TIMER peripheral register block.
- Returns
- True if ref points to a valid timer, false otherwise.
Definition at line
548
of file
em_timer.h
.