static void initHardware(void) { SystemCoreClockUpdate(); SysTick_Config(SystemCoreClock/1000); Board_Init(); Board_LED_Set(0, false); /* Timer */ Chip_TIMER_Init(LPC_TIMER1); Chip_TIMER_PrescaleSet(LPC_TIMER1, #ifdef lpc1769 Chip_Clock_GetPeripheralClockRate(SYSCTL_PCLK_TIMER1) / 1000000 - 1 #else Chip_Clock_GetRate(CLK_MX_TIMER1) / 1000000 - 1 #endif ); /* Match 0 (period) */ Chip_TIMER_MatchEnableInt(LPC_TIMER1, 0); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 0); Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 0); Chip_TIMER_SetMatch(LPC_TIMER1, 0, 1000); /* Match 1 (duty) */ Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1); Chip_TIMER_ResetOnMatchDisable(LPC_TIMER1, 1); Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 1); Chip_TIMER_SetMatch(LPC_TIMER1, 1, 100); Chip_TIMER_Reset(LPC_TIMER1); Chip_TIMER_Enable(LPC_TIMER1); NVIC_EnableIRQ(TIMER1_IRQn); }
/** * @details Initiizes timers for timer based interrupts */ void Init_Timers(void) { // ------------------------------------------------ // Timer 32_0 Init Chip_TIMER_Init(LPC_TIMER32_0); Chip_TIMER_Reset(LPC_TIMER32_0); Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 0); Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, Hertz2Ticks(10)); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 0); // Chip_TIMER_Enable(LPC_TIMER32_0); /* Enable timer interrupt */ NVIC_ClearPendingIRQ(TIMER_32_0_IRQn); NVIC_EnableIRQ(TIMER_32_0_IRQn); // ------------------------------------------------ // Timer 32_0 Init Chip_TIMER_Init(LPC_TIMER32_1); Chip_TIMER_Reset(LPC_TIMER32_1); Chip_TIMER_MatchEnableInt(LPC_TIMER32_1, 0); Chip_TIMER_SetMatch(LPC_TIMER32_1, 0, Hertz2Ticks(BCM_POLL_IDLE_FREQ)); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_1, 0); /* Enable timer_32_1 interrupt */ NVIC_ClearPendingIRQ(TIMER_32_1_IRQn); NVIC_EnableIRQ(TIMER_32_1_IRQn); Chip_TIMER_Enable(LPC_TIMER32_1); }
/** * @brief main routine for timer example * @return Function should not exit. */ int main(void) { uint32_t timerBaseClock; SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); Board_LED_Set(1, false); /* Initialize Timer 0 and Timer 1 */ Chip_TIMER_Init(LPC_TIMER0); Chip_TIMER_Init(LPC_TIMER1); /* Setup prescale value on Timer 0 to PCLK */ Chip_TIMER_PrescaleSet(LPC_TIMER0, 0); /* Setup prescale value on Timer 1 for lower resolution */ Chip_TIMER_PrescaleSet(LPC_TIMER1, PRESCALE_HZ2); /* Reset timers */ Chip_TIMER_Reset(LPC_TIMER0); Chip_TIMER_Reset(LPC_TIMER1); /* Enable both timers to generate interrupts when time matches */ Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1); Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1); /* Get rate of timer base clock */ timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate(); /* Setup Timer 0 for a match every 1s */ Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerBaseClock / TICKRATE_HZ1)); /* Setup Timer 1 for a match twice in a second */ Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerBaseClock / ((PRESCALE_HZ2 + 1) * TICKRATE_HZ2)) ); /* Setup both timers to restart when match occurs */ Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1); /* Start both timers */ Chip_TIMER_Enable(LPC_TIMER0); Chip_TIMER_Enable(LPC_TIMER1); /* Clear both timers of any pending interrupts */ NVIC_ClearPendingIRQ(CT32B0_IRQn); NVIC_ClearPendingIRQ(CT32B1_IRQn); /* Enable both timer interrupts */ NVIC_EnableIRQ(CT32B0_IRQn); NVIC_EnableIRQ(CT32B1_IRQn); /* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */ while (1) { __WFI(); } return 0; }
/** * @brief Initialization 32-bit Timer 0 * @return Nothing */ void Timer32_0_Init(uint32_t tickrate) { uint32_t timerFreq; /* Initialize 32-bit timer 0 clock */ Chip_TIMER_Init(LPC_TIMER32_0); /* Timer rate is system clock rate */ timerFreq = Chip_Clock_GetSystemClockRate(); /* Timer setup for match and interrupt at TICKRATE_HZ */ Chip_TIMER_Reset(LPC_TIMER32_0); /* Enable timer to generate interrupts when time matches */ Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 1); /* Setup 32-bit timer's duration (32-bit match time) */ Chip_TIMER_SetMatch(LPC_TIMER32_0, 1, (timerFreq / tickrate)); /* Setup timer to restart when match occurs */ Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 1); /* Start timer */ Chip_TIMER_Enable(LPC_TIMER32_0); /* Clear timer of any pending interrupts */ NVIC_ClearPendingIRQ(TIMER_32_0_IRQn); /* Enable timer interrupt */ NVIC_EnableIRQ(TIMER_32_0_IRQn); }
/** * @brief main routine for blinky example * @return Function should not exit. */ int main(void) { uint32_t timerFreq; /* Generic Initialization */ SystemCoreClockUpdate(); Board_Init(); /* Enable timer 1 clock */ Chip_TIMER_Init(LPC_TIMER0); /* Timer rate is system clock rate */ timerFreq = Chip_Clock_GetSystemClockRate(); /* Timer setup for match and interrupt at TICKRATE_HZ */ Chip_TIMER_Reset(LPC_TIMER0); Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1); Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerFreq / TICKRATE_HZ1)); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1); Chip_TIMER_Enable(LPC_TIMER0); /* Enable timer interrupt */ NVIC_ClearPendingIRQ(TIMER0_IRQn); NVIC_EnableIRQ(TIMER0_IRQn); /* LEDs toggle in interrupt handlers */ while (1) { __WFI(); } return 0; }
/* * @Brief Initialize Timer peripheral * @param timerNumber: Timer number, 0 to 3 * @param ticks: Number of ticks required to finish the cycle. * @param voidFunctionPointer: function to be executed at the end of the timer cycle * @return nothing * @note For the 'ticks' parameter, see function Timer_microsecondsToTicks */ void Timer_Init( uint8_t timerNumber, uint32_t ticks, voidFunctionPointer_t voidFunctionPointer){ /* Source: http://docs.lpcware.com/lpcopen/v1.03/lpc18xx__43xx_2examples_2periph_2periph__blinky_2blinky_8c_source.html */ /*If timer period = CompareMatch0 Period = 0 => ERROR*/ if (ticks==0){ errorOcurred(); } /* Enable timer clock and reset it */ Chip_TIMER_Init(timer_sd[timerNumber].name); Chip_RGU_TriggerReset(timer_sd[timerNumber].RGU); while (Chip_RGU_InReset(timer_sd[timerNumber].RGU)) {} Chip_TIMER_Reset(timer_sd[timerNumber].name); /* Update the defalut function pointer name of the Compare match 0*/ timer_dd[timerNumber].timerCompareMatchFunctionPointer[TIMERCOMPAREMATCH0] = voidFunctionPointer; /* Initialize compare match with the specified ticks (number of counts needed to clear the match counter) */ Chip_TIMER_MatchEnableInt(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0); Chip_TIMER_SetMatch(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0, ticks); /* Makes Timer Match 0 period the timer period*/ Chip_TIMER_ResetOnMatchEnable(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0); /*Enable timer*/ Chip_TIMER_Enable(timer_sd[timerNumber].name); /* Enable timer interrupt */ NVIC_SetPriority(timer_sd[timerNumber].IRQn, MAX_SYSCALL_INTERRUPT_PRIORITY+1); NVIC_EnableIRQ(timer_sd[timerNumber].IRQn); NVIC_ClearPendingIRQ(timer_sd[timerNumber].IRQn); }
void InicTimers(void){ uint32_t timerFreq; //inicializo los timers para la maquina de estado Chip_TIMER_Init(LPC_TIMER2); //tomo la frecuencia del clok timerFreq = Chip_Clock_GetSystemClockRate(); //confinfiguro el timer 2 y el match 1 Chip_TIMER_Reset(LPC_TIMER2); Chip_TIMER_MatchEnableInt(LPC_TIMER2, 1); Chip_TIMER_SetMatch(LPC_TIMER2, 1, 250); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER2, 1); Chip_TIMER_Enable(LPC_TIMER2); //habilito interrupciones NVIC_ClearPendingIRQ(TIMER2_IRQn); NVIC_EnableIRQ(TIMER2_IRQn); }
/* * @Brief Enables a compare match in a timer * @param timerNumber: Timer number, 0 to 3 * @param compareMatchNumber: Compare match number, 1 to 3 * @param ticks: Number of ticks required to reach the compare match. * @param voidFunctionPointer: function to be executed when the compare match is reached * @return None * @note For the 'ticks' parameter, see function Timer_microsecondsToTicks */ void Timer_EnableCompareMatch(uint8_t timerNumber, uint8_t compareMatchNumber , uint32_t ticks, voidFunctionPointer_t voidFunctionPointer){ timer_dd[timerNumber].timerCompareMatchFunctionPointer[compareMatchNumber] = voidFunctionPointer; Chip_TIMER_MatchEnableInt(timer_sd[timerNumber].name, compareMatchNumber); Chip_TIMER_SetMatch(timer_sd[timerNumber].name, compareMatchNumber, ticks); }
void initialize_timer() { Chip_TIMER_Init(LPC_TIMER1); Chip_TIMER_Reset(LPC_TIMER1); Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1); Chip_TIMER_SetMatch(LPC_TIMER1, 1, 240000);//1200000 Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1); Chip_TIMER_Enable(LPC_TIMER1); NVIC_ClearPendingIRQ(TIMER1_IRQn); NVIC_EnableIRQ(TIMER1_IRQn); }
void call_init (void) { transmit_call = false; Chip_TIMER_Init (LPC_TIMER32_0); Chip_TIMER_Reset (LPC_TIMER32_0); Chip_TIMER_MatchEnableInt (LPC_TIMER32_0, 0); Chip_TIMER_PrescaleSet (LPC_TIMER32_0, Chip_Clock_GetSystemClockRate ()); Chip_TIMER_SetMatch (LPC_TIMER32_0, 0, CALL_INTERVAL_SEC); Chip_TIMER_ResetOnMatchEnable (LPC_TIMER32_0, 0); Chip_TIMER_Enable (LPC_TIMER32_0); NVIC_ClearPendingIRQ (TIMER_32_0_IRQn); NVIC_EnableIRQ (TIMER_32_0_IRQn); }
void Board_TIMER_EnableTimerAsTimer(uint8_t timerNum, uint32_t presc,uint32_t matchValue,bool flagOnce) { // always using match0 int8_t match=0; LPC_TIMER_T* t = getTimerFomIndex(timerNum); Chip_TIMER_PrescaleSet(t, presc); Chip_TIMER_SetMatch(t, match, matchValue); Chip_TIMER_MatchEnableInt(t, match); // enable int for match 0 if(flagOnce==1) { Board_TIMER_DisableTimer(timerNum); Board_TIMER_SetTimerCounter(timerNum,0); Chip_TIMER_ResetOnMatchDisable(t, match); // reset count on match0 } else { Chip_TIMER_ResetOnMatchEnable(t, match); // reset count on match0 } Chip_TIMER_Enable(t); }
void main (void) { SystemInit (); Chip_IOCON_PinMuxSet (LPC_IOCON, LED_STATUS_PIO, IOCON_MODE_INACT | IOCON_FUNC0); Chip_GPIO_SetPinDIROutput (LPC_GPIO, LED_STATUS_PORT, LED_STATUS_PIN); Chip_GPIO_SetPinState (LPC_GPIO, LED_STATUS_PORT, LED_STATUS_PIN, false); Chip_TIMER_Init (LPC_TIMER32_0); Chip_TIMER_Reset (LPC_TIMER32_0); Chip_TIMER_MatchEnableInt (LPC_TIMER32_0, 1); Chip_TIMER_SetMatch (LPC_TIMER32_0, 1, (Chip_Clock_GetSystemClockRate () / (1 * 32))); Chip_TIMER_ResetOnMatchEnable (LPC_TIMER32_0, 1); Chip_TIMER_Enable (LPC_TIMER32_0); /* Enable timer interrupt */ NVIC_ClearPendingIRQ (TIMER_32_0_IRQn); NVIC_EnableIRQ (TIMER_32_0_IRQn); while (1) { __WFI (); } }