LedTask.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. static unsigned char sucRedLedFlash=0;
  14. static unsigned char sucRedLedSleep=0;
  15. static unsigned char sucBlueLedFlash=0;
  16. static 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. }
  36. /*******************************************************************
  37. *LedTask
  38. ********************************************************************
  39. __task void LedTask(void)
  40. {
  41. unsigned char RedLedCt=0;
  42. unsigned char RedLedMaxCt=0;
  43. unsigned char RedLedFlash2=0;
  44. unsigned char LastRedLedFlash=0xff;
  45. unsigned char LastRedLedSleep=0xff;
  46. unsigned char BlueLedCt=0;
  47. unsigned char BlueLedMaxCt=0;
  48. unsigned char BlueLedFlash2=0;
  49. unsigned char LastBlueLedFlash=0xff;
  50. unsigned char LastBlueLedSleep=0xff;
  51. //Obtain own system task identification number.
  52. idLedTask = os_tsk_self();
  53. SpeakerEnable();
  54. SetBeepByNoOS(888,100);
  55. SpeakerDisable();
  56. //Read Product param from flash
  57. ReadProductParaFromFlash();
  58. printf("\r\n%s_V%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion);
  59. printf("PSN:%lu\r\n",sutProductPara.PSN);
  60. //ADC Init
  61. ADCInit();
  62. SlwTrace(INF,"ADC Init...\r\n");
  63. //Led Init
  64. LedInit();
  65. SlwTrace(INF,"Led Init...\r\n");
  66. idMainTask=0;
  67. //create NetTask
  68. idNetTask = os_tsk_create_user(NetTask,3,&stkNetTask,sizeof(stkNetTask));
  69. //create MainTask
  70. idMainTask = os_tsk_create_user(MainTask,2,&stkMainTask,sizeof(stkMainTask));
  71. //LetTask loop begin
  72. os_itv_set (10);
  73. while(1)
  74. {
  75. Uart3RecvProcess();
  76. os_itv_wait ();//wait 10 tick
  77. //red led control
  78. if(sucRedLedFlash==0){ //长灭
  79. MODEM_LED1_LOW;
  80. }else if(sucRedLedSleep==0){//长亮
  81. MODEM_LED1_HIGH;
  82. }else{
  83. if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
  84. RedLedCt=0;
  85. BlueLedCt=0;
  86. LastRedLedFlash=sucRedLedFlash;
  87. LastRedLedSleep=sucRedLedSleep;
  88. RedLedFlash2=sucRedLedFlash*2;
  89. RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
  90. }
  91. if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
  92. //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
  93. if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
  94. else MODEM_LED1_LOW;
  95. }
  96. //blue led control
  97. if(sucBlueLedFlash==0){ //长灭
  98. MODEM_LED2_LOW;
  99. }else if(sucBlueLedSleep==0){//长亮
  100. MODEM_LED2_HIGH;
  101. }else{
  102. if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
  103. RedLedCt=0;
  104. BlueLedCt=0;
  105. LastBlueLedFlash=sucBlueLedFlash;
  106. LastBlueLedSleep=sucBlueLedSleep;
  107. BlueLedFlash2=sucBlueLedFlash*2;
  108. BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
  109. }
  110. if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
  111. //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
  112. if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
  113. else MODEM_LED2_LOW;
  114. }
  115. }
  116. }
  117. */
  118. /********************************************************************
  119. *LedProcess
  120. *Led控制,每10ms执行1次
  121. *********************************************************************/
  122. void LedProcess(unsigned char reset)
  123. {
  124. static unsigned int sucCt=0;
  125. static unsigned char RedLedCt=0;
  126. static unsigned char RedLedMaxCt=0;
  127. static unsigned char RedLedFlash2=0;
  128. static unsigned char LastRedLedFlash=0xff;
  129. static unsigned char LastRedLedSleep=0xff;
  130. static unsigned char BlueLedCt=0;
  131. static unsigned char BlueLedMaxCt=0;
  132. static unsigned char BlueLedFlash2=0;
  133. static unsigned char LastBlueLedFlash=0xff;
  134. static unsigned char LastBlueLedSleep=0xff;
  135. RunMake(THIS_FILE_ID);
  136. if(reset){
  137. sucCt=0;
  138. RedLedCt=0;
  139. RedLedMaxCt=0;
  140. RedLedFlash2=0;
  141. LastRedLedFlash=0xff;
  142. LastRedLedSleep=0xff;
  143. BlueLedCt=0;
  144. BlueLedMaxCt=0;
  145. BlueLedFlash2=0;
  146. LastBlueLedFlash=0xff;
  147. LastBlueLedSleep=0xff;
  148. MODEM_LED1_LOW;
  149. MODEM_LED2_LOW;
  150. return;
  151. }
  152. if(os_time_get() < sucCt) return;
  153. sucCt = os_time_get() + 15;//0.15秒执行一次
  154. //控制0.1S执行一次
  155. // if(++sucCt>9)sucCt=0;
  156. // else return;
  157. //red led control
  158. if(sucRedLedFlash==0){ //长灭
  159. MODEM_LED1_LOW;
  160. }else if(sucRedLedSleep==0){//长亮
  161. MODEM_LED1_HIGH;
  162. }else{
  163. if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
  164. RedLedCt=0;
  165. BlueLedCt=0;
  166. LastRedLedFlash=sucRedLedFlash;
  167. LastRedLedSleep=sucRedLedSleep;
  168. RedLedFlash2=sucRedLedFlash*2;
  169. RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
  170. }
  171. if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
  172. //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
  173. if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
  174. else MODEM_LED1_LOW;
  175. }
  176. //blue led control
  177. if(sucBlueLedFlash==0){ //长灭
  178. MODEM_LED2_LOW;
  179. }else if(sucBlueLedSleep==0){//长亮
  180. MODEM_LED2_HIGH;
  181. }else{
  182. if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
  183. RedLedCt=0;
  184. BlueLedCt=0;
  185. LastBlueLedFlash=sucBlueLedFlash;
  186. LastBlueLedSleep=sucBlueLedSleep;
  187. BlueLedFlash2=sucBlueLedFlash*2;
  188. BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
  189. }
  190. if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
  191. //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
  192. if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
  193. else MODEM_LED2_LOW;
  194. }
  195. RunMake(THIS_FILE_ID);
  196. }
  197. void SetRedLed(unsigned char flash,unsigned char sleep)
  198. {
  199. int t=(flash+sleep)*2;
  200. if(t>255){
  201. return;
  202. }
  203. sucRedLedFlash=flash;
  204. sucRedLedSleep=sleep;
  205. }
  206. void SetBlueLed(unsigned char flash,unsigned char sleep)
  207. {
  208. int t=(flash+sleep)*2;
  209. if(t>255){
  210. return;
  211. }
  212. sucBlueLedFlash=flash;
  213. sucBlueLedSleep=sleep;
  214. }
  215. /************************************************************
  216. *************************************************************/
  217. void SetLedStatus(LED_STATUS LedStatus)
  218. {
  219. switch(LedStatus){
  220. case NotBright: //均不亮
  221. SetRedLed(0,0);
  222. SetBlueLed(0,0);
  223. break;
  224. case RedBright: //红灯常亮
  225. SetRedLed(1,0);
  226. SetBlueLed(0,0);
  227. break;
  228. case RedFastFlash: //红灯快闪
  229. SetRedLed(1,1);
  230. SetBlueLed(0,0);
  231. break;
  232. case RedSlowFlash: //红灯慢闪
  233. SetRedLed(1,10);
  234. SetBlueLed(0,0);
  235. break;
  236. case BlueBright: //蓝灯常亮
  237. SetRedLed(0,0);
  238. SetBlueLed(1,0);
  239. break;
  240. case BlueFastFlash: //蓝灯快闪
  241. SetRedLed(0,0);
  242. SetBlueLed(1,1);
  243. break;
  244. case BlueSlowFlash: //蓝灯慢闪
  245. SetRedLed(0,0);
  246. SetBlueLed(1,10);
  247. break;
  248. case RedBlueBright: //红蓝常亮
  249. SetRedLed(1,0);
  250. SetBlueLed(1,0);
  251. break;
  252. case RedBlueFastFlash: //红蓝快闪
  253. SetRedLed(1,1);
  254. SetBlueLed(1,1);
  255. break;
  256. case RedBlueSlowFlash: //红蓝慢闪
  257. SetRedLed(1,10);
  258. SetBlueLed(1,10);
  259. break;
  260. }
  261. }
  262. void SetLedIndicator(LED_INDICATOR LedInd)
  263. {
  264. switch(LedInd){
  265. case IndModemErr:
  266. g_LedInd=IndModemErr;
  267. SetLedStatus(RedBright);
  268. break;
  269. case IndNoNet:
  270. g_LedInd=IndNoNet;
  271. SetLedStatus(BlueFastFlash);
  272. break;
  273. case IndStandby:
  274. g_LedInd=IndStandby;
  275. SetLedStatus(BlueSlowFlash);
  276. break;
  277. case IndRX:
  278. g_LedInd=IndRX;
  279. SetLedStatus(BlueBright);
  280. break;
  281. case IndTX:
  282. g_LedInd=IndTX;
  283. SetLedStatus(RedBright);
  284. break;
  285. }
  286. }
  287. /***********************************************************************************/