// calculate the settings//#define REQUIRED_MS ((1000/TICK_RESOLUTION)) // the TICK frequency we require in kHz#if TICK_RESOLUTION > 4 #if TICK_RESOLUTION > 64 #define TICK_DIVIDE (((BUS_CLOCK/2/32768) + REQUIRED_MS/2)/REQUIRED_MS) // the divide ratio required (32k prescaler assumed) #define PIT_PRESCALE PIT_PRESCALE_32K #else #define TICK_DIVIDE (((BUS_CLOCK/2/4096) + REQUIRED_MS/2)/REQUIRED_MS) // the divide ratio required (4k prescaler assumed) #define PIT_PRESCALE PIT_PRESCALE_4K #endif#else #define TICK_DIVIDE (((BUS_CLOCK/2/1048) + REQUIRED_MS/2)/REQUIRED_MS) // the divide ratio required (1k prescaler assumed) #define PIT_PRESCALE PIT_PRESCALE_1K#endif// TICK uses PIT 0//extern void fnStartTick(void){ PIT_PCSR_0 = (PIT_PRESCALE | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD); // prepare for load PIT_PMR_0 = (TICK_DIVIDE - 1); // load interval value fnSetIntHandler(PIT0_VECTOR, (unsigned char *)_RealTimeInterrupt); IC_ICR_0_55 = TICK_INTERRUPT_PRIORITY; // define interrupt level and priority IC_IMRH_0 &= ~(PIT_0_PIF_INT_H); // unmask interrupt source IC_IMRL_0 &= ~(MASK_ALL_INT); // clear global mask PIT_PCSR_0 = (PIT_PRESCALE | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD | PIT_PIE | PIT_EN); // start PIT with interrupt enabled}static __interrupt__ void _RealTimeInterrupt(void){ PIT_PCSR_0 = (PIT_PRESCALE | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD | PIT_PIE | PIT_EN); // reset interrupt request flag fnRtmkSystemTick(); // operating system tick}