void mTouchCapPhy_TickInit( void ) { TMR4 = 0; //If the Low power demo is not enabled #ifndef LOW_POWER_DEMO_ENABLE PR4 = TIMER_PERIOD; T4CON = TIMER_ON | TIMER_SOURCE_INTERNAL | GATED_TIME_DISABLED | TIMER_16BIT_MODE | TIMER4_PRESCALER; //If Low Power demo is enabled #else //If the Primary oscillator is switched to FRC for the Low Power Demo then load PR4 with //the period value which is calculated for FRC // The time period is selected such that the functions mTouchCapPhy_ReadCTMU() and mTouchCapPhy_AverageData() // should be executed within the time period //Clock_Switch_Enable_Flag -- this will indicate that clock is switched from Primary to FRC if(Clock_Switch_Enable_Flag) { PR4=TIMER_PERIOD_WITH_FRC; //Timer value when FRC is used for Timer4 interrupt; T4CON = TIMER_ON | TIMER_SOURCE_INTERNAL | GATED_TIME_DISABLED | TIMER_16BIT_MODE | TIMER4_PRESCALER; Timer4_Period_Clock_Switch_Flag =HIGH; //To indicate that the timer4 init for FRC clock is complete } //If the Primary Oscillator is used else { PR4 = TIMER_PERIOD; T4CON = TIMER_ON | TIMER_SOURCE_INTERNAL | GATED_TIME_DISABLED | TIMER_16BIT_MODE | TIMER4_PRESCALER; } #endif //end of #ifndef LOW_POWER_DEMO_ENABLE Set_ScanTimer_IF_Bit_State(DISABLE); //Clear flag Set_ScanTimer_IE_Bit_State(ENABLE); //Enable interrupt Set_ScanTimer_ON_Bit_State(ENABLE) ; //Run timer }
void __ISR(_TIMER_4_VECTOR, IPL1SOFT) mTouchCapTmr_Tmr4ISR(void) #endif { void (*ptr_fcn)(void); /* init local wiht the callback function ptr */ ptr_fcn = (void (*) ())T4CallBackISR; if (ptr_fcn != 0) { // call the callback isr (*ptr_fcn)(); } Set_ScanTimer_IF_Bit_State(DISABLE); //Clear interrupt flag if ( EmTouchDataReady == TRUE ) { Set_ScanTimer_IE_Bit_State(DISABLE); // Disable interrupt Set_ScanTimer_ON_Bit_State(DISABLE); // Stop timer 4 } }
/****************************************************************************** * Function: void InitTimer(void) * * PreCondition: None * * Input: unsigned int time * * Output: None * * Side Effects: None * * Overview: Set the period for timer 4 depending on input param time * * Note: Stops and restarts the timer when setting the new period *****************************************************************************/ void mTouchCapTmr_InitTimer4(void) { // set up the timer interrupt with a priority of 1 Set_ScanTimer_Priority(1); // interrupt subpriority is 0 Set_ScanTimer_Subpriority(0); // clear the interrupt flag Set_ScanTimer_IF_Bit_State(0); // initialize the callback pointer with the value passed as argument T4CallBackISR = TIMERCALLBACKFUNC; /* enable the interrupt */ Set_ScanTimer_IE_Bit_State(1); TMR4 = 0; PR4 = TIMER4_PERIOD; // restart the timer Set_ScanTimer_ON_Bit_State(1); return; }