uTask.c 4.2 KB

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