/*FUNCTION*------------------------------------------------------------- * * Function Name : Custom_Delay * PARAMS : Delay in msec * * Returned Value : none * Comments : * Starts a timer for specified number of msec, puts EFM in EM2 mode. * EFM will wake up when timer fires. * *END*-----------------------------------------------------------------*/ void Custom_Delay(A_UINT32 delay) { #if MQX_VERSION == (402) /* Install the timer */ if (MQX_OK != _lpt_install (0, delay*1000 , LPT_FLAG_CLOCK_SOURCE_LPO, 2, timer_wakeup_isr, TRUE)) { printf ("\nError during installation of timer interrupt!\n"); _task_block(); } /* Stop the timer */ _lpt_run (0, FALSE); /* start timer */ _lpt_run (CUSTOM_DELAY_TMR, TRUE); #else if (MQX_OK != hwtimer_init(&hwtimer2, &BSP_HWTIMER2_DEV, BSP_HWTIMER2_ID, (BSP_DEFAULT_MQX_HARDWARE_INTERRUPT_LEVEL_MAX + 1))) { printf ("\nError during installation of timer interrupt!\n"); _task_block(); } hwtimer_set_period(&hwtimer2, BSP_HWTIMER2_SOURCE_CLK, delay*1000); hwtimer_callback_reg(&hwtimer2,(HWTIMER_CALLBACK_FPTR)timer_wakeup_isr, NULL); /* Start hwtimer2*/ hwtimer_start(&hwtimer2); #endif /* Setting operation mode to LPM_OPERATION_MODE_SLEEP */ _lpm_set_operation_mode (LPM_OPERATION_MODE_STOP); /* Return to RUN mode */ _lpm_set_operation_mode (LPM_OPERATION_MODE_RUN); if (CM_ERR_OK != _lpm_set_clock_configuration(BSP_CLOCK_CONFIGURATION_DEFAULT)) { printf("Cannot change clock configuration"); _task_block(); } }
/******************************************************************************* ** Function Name :timser_isr ** Input :device num of timer ** Return :void ** Author :wk ** Version :v1.0 ** Date :130330 ** Dessription :LPT 定时器0中断函数入口 ** Reverse : *******************************************************************************/ static void timer_isr ( pointer parameter ) { uint_32 timer = (uint_32)parameter; /* Stop the timer */ _lpt_run (timer, FALSE); _lpt_clear_int (timer); // printf("\nhellow\n"); SavePowerFlg =1; // EventKeyFlg=1; SPIEventFlg=1;// wk @130401 --> test event data save _lpt_init(0,3 * 1000000 , LPT_FLAG_CLOCK_SOURCE_LPO,TRUE); }
static void timer_wakeup_isr(pointer parameter) { uint_32 timer = (uint_32)parameter; /* Stop the timer */ #if MQX_VERSION == (402) _lpt_run (timer, FALSE); _lpt_clear_int (timer); #else hwtimer_stop(&hwtimer2); hwtimer_deinit(&hwtimer2); #endif /* Do not return to sleep after isr again */ _lpm_wakeup_core (); }