123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #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()<tick) IWDG_ReloadCounter();
- }
- ///////////////////替换原RTX中的os_tmr_call,os_tmr_create//////////////////
- //不能放在任务中扫描,因为速度不够,否则会出现声音连续起来了
- //要放在系统滴答中,但要尽量简练
- typedef struct{
- char status;
- unsigned short tickStart;
- unsigned short tickTarget;
- }UTIMER_CALL_DEF;
- UTIMER_CALL_DEF uTimerPara[UTIMER_MAX];
- void uTimerCreate(unsigned char type,int timerms){
- UTIMER_CALL_DEF *uTimer;
- if(type >= 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;i<UTIMER_MAX;i++){
- uTimer=&uTimerPara[i];
- if(uTimer->status != 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;
- }
- }
- }
- }
|