uTask.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "uTask.h"
  2. #include "includes.h"
  3. pt_timer_t pt_timerPool;
  4. struct pt pt_TaskFast;
  5. struct pt pt_TaskSecond;
  6. struct pt pt_ModemATProcess;
  7. struct pt pt_ModemUartProcess;
  8. struct pt pt_ModemInitProcess;
  9. struct pt pt_LedTaskProcess;
  10. struct pt pt_socketProcess;
  11. struct pt pt_gpsProcess;
  12. struct pt pt_UIProcess;
  13. struct pt pt_UIAssistProcess;
  14. //快速执行的简单任务
  15. PT_THREAD (ptFastTask(struct pt *pt)){
  16. static timer_t ptTimer;
  17. PT_BEGIN(pt);
  18. //LC_RESUME(s) switch(s) { case 0:
  19. while(1){
  20. //InfoTick();
  21. if(modemInitStatus==1)HeadsetProcess(0);
  22. GTMode_Detected();
  23. PowerOffProtetion();
  24. CommHandler();//处理串口任务
  25. KeyHandler();//按键任务
  26. ModemLedCtl();//模块启动后LED逻辑控制任务
  27. powerSaveHandle();
  28. SetSpkLvProcess(0);
  29. //IncomingSMS();
  30. PTTimerStart(&pt_timerPool, &ptTimer, 1);
  31. PT_WAIT_UNTIL(pt,PTTimerIsExpired(&ptTimer));
  32. //LC_SET(s) s = __LINE__;
  33. // case __LINE__:
  34. // if(!(condition)){ \ //未到return;
  35. // return PT_WAITING; \
  36. // }
  37. }
  38. PT_END(pt);
  39. }
  40. //1秒执行一次的简单任务
  41. PT_THREAD (ptSecondTask(struct pt *pt)){
  42. static timer_t ptTimer;
  43. PT_BEGIN(pt);
  44. while(1){
  45. if(sutPocStatus.QuickGroupUserCt>0)sutPocStatus.QuickGroupUserCt--;
  46. Chargeing=GPIO_ReadInputDataBit(CHARGE_PORT,CHARGE_PIN);
  47. EncodeKeyProcess();
  48. RTC_Update();
  49. BatterProcess();
  50. onStartCtl();
  51. FingerDaemonfinger();
  52. SMSHandle();
  53. if(m_keyreturncnt>0)m_keyreturncnt--;
  54. if(m_keyreturncnt==0&&sutUIstatus.Status!=UIS_STANDBY) UISetNextStatus(UIS_STANDBY);
  55. PTTimerStart(&pt_timerPool, &ptTimer, 100);
  56. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  57. }
  58. PT_END(pt);
  59. }
  60. PT_THREAD (ptModemATProTask(struct pt *pt)){
  61. static timer_t ptTimer;
  62. PT_BEGIN(pt);
  63. while(1){
  64. ModemATProcess();
  65. PTTimerStart(&pt_timerPool, &ptTimer, 1);
  66. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  67. }
  68. PT_END(pt);
  69. }
  70. //150ms执行一次LED任务
  71. PT_THREAD (ptLedTask(struct pt *pt)){
  72. static timer_t ptTimer;
  73. PT_BEGIN(pt);
  74. while(1){
  75. LedProcess(0);
  76. PTTimerStart(&pt_timerPool, &ptTimer, 15);
  77. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  78. }
  79. PT_END(pt);
  80. }
  81. void ptTimerTick(void){
  82. PTTimerTick(&pt_timerPool);//SYStick
  83. }
  84. void ptAllInit(void){
  85. PTTimerInitPool(&pt_timerPool);
  86. PT_INIT(&pt_TaskFast);
  87. PT_INIT(&pt_TaskSecond);
  88. PT_INIT(&pt_ModemATProcess);
  89. PT_INIT(&pt_ModemUartProcess);
  90. PT_INIT(&pt_ModemInitProcess);
  91. PT_INIT(&pt_LedTaskProcess);
  92. PT_INIT(&pt_socketProcess);
  93. PT_INIT(&pt_gpsProcess);
  94. PT_INIT(&pt_UIProcess);
  95. PT_INIT(&pt_UIAssistProcess);
  96. }
  97. void ptTaskRun(void){
  98. while(1){
  99. ptFastTask(&pt_TaskFast);
  100. ptSecondTask(&pt_TaskSecond);
  101. ptModemATProTask(&pt_ModemATProcess);
  102. ptModemUartTask(&pt_ModemUartProcess);
  103. ptModemInitTask(&pt_ModemInitProcess);
  104. ptLedTask(&pt_LedTaskProcess);
  105. ptSocketTask(&pt_socketProcess);
  106. ptGpsTask(&pt_gpsProcess);
  107. ptUITask(&pt_UIProcess);
  108. ptUIAssist(&pt_UIAssistProcess);
  109. }
  110. }
  111. //////////////////uTimer//////////////////////
  112. static unsigned int uSysTick=0;//以系统嘀嗒为单位
  113. void uSysTickUpdate(void){uSysTick++;}
  114. unsigned int uSysTickGet(void){return uSysTick;}
  115. void uTimerStart(unsigned int *timerId, unsigned int dlyTime){
  116. *timerId=uSysTickGet()+dlyTime;
  117. }
  118. char uTimerExpired(unsigned int *timerId){
  119. return ((uSysTickGet()>*timerId)?1:0);
  120. }
  121. /*
  122. 硬延时
  123. 单位10倍ms级
  124. */
  125. void uTimerHardDly(short time_10ms){
  126. unsigned int tick;
  127. tick=uSysTickGet()+time_10ms;
  128. while(uSysTickGet()<tick) IWDG_ReloadCounter();
  129. }
  130. ///////////////////替换原RTX中的os_tmr_call,os_tmr_create//////////////////
  131. //不能放在任务中扫描,因为速度不够,否则会出现声音连续起来了
  132. //要放在系统滴答中,但要尽量简练
  133. typedef struct{
  134. char status;
  135. unsigned short tickStart;
  136. unsigned short tickTarget;
  137. }UTIMER_CALL_DEF;
  138. UTIMER_CALL_DEF uTimerPara[UTIMER_MAX];
  139. void uTimerCreate(unsigned char type,int timerms){
  140. UTIMER_CALL_DEF *uTimer;
  141. if(type >= UTIMER_MAX) return;
  142. uTimer=&uTimerPara[type];
  143. uTimer->tickStart=0;
  144. uTimer->tickTarget=timerms;
  145. uTimer->status=1;
  146. }
  147. void uTimerCall(void){
  148. unsigned char i;
  149. UTIMER_CALL_DEF *uTimer;
  150. //char buf[15];
  151. for(i=0;i<UTIMER_MAX;i++){
  152. uTimer=&uTimerPara[i];
  153. if(uTimer->status != 0){
  154. if(++uTimer->tickStart>=uTimer->tickTarget){
  155. switch(i){
  156. case UTIMER_BEEP:
  157. TIM_Cmd(TIM4, DISABLE);
  158. if(g_ucEnterGTNow)break;
  159. if(sutPocStatus.TTS==1)break;
  160. if(sutPocStatus.Speaker==0){
  161. SpeakerDisable();
  162. }
  163. break;
  164. case UTIMER_MIC:MicEnable();break;
  165. }
  166. uTimer->status=0;
  167. }
  168. }
  169. }
  170. }