/********************************************************************************** * File Name: LedTask.c * Function Describe:The task for LED display * Relate Module: * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式 * Writer: ShiLiangWen * Date: 2015.2.10 **********************************************************************************/ #define THIS_FILE_ID 12 //-------------------------------------------------------------------------------- #include "includes.h" OS_TID idLedTask; unsigned char sucRedLedFlash=0; unsigned char sucRedLedSleep=0; unsigned char sucBlueLedFlash=0; unsigned char sucBlueLedSleep=0; static LED_INDICATOR LedIndicator; LED_INDICATOR g_LedInd; void LedInit(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN; GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN; GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = KEYBOARD_BACKLIGHT_PIN; GPIO_Init(KEYBOARD_BACKLIGHT_PORT, &GPIO_InitStructure); // MODEM_LED1_HIGH; // MODEM_LED2_HIGH; // SetLedIndicator(InStart); MODEM_LED1_LOW; MODEM_LED2_LOW; } /******************************************************************* *LedTask ******************************************************************** __task void LedTask(void) { unsigned char RedLedCt=0; unsigned char RedLedMaxCt=0; unsigned char RedLedFlash2=0; unsigned char LastRedLedFlash=0xff; unsigned char LastRedLedSleep=0xff; unsigned char BlueLedCt=0; unsigned char BlueLedMaxCt=0; unsigned char BlueLedFlash2=0; unsigned char LastBlueLedFlash=0xff; unsigned char LastBlueLedSleep=0xff; //Obtain own system task identification number. idLedTask = os_tsk_self(); SpeakerEnable(); SetBeepByNoOS(888,100); SpeakerDisable(); //Read Product param from flash ReadProductParaFromFlash(); printf("\r\n%s_V%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion); printf("PSN:%lu\r\n",sutProductPara.PSN); //ADC Init ADCInit(); SlwTrace(INF,"ADC Init...\r\n"); //Led Init LedInit(); SlwTrace(INF,"Led Init...\r\n"); idMainTask=0; //create NetTask idNetTask = os_tsk_create_user(NetTask,3,&stkNetTask,sizeof(stkNetTask)); //create MainTask idMainTask = os_tsk_create_user(MainTask,2,&stkMainTask,sizeof(stkMainTask)); //LetTask loop begin os_itv_set (10); while(1) { Uart3RecvProcess(); os_itv_wait ();//wait 10 tick //red led control if(sucRedLedFlash==0){ //长灭 MODEM_LED1_LOW; }else if(sucRedLedSleep==0){//长亮 MODEM_LED1_HIGH; }else{ if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){ RedLedCt=0; BlueLedCt=0; LastRedLedFlash=sucRedLedFlash; LastRedLedSleep=sucRedLedSleep; RedLedFlash2=sucRedLedFlash*2; RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2; } if(++RedLedCt>RedLedMaxCt)RedLedCt=0; //if(RedLedCtBlueLedMaxCt)BlueLedCt=0; //if(BlueLedCt9)sucCt=0; // else return; // SetRedLed(1,0); //红 常亮 flash sleep // SetBlueLed(0,0); // SetRedLed(0,0); 绿 常亮 // SetBlueLed(1,0); //red led control if(sucRedLedFlash==0){ //长灭 MODEM_LED1_LOW; }else if(sucRedLedSleep==0){//长亮 MODEM_LED1_HIGH; } else{ if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){ RedLedCt=0; BlueLedCt=0; LastRedLedFlash=sucRedLedFlash; LastRedLedSleep=sucRedLedSleep; RedLedFlash2=sucRedLedFlash*2; RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2; } if(++RedLedCt>RedLedMaxCt)RedLedCt=0; //if(RedLedCtBlueLedMaxCt)BlueLedCt=0; //if(BlueLedCt255){ return; } sucRedLedFlash=flash; sucRedLedSleep=sleep; } void SetBlueLed(unsigned char flash,unsigned char sleep) { int t=(flash+sleep)*2; if(t>255){ return; } sucBlueLedFlash=flash; sucBlueLedSleep=sleep; } /************************************************************ SetLedStatus(RedFastFlash); *************************************************************/ void SetLedStatus(LED_STATUS LedStatus) { switch(LedStatus){ case NotBright: //均不亮 SetRedLed(0,0); SetBlueLed(0,0); break; case RedBright: //红灯常亮 SetRedLed(1,0); SetBlueLed(0,0); break; case RedFastFlash: //红灯快闪 SetRedLed(1,5); SetBlueLed(0,0); break; case RedSlowFlash: //红灯慢闪 SetRedLed(1,10); // SetRedLed(unsigned char flash,unsigned char sleep) SetBlueLed(0,0); break; case BlueBright: //蓝灯常亮 SetRedLed(0,0); SetBlueLed(1,0); break; case BlueFastFlash: //蓝灯快闪 SetRedLed(0,0); SetBlueLed(1,1); break; case BlueSlowFlash: //蓝灯慢闪 SetRedLed(0,0); SetBlueLed(1,12); break; case RedBlueBright: //红蓝常亮 SetRedLed(1,0); SetBlueLed(1,0); break; case RedBlueFastFlash: //红蓝快闪 SetRedLed(1,1); SetBlueLed(1,1); break; case RedBlueSlowFlash: //红蓝慢闪 SetRedLed(1,10); SetBlueLed(1,10); break; } } void SetLedIndicator(LED_INDICATOR LedInd) { switch(LedInd){ case IndModemErr: g_LedInd=IndModemErr; SetLedStatus(RedBright); break; case IndNoNet: g_LedInd=IndNoNet; SetLedStatus(BlueFastFlash); break; case IndStandby: g_LedInd=IndStandby; SetLedStatus(BlueSlowFlash); break; case IndRX: g_LedInd=IndRX; SetLedStatus(BlueBright); break; case IndTX: g_LedInd=IndTX; SetLedStatus(RedBright); break; case InStart: g_LedInd=InStart; SetLedStatus(BlueBright); break; case InVbatLow: g_LedInd=InVbatLow; SetLedStatus(RedFastFlash); break; } } /***********************************************************************************/ void EnterGTProcess() { unsigned char i=0; //static unsigned int sucCt=0; Uart1RxEnable(1); for(i=0;i<6;i++) //5 { SlwTrace(INF,"AT+POC=500\r\n",1);// os_dly_wait(50); IWDG_ReloadCounter(); if(g_uGtTaskEn==1){ UISetNextStatus(UIS_START_INFOSET); while(1){ os_dly_wait(100); IWDG_ReloadCounter(); } return; } } }