/***************************************************************************//** * @brief * Activate the hardware timer used to pace the 1 millisecond timer system. * * @details * Call this function whenever the HFPERCLK frequency is changed. * This function is initially called by HOST and DEVICE stack xxxx_Init() * functions. ******************************************************************************/ void USBTIMER_Init( void ) { uint32_t freq; TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT; TIMER_InitCC_TypeDef timerCCInit = TIMER_INITCC_DEFAULT; freq = CMU_ClockFreqGet( cmuClock_HFPER ); ticksPrMs = ( freq + 500 ) / 1000; ticksPr1us = ( freq + 500000 ) / 1000000; ticksPr10us = ( freq + 50000 ) / 100000; ticksPr100us = ( freq + 5000 ) / 10000; timerCCInit.mode = timerCCModeCompare; CMU_ClockEnable( TIMER_CLK, true ); TIMER_TopSet( TIMER, 0xFFFF ); TIMER_InitCC( TIMER, 0, &timerCCInit ); TIMER_Init( TIMER, &timerInit ); #if ( NUM_QTIMERS > 0 ) TIMER_IntClear( TIMER, 0xFFFFFFFF ); TIMER_IntEnable( TIMER, TIMER_IEN_CC0 ); TIMER_CompareSet( TIMER, 0, TIMER_CounterGet( TIMER ) + ticksPrMs ); NVIC_ClearPendingIRQ( TIMER_IRQ ); NVIC_EnableIRQ( TIMER_IRQ ); #endif /* ( NUM_QTIMERS > 0 ) */ }
/***************************************************************************//** * @brief * RxTimer, Timer0 IRQHandler. ******************************************************************************/ void TIMER0_IRQHandler(void) { uint32_t irqFlags; irqFlags = TIMER_IntGet(HIJACK_RX_TIMER); TIMER_IntClear(HIJACK_RX_TIMER, irqFlags); if (TIMER_IF_CC1 & irqFlags) { cur_stamp = TIMER_CaptureGet(HIJACK_RX_TIMER, 1); TIMER_CounterSet(HIJACK_RX_TIMER, 0); edge_occur = true; /* Check what transition it was. */ if (GPIO_PinInGet(HIJACK_RX_GPIO_PORT, HIJACK_RX_GPIO_PIN)) { cur_edge = rising; BSP_LedSet( 0 ); } else { cur_edge = falling; BSP_LedClear( 0 ); } } }
void TIMER1_IRQHandler(void) { TIMER_CompareBufSet(TIMER1, 0, PWMratio); TIMER_CompareBufSet(TIMER1, 1, PWMratio); TIMER_IntClear(TIMER1, TIMER_IF_OF); //demoCycle(); }
/***************************************************************************//** * @brief * RxTimer, Timer0 IRQHandler. ******************************************************************************/ void TIMER0_IRQHandler(void) { uint32_t irqFlags; irqFlags = TIMER_IntGet(HIJACK_RX_TIMER); TIMER_IntClear(HIJACK_RX_TIMER, irqFlags); if (TIMER_IF_CC0 & irqFlags) { cur_stamp = TIMER_CaptureGet(HIJACK_RX_TIMER, 0); /* Check what transition it was. */ if(ACMP0->STATUS & ACMP_STATUS_ACMPOUT) { cur_edge = rising; //BSP_LedSet( 0 ); GPIO_PinOutSet(gpioPortD, 5); //Debug_Print( "%d ", cur_stamp ) ; } else { cur_edge = falling; //BSP_LedClear( 0 ); GPIO_PinOutClear(gpioPortD, 5); //Debug_Print( "%d ", cur_stamp ) ; } decode_machine(); } }
void TIMER0_IRQHandler(void) { // Clear the interrupt flag TIMER_IntClear(TIMER0, TIMER_IF_OF); // Increment the timer tick bsp_increment_timer_tick(); }
int timer_init(tim_t dev, unsigned long freq, timer_cb_t callback, void *arg) { TIMER_TypeDef *pre, *tim; /* test if given timer device is valid */ if (dev >= TIMER_NUMOF) { return -1; } /* save callback */ isr_ctx[dev].cb = callback; /* get timers */ pre = timer_config[dev].prescaler.dev; tim = timer_config[dev].timer.dev; /* enable clocks */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(timer_config[dev].prescaler.cmu, true); CMU_ClockEnable(timer_config[dev].timer.cmu, true); /* reset and initialize peripherals */ EFM32_CREATE_INIT(init_pre, TIMER_Init_TypeDef, TIMER_INIT_DEFAULT, .conf.enable = false, .conf.prescale = timerPrescale1 ); EFM32_CREATE_INIT(init_tim, TIMER_Init_TypeDef, TIMER_INIT_DEFAULT, .conf.enable = false, .conf.clkSel = timerClkSelCascade ); TIMER_Reset(tim); TIMER_Reset(pre); TIMER_Init(tim, &init_tim.conf); TIMER_Init(pre, &init_pre.conf); /* configure the prescaler top value */ uint32_t freq_timer = CMU_ClockFreqGet(timer_config[dev].prescaler.cmu); uint32_t top = ( freq_timer / TIMER_Prescaler2Div(init_pre.conf.prescale) / freq) - 1; TIMER_TopSet(pre, top); TIMER_TopSet(tim, 0xffff); /* enable interrupts for the channels */ TIMER_IntClear(tim, TIMER_IFC_CC0 | TIMER_IFC_CC1 | TIMER_IFC_CC2); TIMER_IntEnable(tim, TIMER_IEN_CC0 | TIMER_IEN_CC1 | TIMER_IEN_CC2); NVIC_ClearPendingIRQ(timer_config[dev].irq); NVIC_EnableIRQ(timer_config[dev].irq); /* start the timers */ TIMER_Enable(tim, true); TIMER_Enable(pre, true); return 0; }
/**************************************************************************//** * @brief TIMER0_IRQHandler * Interrupt Service Routine TIMER0 Interrupt Line *****************************************************************************/ void TIMER0_IRQHandler(void) { /* Clear flag for TIMER0 overflow interrupt */ TIMER_IntClear(TIMER0, TIMER_IF_OF); TIMER_CompareBufSet(TIMER0, 1, value_left_wheel); TIMER_CompareBufSet(TIMER0, 2, value_right_wheel); }
void TIMER3_IRQHandler(void) { uint32_t timer_if = TIMER_IntGet(TIMER3) & (TIMER_IF_CC1 | TIMER_IF_OF); TIMER_IntClear(TIMER3, TIMER_IF_CC1 | TIMER_IF_OF); if (timer_if & TIMER_IF_OF) { GPIO_PinOutSet(LED5_PORT_PIN); } else { GPIO_PinOutClear(LED5_PORT_PIN); } }
void us_ticker_set_interrupt(timestamp_t timestamp) { TIMER_IntDisable(US_TICKER_TIMER, TIMER_IEN_CC0); TIMER_IntClear(US_TICKER_TIMER, TIMER_IEN_CC0); TIMER_CompareSet(US_TICKER_TIMER, 0, timestamp); TIMER_IntEnable(US_TICKER_TIMER, TIMER_IEN_CC0); }
/**************************************************************************//** * @brief TIMER0_IRQHandler * Interrupt Service Routine TIMER0 Interrupt Line *****************************************************************************/ void TIMER2_IRQHandler(void) { uint32_t compareValue; /* Clear flag for TIMER0 overflow interrupt */ TIMER_IntClear(TIMER2, TIMER_IF_OF); TIMER_CompareBufSet(TIMER2, 0, TIMER_CaptureGet(TIMER2, 0)); TIMER_CompareBufSet(TIMER2, 1, TIMER_CaptureGet(TIMER2, 1)); }
/** * \brief Timer1 interrupt handler. */ void TIMER1_IRQHandler() { uint32_t flags; INT_Disable(); flags = TIMER_IntGet( TIMER1 ); _hal_tcCb(); TIMER_IntClear( TIMER1, flags ); INT_Enable(); }
void TIMER0_IRQHandler( void ) { TIMER_IntClear( TIMER0, TIMER_IF_OF ); static int i = 0; if (++i >= bufferSize) { copySamples(); i = 0; } FPGA_ToggleClock(); }
void TIMER_IRQHandler( void ) { uint32_t flags; flags = TIMER_IntGet( TIMER ); if ( flags & TIMER_IF_CC0 ) { TIMER_IntClear( TIMER, TIMER_IFC_CC0 ); TIMER_CompareSet( TIMER, 0, TIMER_CaptureGet( TIMER, 0 ) + ticksPrMs ); TimerTick(); } }
/***************************************************************************//** * @brief * Timer1 IRQHandler. ******************************************************************************/ void TIMER1_IRQHandler(void) { uint32_t irqFlags; /* Clear all pending IRQ flags. */ irqFlags = TIMER_IntGet(HIJACK_TX_TIMER); TIMER_IntClear(HIJACK_TX_TIMER, irqFlags); /* Reset the counter and the compare value. */ TIMER_CounterSet(HIJACK_TX_TIMER, 0); TIMER_CompareSet(HIJACK_TX_TIMER, 0, HIJACK_NUM_TICKS_PER_HALF_CYCLE); }
/***************************************************************************//** * @brief * Timer1 IRQHandler. ******************************************************************************/ void TIMER1_IRQHandler(void) { //static volatile uint8_t currentPin = 1; //static volatile uint8_t currentSym = 1; static volatile uint8_t txParity = 0; uint32_t irqFlags; /* Clear all pending IRQ flags. */ irqFlags = TIMER_IntGet(HIJACK_TX_TIMER); TIMER_IntClear(HIJACK_TX_TIMER, irqFlags); ticker++; /* Reset the counter and the compare value. */ TIMER_CounterSet(HIJACK_TX_TIMER, 0); TIMER_CompareSet(HIJACK_TX_TIMER, 0, 500ul*HIJACK_NUM_TICKS_PER_1US*HIJACK_ENC_CARRIER_FREQ_1KHZ/HIJACK_ENC_CARRIER_FREQ_CONF); //BSP_LedToggle(0); encode_machine(); }
/**************************************************************************//** * @brief TIMER0 Interrupt Handler. Writes interrupt count to LCD display *****************************************************************************/ void TIMER0_IRQHandler(void) { /* Clear TIMER0 OF interrupt flag. */ /* Do not need to check other flags since we know this is the only one enabled */ TIMER_IntClear(TIMER0, TIMER_IFC_OF); /* Increment interrupt count and write to LCD */ interruptCount++; SegmentLCD_Number(interruptCount); /* Wait until interrupt has been serviced 5 times */ if (interruptCount >= 5) { /* Clear SLEEPONEXIT to go back to main after ISR */ SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; /* Stop TIMER0 */ TIMER0->CMD = TIMER_CMD_STOP; } }
void TIMER0_IRQHandler(void) { /* Clear flag for TIMER0 overflow interrupt */ TIMER_IntClear(TIMER0, TIMER_IF_OF); /* If the total transfer has not finished, send a request for another * transfer */ if (flashTransferActive) { /* Manual software request to DMA channel 0 */ DMA->CHSWREQ = DMA_CHSWREQ_CH0SWREQ; /* Output the buffer */ SegmentLCD_Write(ramBuffer); } else { /* The transfer has completed, no more need for the interrupt */ TIMER_IntDisable(TIMER0, TIMER_IEN_OF); } }
void us_ticker_init(void) { if (us_ticker_inited) { /* calling init again should cancel current interrupt */ us_ticker_disable_interrupt(); return; } us_ticker_inited = true; /* Enable clock for TIMERs */ CMU_ClockEnable(US_TICKER_TIMER_CLOCK, true); if (REFERENCE_FREQUENCY > 24000000) { US_TICKER_TIMER->CTRL = (US_TICKER_TIMER->CTRL & ~_TIMER_CTRL_PRESC_MASK) | (4 << _TIMER_CTRL_PRESC_SHIFT); } else { US_TICKER_TIMER->CTRL = (US_TICKER_TIMER->CTRL & ~_TIMER_CTRL_PRESC_MASK) | (3 << _TIMER_CTRL_PRESC_SHIFT); } /* Clear TIMER counter value */ TIMER_CounterSet(US_TICKER_TIMER, 0); /* Start TIMER */ TIMER_Enable(US_TICKER_TIMER, true); /* Select Compare Channel parameters */ TIMER_InitCC_TypeDef timerCCInit = TIMER_INITCC_DEFAULT; timerCCInit.mode = timerCCModeCompare; /* Configure Compare Channel 0 */ TIMER_InitCC(US_TICKER_TIMER, 0, &timerCCInit); /* Enable interrupt vector in NVIC */ TIMER_IntClear(US_TICKER_TIMER, TIMER_IEN_CC0); NVIC_SetVector(US_TICKER_TIMER_IRQ, (uint32_t) us_ticker_irq_handler); NVIC_EnableIRQ(US_TICKER_TIMER_IRQ); }
void TIMER0_IRQHandler(void) { //int32_t bmp180_raw; /* Store the interrupt flags before clearing */ uint16_t intFlags = TIMER_IntGet(TIMER0); /* Clear the interrupt flags. Only clear the flags that were stored in */ /* intFlags in case other flags have been set since then */ TIMER_IntClear(TIMER0, intFlags); /* Overflow interrupt occurred */ if(intFlags & TIMER_IF_OF) { GPIO_PinOutToggle(LED_PORT, LED0_PIN ); // turn on LED0 GPIO_PinOutToggle(LED_PORT, LED1_PIN ); // turn on LED0 //GPIO_PinOutToggle(EXT_LED, YEL_LED); // GPIO_PinOutToggle(LED_PORT, LED1_PIN ); // GPIO_PinOutToggle(LED_PORT, OPLED_PIN); timeout++; counter = counter + 1; if(counter > 10) { //count to 10. then check to see how many fix vals have occured. if(fix_val < 3) { //if fix_val is greater than 2, then no fix. If less than 2, then solid fix fix_val = 0; satfix = 1; //solid fix, so notify } else { satfix = 0; } counter = 0; //reset counter } } }
void TIMER1_IRQHandler(void) { timer1_overflow = true; base_value += ONE_MILLISECOND_BASE_VALUE_COUNT; TIMER_IntClear(TIMER1, TIMER_IF_OF); }
/***************************************************************************//** * @brief * Initialize the specified TIMER unit * * @details * * @note * * @param[in] device * Pointer to device descriptor * * @param[in] unitNumber * Unit number * * @return * Pointer to TIMER device ******************************************************************************/ static struct efm32_timer_device_t *rt_hw_timer_unit_init( rt_device_t device, rt_uint8_t unitNumber, rt_uint8_t mode) { struct efm32_timer_device_t *timer; TIMER_Init_TypeDef init; efm32_irq_hook_init_t hook; CMU_Clock_TypeDef timerClock; IRQn_Type timerIrq; do { /* Allocate device */ timer = rt_malloc(sizeof(struct efm32_timer_device_t)); if (timer == RT_NULL) { timer_debug("no memory for TIMER%d driver\n", unitNumber); break; } /* Initialization */ if (unitNumber >= TIMER_COUNT) { break; } switch (unitNumber) { case 0: timer->timer_device = TIMER0; timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER0; timerIrq = TIMER0_IRQn; break; case 1: timer->timer_device = TIMER1; timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER1; timerIrq = TIMER1_IRQn; break; case 2: timer->timer_device = TIMER2; timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER2; timerIrq = TIMER2_IRQn; break; default: break; } /* Enable TIMER clock */ CMU_ClockEnable(timerClock, true); /* Reset */ TIMER_Reset(timer->timer_device); /* Init specified TIMER unit */ init.enable = false; init.debugRun = true; init.prescale = TMR_CFG_PRESCALER; init.clkSel = timerClkSelHFPerClk; init.fallAction = timerInputActionNone; init.riseAction = timerInputActionNone; init.mode = timerModeUp; init.dmaClrAct = false; init.quadModeX4 = false; init.oneShot = (mode > 0) ? true : false; init.sync = false; TIMER_Init(timer->timer_device, &init); /* Config interrupt and NVIC */ hook.type = efm32_irq_type_timer; hook.unit = unitNumber; hook.cbFunc = rt_hw_timer_isr; hook.userPtr = device; efm32_irq_hook_register(&hook); /* Enable overflow interrupt */ TIMER_IntEnable(timer->timer_device, TIMER_IF_OF); TIMER_IntClear(timer->timer_device, TIMER_IF_OF); /* Enable TIMERn interrupt vector in NVIC */ NVIC_ClearPendingIRQ(timerIrq); NVIC_SetPriority(timerIrq, EFM32_IRQ_PRI_DEFAULT); NVIC_EnableIRQ(timerIrq); return timer; } while(0); if (timer) { rt_free(timer); } rt_kprintf("TIMER: Init failed!\n"); return RT_NULL; }
void initPWM() // Brightness should be less than TIMER_TOP (1024) { /* Enable clocks */ CMU->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO; CMU_ClockEnable(cmuClock_TIMER1, true); /* Set pins */ GPIO_PinModeSet(gpioPortE,10,gpioModePushPull,1); GPIO_PinModeSet(gpioPortE,11,gpioModePushPull,1); /* Select CC channel parameters */ TIMER_InitCC_TypeDef timerCCInit = { .eventCtrl = timerEventEveryEdge, .edge = timerEdgeBoth, .prsSel = timerPRSSELCh0, .cufoa = timerOutputActionNone, .cofoa = timerOutputActionNone, .cmoa = timerOutputActionToggle, .mode = timerCCModePWM, .filter = false, .prsInput = false, .coist = false, .outInvert = false, }; /* Configure CC channels */ TIMER_InitCC(TIMER1, 0, &timerCCInit); TIMER_InitCC(TIMER1, 1, &timerCCInit); /* Set which pins will be set by the timer */ TIMER1->ROUTE = TIMER_ROUTE_CC0PEN | TIMER_ROUTE_CC1PEN | TIMER_ROUTE_LOCATION_LOC1; /* Set Top Value */ TIMER_TopSet(TIMER1, TIMER_TOP); /* Set compare value starting at top - it will be incremented in the interrupt handler */ TIMER_CompareBufSet(TIMER1, 0, TIMER_TOP + 1); TIMER_CompareBufSet(TIMER1, 1, TIMER_TOP + 1); /* Select timer parameters */ TIMER_Init_TypeDef timerInit = { .enable = true, .debugRun = false, .prescale = timerPrescale16, .clkSel = timerClkSelHFPerClk, .fallAction = timerInputActionNone, .riseAction = timerInputActionNone, .mode = timerModeUp, .dmaClrAct = false, .quadModeX4 = false, .oneShot = false, .sync = false, }; /* Enable overflow interrupt */ TIMER_IntEnable(TIMER1, TIMER_IF_OF); TIMER_IntClear(TIMER1, TIMER_IF_OF); /* Enable TIMER1 interrupt vector in NVIC */ NVIC_EnableIRQ(TIMER1_IRQn); /* Configure timer */ TIMER_Init(TIMER1, &timerInit); }
/****************************************************************************** * @brief TIMER1_IRQHandler on active burst/rburst counting Interrupts of CC2 * *****************************************************************************/ void TIMER1_IRQHandler(void) { /* Store the interrupt flags before clearing */ uint16_t intFlags = TIMER1->IF; /* Clear the interrupt flags. Only clear the flags that were stored in */ /* intFlags in case other flags have been set since then */ TIMER_IntClear( TIMER1, intFlags ); /* CC2 interrupt occurred */ if( intFlags & TIMER_IF_CC2 ) { counter++; switch (MM_Entry) { case distance: TX_Stop_Burst(); break; case speed: // measure speed break; case testing: switch (SM_Testing) { case tst_measure: case sburst: if ( counter == BURST_PULSE_CNT || counter == (BURST_PULSE_CNT + 1) ) { // TIMER1->CC[0].CTRL = DL_CC_STOP; // stop CH1 // TIMER1->CC[1].CTRL = DH_CC_STOP; // stop CH2 // TIMER1->CC[2].CTRL = CC2_STOP; TX_Stop_Burst(); routineactive = false; // show Program State OFF RoutineStateChng = true; } break; case rburst: if (counter == BURST_PULSE_CNT) { TX_Stop_Signal(); } else if ( SM_Testing == rburst && counter == PERIOD_PULSE_CNT ) { // after a cycle restart the cycle again TX_Start_Burst(); } break; default: ; // do nothing State } break; default: ; } } }// END: TIMER1_IRQHandler
void us_ticker_clear_interrupt(void) { /* Clear compare channel interrupts */ TIMER_IntClear(US_TICKER_TIMER, TIMER_IFC_CC0); }
void InitAudioPWM(void) { CMU_ClockEnable(cmuClock_TIMER1, true); /* Select CC channel parameters */ TIMER_InitCC_TypeDef timerCCInit = { .eventCtrl = timerEventEveryEdge, .edge = timerEdgeBoth, .prsSel = timerPRSSELCh0, .cufoa = timerOutputActionNone, .cofoa = timerOutputActionNone, .cmoa = timerOutputActionToggle, .mode = timerCCModePWM, .filter = false, .prsInput = false, .coist = false, .outInvert = false, }; /* Configure CC channel 0 */ TIMER_InitCC(TIMER1, 0, &timerCCInit); TIMER_InitCC(TIMER1, 1, &timerCCInit); //TIMER_InitCC(TIMER0, 2, &timerCCInit); // TIMER3->ROUTE |= (TIMER_ROUTE_CC0PEN | TIMER_ROUTE_CC1PEN | TIMER_ROUTE_CC2PEN | TIMER_ROUTE_LOCATION_LOC0); TIMER1->ROUTE = TIMER_ROUTE_CC0PEN | TIMER_ROUTE_CC1PEN | TIMER_ROUTE_LOCATION_LOC1; /* Set Top Value */ TIMER_TopSet(TIMER1, 255);//384 /* Set compare value starting at top - it will be incremented in the interrupt handler */ TIMER_CompareBufSet(TIMER1, 0, 256);//385 TIMER_CompareBufSet(TIMER1, 1, 256);//385 //TIMER_CompareBufSet(TIMER3, 2, RGB_PWM_TIMER_TOP + 1); /* Select timer parameters */ TIMER_Init_TypeDef timerInit = { .enable = true, .debugRun = false, .prescale = timerPrescale8, .clkSel = timerClkSelHFPerClk, .fallAction = timerInputActionNone, .riseAction = timerInputActionNone, .mode = timerModeUp, .dmaClrAct = false, .quadModeX4 = false, .oneShot = false, .sync = false, }; ///* Enable overflow interrupt */ TIMER_IntEnable(TIMER1, TIMER_IF_OF); TIMER_IntClear(TIMER1, TIMER_IF_OF); /* Enable TIMER0 interrupt vector in NVIC */ NVIC_EnableIRQ(TIMER1_IRQn); /* Configure timer */ TIMER_Init(TIMER1, &timerInit); } void TIMER1_IRQHandler(void) { int audio_Sample = 0; if(toPlay > 0) { audio_Sample = buff[(iterator = next(iterator))]; toPlay--; } else { audio_Sample = 0; } TIMER_CompareBufSet(TIMER1, 0, (audio_Sample)); TIMER_IntClear(TIMER1, TIMER_IF_OF); }
/***************************************************************************//** * @brief * Interrupt Service Routine for TIMER1 Interrupt Line. ******************************************************************************/ void TIMER1_IRQHandler(void) { // Clear flag for TIMER1 overflow interrupt TIMER_IntClear(TIMER1, TIMER_IF_OF); TickUser++; }