/** * @brief RITimer IRQ handler and timebase management * @return Nothing * @note This function keeps a timebase for LWIP that can be * used for other functions. */ void OSEK_ISR_RIT_IRQHandler(void) { /* Clear RITimer Interrupt, Reload counter value */ Chip_RIT_ClearInt(LPC_RITIMER); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */ /* Increment tick count */ systick_timems += saved_period; }
/** * @brief Initialize tick interrupts * @return Nothing * @note This function initializes the tick interrupts, and must * be called before starting the freeRTOS scheduler. */ void prvSetupTimerInterrupt(void) { /* Clear any pending interrupt */ Chip_RIT_ClearInt(LPC_RITIMER); /* Calculate reload value */ reload_val = (configCPU_CLOCK_HZ / configTICK_RATE_HZ); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Start tick */ /* Set the priority and enable the interrupt */ NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, portNVIC_SYSTICK_PRI); NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn); }
/* Set timer interval value */ void Chip_RIT_SetTimerInterval_(LPC_RITIMER_T *pRITimer, uint32_t time_interval) { uint32_t cmp_value; /* Determine aapproximate compare value based on clock rate and passed interval */ cmp_value = ((Chip_Clock_GetRate(CLK_MX_RITIMER) / 1000) * time_interval )/ 1000; /* Set timer compare value */ Chip_RIT_SetCOMPVAL(pRITimer, cmp_value); /* Set timer enable clear bit to clear timer to 0 whenever counter value equals the contents of RICOMPVAL */ Chip_RIT_EnableCTRL(pRITimer, RIT_CTRL_ENCLR); }
/* Enable LWIP tick and interrupt */ void lwipSysTick_Enable(uint32_t period) { saved_period = period; /* Clear any pending interrupt */ Chip_RIT_ClearInt(LPC_RITIMER); /* Calculate reload value */ reload_val = ( SystemCoreClock / ( 1000 / period ) ); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Let it tick */ /* Set the priority and enable the interrupt */ NVIC_SetPriority((IRQn_Type) RITIMER_IRQn, RITIMER_IRQn_PRI); NVIC_EnableIRQ((IRQn_Type) RITIMER_IRQn); }
/** * @brief RITimer IRQ handler and timebase management * @return Nothing * @note This function keeps a timebase for LWIP that can be * used for other functions. */ void RIT_IRQHandler(void) { #define CONTEXT_ISR2 3 typedef uint8_t ContextType; extern ContextType ActualContext; ContextType ctx = ActualContext; ActualContext = CONTEXT_ISR2; /* Clear RITimer Interrupt, Reload counter value */ Chip_RIT_ClearInt(LPC_RITIMER); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */ /* Increment tick count */ systick_timems += saved_period; ActualContext = ctx; }
/** * @brief Tick interrupt handler routine * @return Nothing * @note This function handles the tick interrupts that are generated by RITIMER. */ void xPortSysTickHandler(void) { unsigned long ulDummy; /* TODO: check if WWDT interrupt and redirect */ Chip_RIT_ClearInt(LPC_RITIMER); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */ #if configUSE_PREEMPTION == 1 /* If using preemption, also force a context switch. */ *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; #endif ulDummy = portSET_INTERRUPT_MASK_FROM_ISR(); { vTaskIncrementTick(); } portCLEAR_INTERRUPT_MASK_FROM_ISR(ulDummy); }
/** \brief Set timer interval value in microseconds */ void Chip_RIT_SetTimerIntervaluS(LPC_RITIMER_T *pRITimer, uint32_t time_interval_us) { /** \details * This method is a copy of Chip_RIT_SetTimerInterval provided by vendor, in which * I made a minimal change to obtain a function that uses as parameter a number * in microseconds to interrupt with the RIT timer * * \param LPC_RITIMER_T *pRITimer: pointer to the RIT timer. * \param uint32_t time_interval_us: time interval in microseconds. * * \return nothing * */ uint32_t cmp_value; /* Determine approximate compare value based on clock rate and passed interval */ cmp_value = (Chip_Clock_GetRate(CLK_MX_RITIMER)/1000000) * time_interval_us; /* Set timer compare value */ Chip_RIT_SetCOMPVAL(pRITimer, cmp_value); /* Set timer enable clear bit to clear timer to 0 whenever counter value equals the contents of RICOMPVAL */ Chip_RIT_EnableCTRL(pRITimer, RIT_CTRL_ENCLR); }
/** * @brief Tick interrupt handler routine * @return Nothing * @note This function handles the tick interrupts that are generated by RITIMER. */ void RIT_IRQHandler(void) { unsigned long ulPreviousMask; /* TODO: check if WWDT interrupt and redirect */ Chip_RIT_ClearInt(LPC_RITIMER); Chip_RIT_SetCOMPVAL(LPC_RITIMER, Chip_RIT_GetCounter(LPC_RITIMER) + reload_val);/* Reload value */ #if configUSE_PREEMPTION == 1 /* If using preemption, also force a context switch. */ *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; #endif ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { /* Pend a context switch. */ *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET; } } portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); }