123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- /**********************************************************************************
- * 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;
- static unsigned char sucRedLedFlash=0;
- static unsigned char sucRedLedSleep=0;
- static unsigned char sucBlueLedFlash=0;
- static 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;
- }
- /*******************************************************************
- *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(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
- if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
- else MODEM_LED1_LOW;
- }
- //blue led control
- if(sucBlueLedFlash==0){ //长灭
- MODEM_LED2_LOW;
- }else if(sucBlueLedSleep==0){//长亮
- MODEM_LED2_HIGH;
- }else{
- if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
- RedLedCt=0;
- BlueLedCt=0;
- LastBlueLedFlash=sucBlueLedFlash;
- LastBlueLedSleep=sucBlueLedSleep;
- BlueLedFlash2=sucBlueLedFlash*2;
- BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
- }
- if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
- //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
- if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
- else MODEM_LED2_LOW;
- }
- }
- }
- */
- /********************************************************************
- *LedProcess
- *Led控制,每10ms执行1次
- *********************************************************************/
- void LedProcess(unsigned char reset)
- {
- static unsigned int sucCt=0;
-
- static unsigned char RedLedCt=0;
- static unsigned char RedLedMaxCt=0;
- static unsigned char RedLedFlash2=0;
- static unsigned char LastRedLedFlash=0xff;
- static unsigned char LastRedLedSleep=0xff;
- static unsigned char BlueLedCt=0;
- static unsigned char BlueLedMaxCt=0;
- static unsigned char BlueLedFlash2=0;
- static unsigned char LastBlueLedFlash=0xff;
- static unsigned char LastBlueLedSleep=0xff;
- RunMake(THIS_FILE_ID);
-
- if(reset){
- sucCt=0;
- RedLedCt=0;
- RedLedMaxCt=0;
- RedLedFlash2=0;
- LastRedLedFlash=0xff;
- LastRedLedSleep=0xff;
- BlueLedCt=0;
- BlueLedMaxCt=0;
- BlueLedFlash2=0;
- LastBlueLedFlash=0xff;
- LastBlueLedSleep=0xff;
- MODEM_LED1_LOW;
- MODEM_LED2_LOW;
- return;
- }
-
- if(os_time_get() < sucCt) return;
- sucCt = os_time_get() + 15;//0.15秒执行一次
- //控制0.1S执行一次
- // if(++sucCt>9)sucCt=0;
- // else return;
-
- //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(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
- if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
- else MODEM_LED1_LOW;
- }
- //blue led control
- if(sucBlueLedFlash==0){ //长灭
- MODEM_LED2_LOW;
- }else if(sucBlueLedSleep==0){//长亮
- MODEM_LED2_HIGH;
- }else{
- if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
- RedLedCt=0;
- BlueLedCt=0;
- LastBlueLedFlash=sucBlueLedFlash;
- LastBlueLedSleep=sucBlueLedSleep;
- BlueLedFlash2=sucBlueLedFlash*2;
- BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
- }
- if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
- //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
- if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
- else MODEM_LED2_LOW;
- }
- RunMake(THIS_FILE_ID);
- }
- void SetRedLed(unsigned char flash,unsigned char sleep)
- {
- int t=(flash+sleep)*2;
- if(t>255){
- 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;
- }
- /************************************************************
- *************************************************************/
- 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,1);
- SetBlueLed(0,0);
- break;
- case RedSlowFlash: //红灯慢闪
- SetRedLed(1,10);
- 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,10);
- 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;
- }
- }
- /***********************************************************************************/
|