// enable muxed pins as gpio outputs and disable all related interrupts.
// would need to also setup the pinmux register to select the gpio
// function of these pins in order to use as gpio.
// TMR0->GPINT_GPEN = GPENO12 | GPENI12;
// TMR0->GPDATA_GPDIR = GPDIRO12 | GPDIRI12;
// stop the timer, clear int stat, and clear timer value.
CLRBIT(TMR0->TGCR, TIM34RS);
TMR0->TCR = 0x00000000;
SETBIT(TMR0->INTCTLSTAT, PRDINTSTAT34);
TMR0->TIM34 = 0x00000000;
// setup compare time.
TMR0->PRD34 = TICKS_PER_US * in_delay;
// start timer1 - 3:4 to run once up to the period.
SETBIT(TMR0->TCR, ENAMODE34_ONETIME);
SETBIT(TMR0->TGCR, TIM34RS);
// wait for the signal that we have hit our period.
while (!CHKBIT(TMR0->INTCTLSTAT, PRDINTSTAT34));
#else
// stop the timer, clear int stat, and clear timer value.
CLRBIT(TMR0->TGCR, TIM12RS);
TMR0->TCR = 0x00000000;
SETBIT(TMR0->INTCTLSTAT, PRDINTSTAT12);
TMR0->TIM12 = 0x00000000;
uint32_t USTIMER0_init(void)
{
// configure timer 0 for free run.
// 32-bit unchained mode, timer3:4 /12 prescaler.
// enable muxed pins as gpio outputs and disable all related interrupts.
// would need to also setup the pinmux register to select the gpio
// function of these pins in order to use as gpio.
// TMR0->GPINT_GPEN = GPENO12 | GPENI12;
// TMR0->GPDATA_GPDIR = GPDIRO12 | GPDIRI12;
// stop and reset timer.
TMR0->TGCR = 0x00000000;
TMR0->TCR = 0x00000000;
// disable interrupts and set emulation to free run.
TMR0->INTCTLSTAT = 0;
SETBIT(TMR0->EMUMGT, SOFT | FREE);
// config timer0 in 32-bit unchained mode.
// remove timer0 - 3:4 from reset.
SETBIT(TMR0->TGCR, PRESCALER(TIMER_DIV - 1) | TIMMODE_32BIT_UNCHAINED /*| TIM34RS*/ );
// init timer0 - 1:2 period....use full range of counter.
TMR0->TIM34 = 0x00000000;
TMR0->PRD34 = 0x00000000;
// TMR0->PRD34 = 0xFFFFFFFF;
TMR0->TIM12 = 0x00000000;
TMR0->PRD12 = 0x00000000;
// start timer0 - 3:4.
// SETBIT(TMR0->TCR, ENAMODE34_CONT);
return (ERR_NO_ERROR);
}
void USTIMER0_delay(uint32_t in_delay)
{
uint32_t regData;
#if 0
// stop the timer, clear int stat, and clear timer value.
CLRBIT(TMR0->TGCR, TIM34RS);
TMR0->TCR = 0x00000000;
SETBIT(TMR0->INTCTLSTAT, PRDINTSTAT34);
TMR0->TIM34 = 0x00000000;
// setup compare time.
TMR0->PRD34 = TICKS_PER_US * in_delay;
// start timer1 - 3:4 to run once up to the period.
SETBIT(TMR0->TCR, ENAMODE34_ONETIME);
SETBIT(TMR0->TGCR, TIM34RS);
// wait for the signal that we have hit our period.
while (!CHKBIT(TMR0->INTCTLSTAT, PRDINTSTAT34));
#else
// stop the timer, clear int stat, and clear timer value.
CLRBIT(TMR0->TGCR, TIM12RS);
TMR0->TCR = 0x00000000;
SETBIT(TMR0->INTCTLSTAT, PRDINTSTAT12);
TMR0->TIM12 = 0x00000000;
// setup compare time.
TMR0->PRD12 = TICKS_PER_US * in_delay;
CLRBIT(TMR0->TCR,CLKSRC12);
CLRBIT(TMR0->TCR,TIEN12);
// start timer1 - 3:4 to run once up to the period.
SETBIT(TMR0->TCR, ENAMODE12_ONETIME);
SETBIT(TMR0->TGCR, TIM12RS);
// wait for the signal that we have hit our period.
while (!CHKBIT(TMR0->INTCTLSTAT, PRDINTSTAT12));
#endif
}
主函数
main()
{
USTIMER0_init();
printf("the timer0 test start " );
USTIMER0_delay(100);
printf("the timer0 test end ");
}
一周热门 更多>