uTask.c 4.0 KB

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