| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- /**********************************************************************************
- * File Name: Led.c
- * Function Describe:The task for LED display
- * Relate Module:
- * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式
- * Date: 2019.2.25
-
- LED1 绿色 电源指示灯,MCU工作常亮
- LED2 红色 wifi指示灯
- LED3 蓝色 LAN指示灯
- LED4 stat绿色 指示与外部设备通讯状态,收到一包数据并解析成功,闪烁1次
-
-
- LED2 红色 wifi模式下工作指示灯
- wifi硬件故障,或非wifi模式下 常灭
- wifi连接服务器失败 单闪
- 已经正常连接 双闪 //收到一包数据
-
- LED3 蓝色 有线模式下工作指示灯
- 网络芯片硬件故障 ,或非有线模式, 常灭
- 未插网线或未分配内部IP 单闪
- 已正常连接 双闪
-
- **********************************************************************************/
- #define THIS_FILE_ID 9
- //--------------------------------------------------------------------------------
- #include "includes.h"
- static unsigned char sucRedLedFlash=0;
- static unsigned char sucRedLedSleep=0;
- static unsigned char sucBlueLedFlash=0;
- static unsigned char sucBlueLedSleep=0;
- static unsigned char sucLedFlash[3]={0,0,0};
- static unsigned char sucLedSleep[3]={0,0,0};
- void LedOn(int i);
- void LedOff(int i);
- void LedInit(void)
- {
- int i;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = WARN_LED1_PIN;
- GPIO_Init(WARN_LED1_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = WARN_LED2_PIN;
- GPIO_Init(WARN_LED2_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = WARN_LED3_PIN;
- GPIO_Init(WARN_LED3_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = WARN_BEEP_PIN;
- GPIO_Init(WARN_BEEP_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = MODEM_LED4_PIN;
- GPIO_Init(MODEM_LED4_PORT, &GPIO_InitStructure);
- for(i=0;i<4;i++) LedOff(i);
- FEED_EXTWATCHDOG();//喂狗
- IWDG_ReloadCounter();//喂狗
- for(i=0;i<4;i++){
- LedOn(i);
- os_dly_wait(80);
- FEED_EXTWATCHDOG();//喂狗
- IWDG_ReloadCounter();//喂狗
- }
-
- FEED_EXTWATCHDOG();//喂狗
- IWDG_ReloadCounter();//喂狗
- for(i=0;i<4;i++)LedOff(i);
- }
- void LedOn(int i)
- {
- if(i==0)WARN_LED1_HIGH;
- else if(i==1)WARN_LED2_HIGH;
- else if(i==2)WARN_LED3_HIGH;
- else MODEM_LED4_HIGH;
- }
- void LedOff(int i)
- {
- if(i==0)WARN_LED1_LOW;
- else if(i==1)WARN_LED2_LOW;
- else if(i==2)WARN_LED3_LOW;
- else MODEM_LED4_LOW;
- }
- void LedProcess(unsigned char reset)
- {
- int i;
- static unsigned char LedCt[3]={0,0,0};
- static unsigned char LedMaxCt[3]={0,0,0};
- static unsigned char LedFlash2[3]={0,0,0};
- static unsigned char LastLedFlash[3]={0,0,0};
- static unsigned char LastLedSleep[3]={0,0,0};
- static unsigned char sucCt=0;
- static unsigned char Uart1LedCt=0;
- if(reset){
- for(i=0;i<3;i++){
- LedCt[i]=0;
- LedMaxCt[i]=0;
- LedFlash2[i]=0;
- LastLedFlash[i]=0;
- LastLedSleep[i]=0;
- LedOff(i);
- }
- sucCt=0;
- Uart1LedCt=0;
- }
-
- //控制200ms执行一次
- if(++sucCt>20)sucCt=0;
- else return;
- //LED1~LED3
- for(i=0;i<3;i++){
- if(sucLedFlash[i]==0){ //长灭
- LedOff(i);
- }else if(sucLedSleep[i]==0){//长亮
- LedOn(i);
- }else{
- if(LastLedFlash[i]!=sucLedFlash[i] || LastLedSleep[i]!=sucLedSleep[i]){
- LedCt[i]=0;
- LastLedFlash[i]=sucLedFlash[i];
- LastLedSleep[i]=sucLedSleep[i];
- LedFlash2[i]=sucLedFlash[i]*2;
- LedMaxCt[i]=(LedFlash2[i]+LastLedSleep[i])*2;
- }
- if(++LedCt[i]>LedMaxCt[i])LedCt[i]=0;
- if(LedCt[i]<LedFlash2[i] && (LedCt[i]&0x01)==0x01)LedOn(i);
- else LedOff(i);
- }
- }
- //LED4 串口指示灯,来一包数据闪烁一下
- if(g_ucUart1Activated == 1){//串口1有数据来就闪灯
- g_ucUart1Activated=0;
- Uart1LedCt=0;
- MODEM_LED4_HIGH;
- }else if(++Uart1LedCt>0){//串口1无数据来就灭灯 //
- Uart1LedCt=0;
- MODEM_LED4_LOW;
- }
- }
- ///********************************************************************
- //SetLed
- //设置内部运行参数
- //*********************************************************************/
- void SetLed(unsigned char LedId,unsigned char flash,unsigned char sleep)
- {
- //合法性判断
- int t=(flash+sleep)*2;
- if(t>255){
- return;
- }
- if(LedId>2)return;
- //设置运行参数
- sucLedFlash[LedId]=flash;
- sucLedSleep[LedId]=sleep;
- }
- void SetLedStatus(unsigned char LedId,LED_STATUS LedStatus)
- {
- switch(LedStatus){
- case NotBright:
- SetLed(LedId,0,0); //常灭
- break;
- case Bright:
- SetLed(LedId,1,0); //常亮
- break;
- case Flash:
- SetLed(LedId,1,1);
- break;
- case OneFlashFast:
- SetLed(LedId,1,6);
- break;
- case TowFlashFast:
- SetLed(LedId,2,6);
- break;
- case ThreeFlashFast:
- SetLed(LedId,3,6);
- break;
- case OneFlashSlow:
- SetLed(LedId,1,20);
- break;
- case TowFlashSlow:
- SetLed(LedId,2,20);
- break;
- case ThreeFlashSlow:
- SetLed(LedId,3,20);
- break;
- }
- }
- //void SetLedIndicator(void)
- //{
- // if(sutTcpStatus.NetMode==1){//4G 模式
- // SetLedStatus(1,NotBright);//常灭
- // if(sutModemStatus.Power==CLOSED){
- // SetLedStatus(0,NotBright);//常灭
- // }else if(sutModemStatus.CardStatus!=OPENED){
- // SetLedStatus(0,Bright);//常亮
- // }else if(sutModemStatus.CREG!=OPENED){
- // SetLedStatus(0,Flash);//均匀闪烁
- // }else if(sutModemStatus.PPPStatus!=OPENED){
- // SetLedStatus(0,OneFlashFast);//1闪
- // }else if(sutTcpStatus.ServerStatus!=OPENED){
- // SetLedStatus(0,TowFlashFast);//2闪
- // }else{
- // SetLedStatus(0,ThreeFlashFast);//3闪
- // }
- // }else if(sutTcpStatus.NetMode==2){//LAN模式
- // SetLedStatus(0,NotBright);//常灭
- // if(sutWLanStatus.NetFlag==0){//网络芯片未完成初始化
- // SetLedStatus(1,NotBright);//常灭
- // }else if(sutWLanStatus.NetFlag==1){//网络IC初始化成功但网线未链接
- // SetLedStatus(1,Bright);//常亮
- // }else if(sutWLanStatus.NetFlag==2){//网线已插入但DHCP未分配IP
- // SetLedStatus(1,Flash);//均匀闪烁
- // }else if(sutWLanStatus.Connected==0){//DHCP已成功分配IP,但未连接服务器
- // SetLedStatus(1,OneFlashFast);//1闪
- // }else if(sutTcpStatus.ServerStatus!=OPENED){//已连接服务器但未成功登陆
- // SetLedStatus(1,TowFlashFast);//2闪
- // }else{//已成功登陆服务器
- // SetLedStatus(1,ThreeFlashFast);//3闪
- // }
- // }else{//无效模式
- // SetLedStatus(0,NotBright);//常灭
- // SetLedStatus(1,NotBright);//常灭
- // }
- //
- //}
- /***********************************************************************************/
|