44 uint32_t u32Cmpr = 0UL, u32Prescale = 0UL;
47 if(u32Freq > (u32Clk / 2UL))
53 u32Cmpr = u32Clk / u32Freq;
54 u32Prescale = (u32Cmpr >> 24);
55 if (u32Prescale > 0UL)
56 u32Cmpr = u32Cmpr / (u32Prescale + 1UL);
59 timer->
CTL = u32Mode | u32Prescale;
62 return(u32Clk / (u32Cmpr * (u32Prescale + 1UL)));
97 uint32_t u32Prescale = 0UL, u32Delay;
98 uint32_t u32Cmpr, u32Cntr, u32NsecPerTick, i = 0UL;
104 if(u32Clk <= 1000000UL)
110 if(u32Usec > 1000000UL)
121 if(u32Usec > 1000000UL)
127 if(u32Clk <= 1000000UL)
130 u32NsecPerTick = 1000000000UL / u32Clk;
131 u32Cmpr = (u32Usec * 1000UL) / u32NsecPerTick;
135 u32Cmpr = u32Usec * (u32Clk / 1000000UL);
136 u32Prescale = (u32Cmpr >> 24);
137 if (u32Prescale > 0UL)
138 u32Cmpr = u32Cmpr / (u32Prescale + 1UL);
141 timer->
CMP = u32Cmpr;
147 for(u32Delay = (
SystemCoreClock / u32Clk) + 1UL; u32Delay > 0UL; u32Delay--)
156 u32Cntr = timer->
CNT;
160 if(u32Cntr == timer->
CNT)
170 u32Cntr = timer->
CNT;
212 timer->
EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
231 timer->
EXTCTL = (timer->
EXTCTL & ~TIMER_EXTCTL_CNTPHASE_Msk) | u32Edge;
246 timer->
CTL &= ~TIMER_CTL_EXTCNTEN_Msk;
261 uint32_t u32Src, u32Clk;
294 u32Clk = au32Clk[u32Src];
316 uint32_t u32DropCount,
318 uint32_t u32EnableInt)
337 timer->
CTL &= ~TIMER_CTL_INTRGEN_Msk;
351 timer->
TRGCTL = (timer->
TRGCTL & ~TIMER_TRGCTL_TRGSSEL_Msk) | u32Src;
NuMicro peripheral access layer header file.
uint32_t CLK_GetPCLK1Freq(void)
Get PCLK1 frequency.
uint32_t CLK_GetPCLK0Freq(void)
Get PCLK0 frequency.
#define CLK_CLKSEL1_TMR1SEL_Msk
#define TIMER_TRGCTL_TRGEADC_Msk
#define CLK_CLKSEL1_TMR0SEL_Msk
#define TIMER_TRGCTL_TRGPDMA_Msk
#define TIMER_EXTCTL_CAPFUNCS_Msk
#define CLK_CLKSEL1_TMR2SEL_Pos
#define TIMER_EXTCTL_CAPEDGE_Msk
#define CLK_CLKSEL1_TMR1SEL_Pos
#define TIMER_TRGCTL_TRGEPWM_Msk
#define TIMER_CTL_EXTCNTEN_Msk
#define TIMER_EXTCTL_CAPIEN_Msk
#define TIMER_TRGCTL_TRGDAC_Msk
#define TIMER_CTL_INTRGEN_Msk
#define CLK_CLKSEL1_TMR3SEL_Msk
#define TIMER_CTL_ACTSTS_Msk
#define TIMER_CTL_CNTEN_Msk
#define CLK_CLKSEL1_TMR3SEL_Pos
#define TIMER_EXTCTL_CAPEN_Msk
#define CLK_CLKSEL1_TMR0SEL_Pos
#define TIMER_CNT_RSTACT_Msk
#define CLK_CLKSEL1_TMR2SEL_Msk
#define TIMER_ONESHOT_MODE
#define TIMER_TIMEOUT_ERR
void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src)
This function is used to select the interrupt source used to trigger other modules.
void TIMER_DisableCapture(TIMER_T *timer)
Disable Timer Capture Function.
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
Open Timer with Operate Mode and Frequency.
void TIMER_DisableEventCounter(TIMER_T *timer)
Disable Timer Counter Function.
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
Get Timer Clock Frequency.
int32_t TIMER_ResetCounter(TIMER_T *timer)
Reset Counter.
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
Enable Timer Counter Function.
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
Enable Timer Capture Function.
void TIMER_Close(TIMER_T *timer)
Stop Timer Counting.
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.
void TIMER_EnableFreqCounter(TIMER_T *timer, uint32_t u32DropCount, uint32_t u32Timeout, uint32_t u32EnableInt)
This function is used to enable the Timer frequency counter function.