44 uint32_t u32Cmpr = 0, u32Prescale = 0;
47 if(u32Freq > (u32Clk / 2))
53 u32Cmpr = u32Clk / u32Freq;
54 u32Prescale = (u32Cmpr >> 24);
56 u32Cmpr = u32Cmpr / (u32Prescale + 1);
59 timer->
CTL = u32Mode | u32Prescale;
62 return(u32Clk / (u32Cmpr * (u32Prescale + 1)));
95 uint32_t u32Prescale = 0UL, u32Delay;
96 uint32_t u32Cmpr, u32Cntr, u32NsecPerTick, i = 0UL;
102 if(u32Clk <= 1000000UL)
108 if(u32Usec > 1000000UL)
119 if(u32Usec > 1000000UL)
125 if(u32Clk <= 1000000UL)
128 u32NsecPerTick = 1000000000UL / u32Clk;
129 u32Cmpr = (u32Usec * 1000UL) / u32NsecPerTick;
133 u32Cmpr = u32Usec * (u32Clk / 1000000UL);
134 u32Prescale = (u32Cmpr >> 24);
135 if (u32Prescale > 0UL)
136 u32Cmpr = u32Cmpr / (u32Prescale + 1UL);
139 timer->
CMP = u32Cmpr;
145 for(u32Delay = (
SystemCoreClock / u32Clk) + 1UL; u32Delay > 0UL; u32Delay--)
154 u32Cntr = timer->
CNT;
159 if(u32Cntr == timer->
CNT)
169 u32Cntr = timer->
CNT;
211 timer->
EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
230 timer->
EXTCTL = (timer->
EXTCTL & ~TIMER_EXTCTL_CNTPHASE_Msk) | u32Edge;
245 timer->
CTL &= ~TIMER_CTL_EXTCNTEN_Msk;
277 return (au32Clk[u32Src]);
#define TIMER_EXTCTL_CAPFUNCS_Msk
#define TIMER_EXTCTL_CAPEDGE_Msk
#define TIMER_CTL_EXTCNTEN_Msk
#define TIMER_CTL_ACTSTS_Msk
#define TIMER_CTL_CNTEN_Msk
#define TIMER_EXTCTL_CAPEN_Msk
NuMicro peripheral access layer header file.
#define CLK_CLKSEL1_TMR1SEL_Msk
#define CLK_CLKSEL1_TMR0SEL_Msk
#define CLK_CLKSEL1_TMR2SEL_Pos
#define CLK_CLKSEL1_TMR1SEL_Pos
#define CLK_CLKSEL1_TMR3SEL_Msk
#define CLK_CLKSEL1_TMR3SEL_Pos
#define CLK_CLKSEL1_TMR0SEL_Pos
#define CLK_CLKSEL1_TMR2SEL_Msk
#define TIMER_ONESHOT_MODE
#define TIMER_TIMEOUT_ERR
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.
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.
int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.