LedTask.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /**********************************************************************************
  2. * File Name: LedTask.c
  3. * Function Describe:The task for LED display
  4. * Relate Module:
  5. * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式
  6. * Writer: ShiLiangWen
  7. * Date: 2015.2.10
  8. **********************************************************************************/
  9. #define THIS_FILE_ID 12
  10. //--------------------------------------------------------------------------------
  11. #include "includes.h"
  12. OS_TID idLedTask;
  13. unsigned char sucRedLedFlash=0;
  14. unsigned char sucRedLedSleep=0;
  15. unsigned char sucBlueLedFlash=0;
  16. unsigned char sucBlueLedSleep=0;
  17. static LED_INDICATOR LedIndicator;
  18. LED_INDICATOR g_LedInd;
  19. void LedInit(void)
  20. {
  21. GPIO_InitTypeDef GPIO_InitStructure;
  22. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能
  23. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled
  24. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE);
  25. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  26. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  27. GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
  28. GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
  29. GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
  30. GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
  31. GPIO_InitStructure.GPIO_Pin = KEYBOARD_BACKLIGHT_PIN;
  32. GPIO_Init(KEYBOARD_BACKLIGHT_PORT, &GPIO_InitStructure);
  33. // MODEM_LED1_HIGH;
  34. // MODEM_LED2_HIGH;
  35. // SetLedIndicator(InStart);
  36. MODEM_LED1_LOW;
  37. MODEM_LED2_LOW;
  38. }
  39. /*******************************************************************
  40. *LedTask
  41. ********************************************************************
  42. __task void LedTask(void)
  43. {
  44. unsigned char RedLedCt=0;
  45. unsigned char RedLedMaxCt=0;
  46. unsigned char RedLedFlash2=0;
  47. unsigned char LastRedLedFlash=0xff;
  48. unsigned char LastRedLedSleep=0xff;
  49. unsigned char BlueLedCt=0;
  50. unsigned char BlueLedMaxCt=0;
  51. unsigned char BlueLedFlash2=0;
  52. unsigned char LastBlueLedFlash=0xff;
  53. unsigned char LastBlueLedSleep=0xff;
  54. //Obtain own system task identification number.
  55. idLedTask = os_tsk_self();
  56. SpeakerEnable();
  57. SetBeepByNoOS(888,100);
  58. SpeakerDisable();
  59. //Read Product param from flash
  60. ReadProductParaFromFlash();
  61. printf("\r\n%s_V%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion);
  62. printf("PSN:%lu\r\n",sutProductPara.PSN);
  63. //ADC Init
  64. ADCInit();
  65. SlwTrace(INF,"ADC Init...\r\n");
  66. //Led Init
  67. LedInit();
  68. SlwTrace(INF,"Led Init...\r\n");
  69. idMainTask=0;
  70. //create NetTask
  71. idNetTask = os_tsk_create_user(NetTask,3,&stkNetTask,sizeof(stkNetTask));
  72. //create MainTask
  73. idMainTask = os_tsk_create_user(MainTask,2,&stkMainTask,sizeof(stkMainTask));
  74. //LetTask loop begin
  75. os_itv_set (10);
  76. while(1)
  77. {
  78. Uart3RecvProcess();
  79. os_itv_wait ();//wait 10 tick
  80. //red led control
  81. if(sucRedLedFlash==0){ //长灭
  82. MODEM_LED1_LOW;
  83. }else if(sucRedLedSleep==0){//长亮
  84. MODEM_LED1_HIGH;
  85. }else{
  86. if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
  87. RedLedCt=0;
  88. BlueLedCt=0;
  89. LastRedLedFlash=sucRedLedFlash;
  90. LastRedLedSleep=sucRedLedSleep;
  91. RedLedFlash2=sucRedLedFlash*2;
  92. RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
  93. }
  94. if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
  95. //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
  96. if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
  97. else MODEM_LED1_LOW;
  98. }
  99. //blue led control
  100. if(sucBlueLedFlash==0){ //长灭
  101. MODEM_LED2_LOW;
  102. }else if(sucBlueLedSleep==0){//长亮
  103. MODEM_LED2_HIGH;
  104. }else{
  105. if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
  106. RedLedCt=0;
  107. BlueLedCt=0;
  108. LastBlueLedFlash=sucBlueLedFlash;
  109. LastBlueLedSleep=sucBlueLedSleep;
  110. BlueLedFlash2=sucBlueLedFlash*2;
  111. BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
  112. }
  113. if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
  114. //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
  115. if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
  116. else MODEM_LED2_LOW;
  117. }
  118. }
  119. }
  120. */
  121. /********************************************************************
  122. *LedProcess
  123. *Led控制,每10ms执行1次
  124. *********************************************************************/
  125. void LedProcess(unsigned char reset)
  126. {
  127. static unsigned int sucCt=0;
  128. static unsigned char RedLedCt=0;
  129. static unsigned char RedLedMaxCt=0;
  130. static unsigned char RedLedFlash2=0;
  131. static unsigned char LastRedLedFlash=0xff;
  132. static unsigned char LastRedLedSleep=0xff;
  133. static unsigned char BlueLedCt=0;
  134. static unsigned char BlueLedMaxCt=0;
  135. static unsigned char BlueLedFlash2=0;
  136. static unsigned char LastBlueLedFlash=0xff;
  137. static unsigned char LastBlueLedSleep=0xff;
  138. RunMake(THIS_FILE_ID);
  139. if(reset){
  140. sucCt=0;
  141. RedLedCt=0;
  142. RedLedMaxCt=0;
  143. RedLedFlash2=0;
  144. LastRedLedFlash=0xff;
  145. LastRedLedSleep=0xff;
  146. BlueLedCt=0;
  147. BlueLedMaxCt=0;
  148. BlueLedFlash2=0;
  149. LastBlueLedFlash=0xff;
  150. LastBlueLedSleep=0xff;
  151. MODEM_LED1_LOW;
  152. MODEM_LED2_LOW;
  153. return;
  154. }
  155. if(os_time_get() < sucCt) return;
  156. sucCt = os_time_get() + 15;//0.15秒执行一次
  157. //控制0.1S执行一次
  158. // if(++sucCt>9)sucCt=0;
  159. // else return;
  160. // SetRedLed(1,0); //红 常亮 flash sleep
  161. // SetBlueLed(0,0);
  162. // SetRedLed(0,0); 绿 常亮
  163. // SetBlueLed(1,0);
  164. //red led control
  165. if(sucRedLedFlash==0){ //长灭
  166. MODEM_LED1_LOW;
  167. }else if(sucRedLedSleep==0){//长亮
  168. MODEM_LED1_HIGH;
  169. }
  170. else{
  171. if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
  172. RedLedCt=0;
  173. BlueLedCt=0;
  174. LastRedLedFlash=sucRedLedFlash;
  175. LastRedLedSleep=sucRedLedSleep;
  176. RedLedFlash2=sucRedLedFlash*2;
  177. RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
  178. }
  179. if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
  180. //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
  181. if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
  182. else MODEM_LED1_LOW;
  183. }
  184. //blue led control
  185. if(sucBlueLedFlash==0){ //长灭
  186. MODEM_LED2_LOW;
  187. }else if(sucBlueLedSleep==0){//长亮
  188. MODEM_LED2_HIGH;
  189. }
  190. else{
  191. if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
  192. RedLedCt=0;
  193. BlueLedCt=0;
  194. LastBlueLedFlash=sucBlueLedFlash;
  195. LastBlueLedSleep=sucBlueLedSleep;
  196. BlueLedFlash2=sucBlueLedFlash*2;
  197. BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
  198. }
  199. if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
  200. //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
  201. if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
  202. else MODEM_LED2_LOW;
  203. }
  204. RunMake(THIS_FILE_ID);
  205. }
  206. void SetRedLed(unsigned char flash,unsigned char sleep)
  207. {
  208. int t=(flash+sleep)*2;
  209. if(t>255){
  210. return;
  211. }
  212. sucRedLedFlash=flash;
  213. sucRedLedSleep=sleep;
  214. }
  215. void SetBlueLed(unsigned char flash,unsigned char sleep)
  216. {
  217. int t=(flash+sleep)*2;
  218. if(t>255){
  219. return;
  220. }
  221. sucBlueLedFlash=flash;
  222. sucBlueLedSleep=sleep;
  223. }
  224. /************************************************************
  225. SetLedStatus(RedFastFlash);
  226. *************************************************************/
  227. void SetLedStatus(LED_STATUS LedStatus)
  228. {
  229. switch(LedStatus){
  230. case NotBright: //均不亮
  231. SetRedLed(0,0);
  232. SetBlueLed(0,0);
  233. break;
  234. case RedBright: //红灯常亮
  235. SetRedLed(1,0);
  236. SetBlueLed(0,0);
  237. break;
  238. case RedFastFlash: //红灯快闪
  239. SetRedLed(1,5);
  240. SetBlueLed(0,0);
  241. break;
  242. case RedSlowFlash: //红灯慢闪
  243. SetRedLed(1,10); // SetRedLed(unsigned char flash,unsigned char sleep)
  244. SetBlueLed(0,0);
  245. break;
  246. case BlueBright: //蓝灯常亮
  247. SetRedLed(0,0);
  248. SetBlueLed(1,0);
  249. break;
  250. case BlueFastFlash: //蓝灯快闪
  251. SetRedLed(0,0);
  252. SetBlueLed(1,1);
  253. break;
  254. case BlueSlowFlash: //蓝灯慢闪
  255. SetRedLed(0,0);
  256. SetBlueLed(1,12);
  257. break;
  258. case RedBlueBright: //红蓝常亮
  259. SetRedLed(1,0);
  260. SetBlueLed(1,0);
  261. break;
  262. case RedBlueFastFlash: //红蓝快闪
  263. SetRedLed(1,1);
  264. SetBlueLed(1,1);
  265. break;
  266. case RedBlueSlowFlash: //红蓝慢闪
  267. SetRedLed(1,10);
  268. SetBlueLed(1,10);
  269. break;
  270. }
  271. }
  272. void SetLedIndicator(LED_INDICATOR LedInd)
  273. {
  274. switch(LedInd){
  275. case IndModemErr:
  276. g_LedInd=IndModemErr;
  277. SetLedStatus(RedBright);
  278. break;
  279. case IndNoNet:
  280. g_LedInd=IndNoNet;
  281. SetLedStatus(BlueFastFlash);
  282. break;
  283. case IndStandby:
  284. g_LedInd=IndStandby;
  285. SetLedStatus(BlueSlowFlash);
  286. break;
  287. case IndRX:
  288. g_LedInd=IndRX;
  289. SetLedStatus(BlueBright);
  290. break;
  291. case IndTX:
  292. g_LedInd=IndTX;
  293. SetLedStatus(RedBright);
  294. break;
  295. case InStart:
  296. g_LedInd=InStart;
  297. SetLedStatus(BlueBright);
  298. break;
  299. case InVbatLow:
  300. g_LedInd=InVbatLow;
  301. SetLedStatus(RedFastFlash);
  302. break;
  303. }
  304. }
  305. /***********************************************************************************/
  306. void EnterGTProcess()
  307. {
  308. unsigned char i=0;
  309. //static unsigned int sucCt=0;
  310. Uart1RxEnable(1);
  311. for(i=0;i<6;i++) //5
  312. {
  313. SlwTrace(INF,"AT+POC=500\r\n",1);//
  314. os_dly_wait(50);
  315. IWDG_ReloadCounter();
  316. if(g_uGtTaskEn==1){
  317. UISetNextStatus(UIS_START_INFOSET);
  318. while(1){
  319. os_dly_wait(100);
  320. IWDG_ReloadCounter();
  321. }
  322. return;
  323. }
  324. }
  325. }