#include "uTask.h" #include "includes.h" pt_timer_t pt_timerPool; struct pt pt_TaskFast; struct pt pt_TaskSecond; struct pt pt_ModemATProcess; struct pt pt_ModemUartProcess; struct pt pt_ModemInitProcess; struct pt pt_LedTaskProcess; struct pt pt_socketProcess; struct pt pt_gpsProcess; struct pt pt_UIProcess; struct pt pt_UIAssistProcess; //快速执行的简单任务 PT_THREAD (ptFastTask(struct pt *pt)){ static timer_t ptTimer; PT_BEGIN(pt); //LC_RESUME(s) switch(s) { case 0: while(1){ //InfoTick(); if(modemInitStatus==1)HeadsetProcess(0); GTMode_Detected(); PowerOffProtetion(); CommHandler();//处理串口任务 KeyHandler();//按键任务 ModemLedCtl();//模块启动后LED逻辑控制任务 powerSaveHandle(); SetSpkLvProcess(0); //IncomingSMS(); PTTimerStart(&pt_timerPool, &ptTimer, 1); PT_WAIT_UNTIL(pt,PTTimerIsExpired(&ptTimer)); //LC_SET(s) s = __LINE__; // case __LINE__: // if(!(condition)){ \ //未到return; // return PT_WAITING; \ // } } PT_END(pt); } //1秒执行一次的简单任务 PT_THREAD (ptSecondTask(struct pt *pt)){ static timer_t ptTimer; PT_BEGIN(pt); while(1){ if(sutPocStatus.QuickGroupUserCt>0)sutPocStatus.QuickGroupUserCt--; Chargeing=GPIO_ReadInputDataBit(CHARGE_PORT,CHARGE_PIN); EncodeKeyProcess(); RTC_Update(); BatterProcess(); onStartCtl(); FingerDaemonfinger(); SMSHandle(); if(m_keyreturncnt>0)m_keyreturncnt--; if(m_keyreturncnt==0&&sutUIstatus.Status!=UIS_STANDBY) UISetNextStatus(UIS_STANDBY); PTTimerStart(&pt_timerPool, &ptTimer, 100); PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer)); } PT_END(pt); } PT_THREAD (ptModemATProTask(struct pt *pt)){ static timer_t ptTimer; PT_BEGIN(pt); while(1){ ModemATProcess(); PTTimerStart(&pt_timerPool, &ptTimer, 1); PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer)); } PT_END(pt); } //150ms执行一次LED任务 PT_THREAD (ptLedTask(struct pt *pt)){ static timer_t ptTimer; PT_BEGIN(pt); while(1){ LedProcess(0); PTTimerStart(&pt_timerPool, &ptTimer, 15); PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer)); } PT_END(pt); } void ptTimerTick(void){ PTTimerTick(&pt_timerPool);//SYStick } void ptAllInit(void){ PTTimerInitPool(&pt_timerPool); PT_INIT(&pt_TaskFast); PT_INIT(&pt_TaskSecond); PT_INIT(&pt_ModemATProcess); PT_INIT(&pt_ModemUartProcess); PT_INIT(&pt_ModemInitProcess); PT_INIT(&pt_LedTaskProcess); PT_INIT(&pt_socketProcess); PT_INIT(&pt_gpsProcess); PT_INIT(&pt_UIProcess); PT_INIT(&pt_UIAssistProcess); } void ptTaskRun(void){ while(1){ ptFastTask(&pt_TaskFast); ptSecondTask(&pt_TaskSecond); ptModemATProTask(&pt_ModemATProcess); ptModemUartTask(&pt_ModemUartProcess); ptModemInitTask(&pt_ModemInitProcess); ptLedTask(&pt_LedTaskProcess); ptSocketTask(&pt_socketProcess); ptGpsTask(&pt_gpsProcess); ptUITask(&pt_UIProcess); ptUIAssist(&pt_UIAssistProcess); } } //////////////////uTimer////////////////////// static unsigned int uSysTick=0;//以系统嘀嗒为单位 void uSysTickUpdate(void){uSysTick++;} unsigned int uSysTickGet(void){return uSysTick;} void uTimerStart(unsigned int *timerId, unsigned int dlyTime){ *timerId=uSysTickGet()+dlyTime; } char uTimerExpired(unsigned int *timerId){ return ((uSysTickGet()>*timerId)?1:0); } /* 硬延时 单位10倍ms级 */ void uTimerHardDly(short time_10ms){ unsigned int tick; tick=uSysTickGet()+time_10ms; while(uSysTickGet()= UTIMER_MAX) return; uTimer=&uTimerPara[type]; uTimer->tickStart=0; uTimer->tickTarget=timerms; uTimer->status=1; } void uTimerCall(void){ unsigned char i; UTIMER_CALL_DEF *uTimer; //char buf[15]; for(i=0;istatus != 0){ if(++uTimer->tickStart>=uTimer->tickTarget){ switch(i){ case UTIMER_BEEP: TIM_Cmd(TIM4, DISABLE); if(g_ucEnterGTNow)break; if(sutPocStatus.TTS==1)break; if(sutPocStatus.Speaker==0){ SpeakerDisable(); } break; case UTIMER_MIC:MicEnable();break; } uTimer->status=0; } } } }