Explorar o código

新增:文件记录打印,LED显示网络状态,修改睡眠唤醒时间

CHENJIE-PC\QiXiang_CHENJIE %!s(int64=4) %!d(string=hai) anos
pai
achega
a2c30b6d7b
Modificáronse 3 ficheiros con 246 adicións e 7 borrados
  1. 55 6
      src/app.c
  2. 9 1
      src/bsp_custom.c
  3. 182 0
      src/hal_module_adapter.c

+ 55 - 6
src/app.c

@@ -134,6 +134,11 @@ static StaticTask_t             gProcess_Can_Task_t;
 static UINT8                  gProcess_Can_TaskStack[PROC_CAN_TASK_STACK_SIZE];
 static StaticTask_t             gProcess_Tcp_Task_t;
 static UINT8                  gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
+
+
+#ifdef BL_FILE_LOG
+uint8_t lockoutState=0;
+#endif
 //睡眠进出函数
 static void appBeforeHib(void *pdata, slpManLpState state)
 {
@@ -194,7 +199,7 @@ static void Main_Task(void* arg)
     int32_t inParam = 0xAABBCCDD;
     uint32_t Chrgend_Work_time = 180000;
     uint32_t Wakeup_Work_time = 120*100;
-    uint32_t Sleep_Time = 120*1000;
+    uint32_t Sleep_Time = 300*1000;
     //上述参数应写入文件里
     slpManWakeSrc_e Wakeup_source;
     PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
@@ -220,11 +225,17 @@ static void Main_Task(void* arg)
     slpManSlpState_t slpstate = slpManGetLastSlpState();
 
     #ifdef USING_PRINTF
-            printf("slpstate:%d \n",slpstate);
+        printf("slpstate:%d \n",slpstate);
+    #endif
+    #ifdef BL_FILE_LOG
+	    bluejoy_printf(BL_LEVEL3,"slpstate:%d \n",slpstate);
     #endif
     Wakeup_source =  slpManGetWakeupSrc();//获取唤醒源
     #ifdef USING_PRINTF
-            printf("Wakeup_source:%d \n",Wakeup_source);
+        printf("Wakeup_source:%d \n",Wakeup_source);
+    #endif
+    #ifdef BL_FILE_LOG
+	    bluejoy_printf(BL_LEVEL3,"Wakeup_source:%d \n",Wakeup_source);
     #endif
     if (Wakeup_source==0)
     {
@@ -268,7 +279,6 @@ static void Main_Task(void* arg)
             }
             case PROCESS_STATE_WORK:
             {
-                NetSocDisplay(LED_SOC_0,LED_TURN_ON);
                 osDelay(10/portTICK_PERIOD_MS);
                 Can_index++;
                 Uart_index++;
@@ -283,7 +293,7 @@ static void Main_Task(void* arg)
                     PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_RECV);
                     Can_index = 0;
                 }
-                if (Tcp_index >=500)//Tcp 5s 调用一次
+                if (Tcp_index >=1000)//Tcp 5s 调用一次
                 {
                     PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_LINK);
                     Tcp_index = 0;
@@ -345,6 +355,9 @@ static void Main_Task(void* arg)
                 #ifdef USING_PRINTF
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
+                #ifdef BL_FILE_LOG
+	                bluejoy_printf(BL_LEVEL3,"which slpstate can go now :%d \n",slpstate);
+                #endif
                 slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
                 while(1)
                 {
@@ -546,7 +559,6 @@ static void Uart_Task(void* arg)
                 #ifdef USING_PRINTF
                         printf("UART_STATE_WORK!\n");
                 #endif
-                NetSocDisplay(LED_SOC_1,LED_TURN_ON);
                 Uart_task = false;
                 Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
                 while(!Uart_task)
@@ -974,6 +986,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             #ifdef USING_PRINTF
                 printf("SIM ready(imsi=%s)\n",(UINT8 *)imsi->contents);
             #endif
+            #ifdef BL_FILE_LOG
+	            bluejoy_printf(BL_LEVEL3,"SIM ready(imsi=%s)\n",(UINT8 *)imsi->contents);
+            #endif
             break;
         }
         case NB_URC_ID_MM_SIGQ:
@@ -982,6 +997,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             #ifdef USING_PRINTF
                 printf("RSSI signal=%d\n",rssi);
             #endif
+            #ifdef BL_FILE_LOG
+	            bluejoy_printf(BL_LEVEL3,"RSSI signal=%d\n",rssi);
+            #endif
             ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_1, P_INFO, 1, "RSSI signal=%d", rssi);
             break;
         }
@@ -990,6 +1008,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             #ifdef USING_PRINTF
                 printf("Default bearer activated\n");
             #endif
+            #ifdef BL_FILE_LOG
+	            bluejoy_printf(BL_LEVEL3,"Default bearer activated\n");
+            #endif
             break;
         }
         case NB_URC_ID_PS_BEARER_DEACTED:
@@ -997,6 +1018,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             #ifdef USING_PRINTF
                 printf("Default bearer Deactivated\n");
             #endif
+            #ifdef BL_FILE_LOG
+	            bluejoy_printf(BL_LEVEL3,"Default bearer Deactivated\n");
+            #endif
             break;
         }
         case NB_URC_ID_PS_CEREG_CHANGED:
@@ -1006,6 +1030,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             #ifdef USING_PRINTF
                 printf("URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
             #endif
+            #ifdef BL_FILE_LOG
+	            bluejoy_printf(BL_LEVEL3,"URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
+            #endif
             break;
         }
         case NB_URC_ID_PS_NETINFO:
@@ -1013,6 +1040,9 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
             netif = (NmAtiNetifInfo *)param;
             if (netif->netStatus == NM_NETIF_ACTIVATED)
                 //sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
+                #ifdef BL_FILE_LOG
+	                bluejoy_printf(BL_LEVEL3,"QMSG_ID_NW_IP_READY\n");
+                #endif
                 Tcp_statuts = 1;
             break;
         }
@@ -1172,6 +1202,12 @@ static void Tcp_Task(void* arg)
     {
         Tcp_statuts = 1;
     }
+    #ifdef BL_FILE_LOG
+        if(lockoutState)
+            bluejoy_del_logfile();
+        bluejoy_read_logfile();
+        bluejoy_printf(BL_LEVEL3,"processAppTask\r\n");
+	#endif
     appSetCFUN(1);
     while(true)
     {
@@ -1179,6 +1215,8 @@ static void Tcp_Task(void* arg)
         {
             case PROCESS_TCP_STATE_IDLE:
             {
+                NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+                NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
                 osDelay(100);
                 break;
             }
@@ -1233,6 +1271,7 @@ static void Tcp_Task(void* arg)
                                 Tcp_statuts=2;
                                 PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
                                 Reconnect_Num++;
+                                NetSocDisplay(LED_SOC_0,LED_TURN_ON);
                             }
                             else
                             {
@@ -1241,6 +1280,9 @@ static void Tcp_Task(void* arg)
                             }
                             if(Reconnect_Num>=20)
                             {
+                                #ifdef BL_FILE_LOG
+	                                bluejoy_printf(BL_LEVEL3,"Connect failed!%d,Reconnect:%d\n",TcpconnectID,Reconnect_Num));
+                                #endif
                                 appSetCFUN(0);
                                 osDelay(10);
                                 appSetCFUN(1);
@@ -1362,6 +1404,9 @@ static void Tcp_Task(void* arg)
                             free(TcpSendBuffer);
                             if (TcpsendID<0)
                             {
+                                #ifdef BL_FILE_LOG
+	                                bluejoy_printf(BL_LEVEL3,"ConnectID:%d,TcpSend:%d,data length:%d\n",sockfd,TcpsendID,NB_send_len);
+                                #endif
                                 closesocket(sockfd);
                                 TcpconnectID = -1;
                                 Tcp_Index=-1;
@@ -1369,7 +1414,11 @@ static void Tcp_Task(void* arg)
                             }
                             else
                             {
+                                NetSocDisplay(LED_SOC_1,LED_TURN_ON);
                                 Tcp_Index=3;
+                                #ifdef BL_FILE_LOG
+	                                bluejoy_printf(BL_LEVEL3,"ConnectID:%d,TcpSend:%d,data length:%d\n",sockfd,TcpsendID,NB_send_len);
+                                #endif
                             }
                             break;
                         }

+ 9 - 1
src/bsp_custom.c

@@ -13,7 +13,9 @@
 #include "slpman_ec616.h"
 #include "plat_config.h"
 #include "debug_log.h"
-
+#ifdef BL_FILE_LOG
+extern uint8_t lockoutState;
+#endif
 void GPR_SetUartClk(void)
 {
     GPR_ClockDisable(GPR_UART0FuncClk);
@@ -96,10 +98,16 @@ void CheckLockOutState(void){
 	if((slpManGetWakeupPinValue() & (0x1<<2)) == 0){
 		#ifdef USING_PRINTF
 			printf("LOCK_OUT DOWN\r\n");
+		#endif
+        #ifdef BL_FILE_LOG
+			 lockoutState=1;
 		#endif	
 	}else{
 		#ifdef USING_PRINTF
 			printf("LOCK_OUT UP\r\n",__LINE__);
+		#endif
+        #ifdef BL_FILE_LOG
+			 lockoutState=0;
 		#endif	
 	}
 }

+ 182 - 0
src/hal_module_adapter.c

@@ -191,6 +191,188 @@ led_pin_config_t gLedCfg[LED_INX_MAX]={{LED_PORT_0,LED_GPIO_PIN_1,LED_PAD_INDEX1
 									 {LED_PORT_0,LED_GPIO_PIN_4,LED_PAD_INDEX4, PAD_MuxAlt0},\
 								       {LED_PORT_1,LED_GPIO_PIN_5,LED_PAD_INDEX5, PAD_MuxAlt0}};
 
+#ifdef BL_FILE_LOG
+#include <stdarg.h>
+static UINT8 blLogFileNux=0;
+
+//UTCת��Ϊ����ʱ��  ������ֱ�ӵ���
+static void UTCToBeijing(unsigned char * bjttbuf,unsigned int UTCyear,unsigned char UTCmonth,unsigned char UTCday,unsigned int UTChour,unsigned char UTCminute,unsigned char UTCsecond)
+{
+	int year=0,month=0,day=0,hour=0;
+    int lastday = 0;// �µ����һ������
+    int lastlastday = 0;//���µ����һ������
+	
+	  year=UTCyear;
+		month=UTCmonth;
+	  day=UTCday;
+	  hour=UTChour+8;//UTC+8ת��Ϊ����ʱ��
+	
+	  if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
+		{
+        lastday = 31;
+        if(month == 3)
+				{
+            if((year%400 == 0)||(year%4 == 0 && year%100 != 0))//�ж��Ƿ�Ϊ����
+                lastlastday = 29;//�����2��Ϊ29�죬ƽ��Ϊ28��
+            else
+                lastlastday = 28;
+        }
+        if(month == 8)
+            lastlastday = 31;
+    }
+    else 
+		if(month == 4 || month == 6 || month == 9 || month == 11)
+		{
+        lastday = 30;
+        lastlastday = 31;
+    }
+    else
+		{
+        lastlastday = 31;
+        if((year%400 == 0)||(year%4 == 0 && year%100 != 0))//�����2��Ϊ29�죬ƽ��Ϊ28��
+            lastday = 29;
+        else
+            lastday = 28;
+    }
+		if(hour >= 24)//�������ʱ���ڻ����24��00ʱ��Ӧ��ȥ24��00�����ڼ�һ��
+		{
+				hour -= 24;
+				day += 1; 
+				if(day > lastday)//����������ڴ��ڸ������һ��ʱ��Ӧ��ȥ�������һ������ڣ��·ݼ���һ����
+				{ 
+						day -= lastday;
+						month += 1;
+
+						if(month > 12)//��������·ݴ���12��Ӧ��ȥ12����ݼ���1��
+						{
+								month -= 12;
+								year += 1;
+						}
+				}
+		}
+		
+		sprintf((char *)bjttbuf,"%04d-%02d-%02d %02d:%02d:%02d ",
+							year,month,day,hour,UTCminute,UTCsecond);	//UTC����ʱ����ת���ɱ���ʱ��
+}
+
+static void bluejoy_write_logfile(UINT8 * buf)
+{
+	int32_t err;
+	UINT32 Count;
+	OSAFILE file;
+	while(blLogFileNux){
+		 osDelay(10/portTICK_PERIOD_MS);
+	}
+	blLogFileNux=1;
+	file = OsaFopen("blLog","wb");
+	if(file==NULL){
+		//printf("blLog open fail!\r\n");
+		blLogFileNux=0;
+		return;
+	}
+	if(OsaFseek(file, 0, SEEK_END) != 0)
+	{
+	    //printf("Seek file failed [%d] \r\n",__LINE__);
+	    OsaFclose(file);
+	    blLogFileNux=0;
+	    return;
+	}
+	Count = OsaFwrite(buf, 1, strlen(buf), file);
+	if(Count != (strlen(buf))){
+		//printf("blLog write fail!\r\n");
+
+	}
+	OsaFclose(file);
+	blLogFileNux=0;
+}
+
+void bluejoy_read_logfile(void)
+{
+	int32_t err;
+	UINT32 Count;
+	OSAFILE file;
+	UINT8 rbuf[128+1]={0};
+	UINT8 * flag_p;
+	UINT16 pri_l; 
+	
+	printf("%s start\r\n",__FUNCTION__);
+	while(blLogFileNux){
+		 osDelay(10/portTICK_PERIOD_MS);
+	}
+	blLogFileNux=1;
+	file = OsaFopen("blLog","rb");
+	if(file==NULL){
+		printf("blLog not exst!\r\n");
+		blLogFileNux=0;
+		return;
+	}
+	
+	if(OsaFseek(file, 0, SEEK_SET) != 0)
+	{
+	    printf("Seek file failed [%d] \r\n",__LINE__);
+	    OsaFclose(file);
+	    blLogFileNux=0;
+	    return;
+	}
+		
+	do{	
+		memset(rbuf,0,128);
+		Count = OsaFread(rbuf, 1, 128, file);
+		printf("%s",rbuf);
+				
+	}while(Count==128);
+	
+	OsaFclose(file);
+	blLogFileNux=0;
+	printf("%s end! \r\n",__FUNCTION__);
+}
+
+void bluejoy_del_logfile(void)
+{
+	UINT32 ret;
+	//printf("%s start! \r\n",__FUNCTION__);
+	while(blLogFileNux){
+		 osDelay(10/portTICK_PERIOD_MS);
+	}
+	blLogFileNux=1;
+	OsaFremove("blLog");
+	blLogFileNux=0;
+	FaultDisplay(LED_TURN_OFF);
+	 osDelay(1000/portTICK_PERIOD_MS);
+	FaultDisplay(LED_TURN_ON);
+	 osDelay(1000/portTICK_PERIOD_MS);
+	FaultDisplay(LED_TURN_OFF);
+	 osDelay(1000/portTICK_PERIOD_MS);
+	FaultDisplay(LED_TURN_ON);
+}
+
+
+void bluejoy_printf(BlLogLevel level, const UINT8 *format, ...)
+ {
+	UINT8 buf[128+1];
+	va_list args;
+	OsaUtcTimeTValue    timeUtc;
+	UINT16 year;
+	UINT8 month,day,hour,minite,sec;
+	if(level<BL_LEVEL2)
+		return;
+	appGetSystemTimeUtcSync(&timeUtc);
+	year=(timeUtc.UTCtimer1&0xffff0000)>>16;
+	month=(timeUtc.UTCtimer1&0xff00)>>8;
+	day=timeUtc.UTCtimer1&0xff;
+	hour=(timeUtc.UTCtimer2&0xff000000)>>24;
+	minite=(timeUtc.UTCtimer2&0xff0000)>>16;
+	sec=(timeUtc.UTCtimer2&0xff00)>>8;
+	memset(buf,0,128+1);
+	UTCToBeijing(buf,year,month,day,hour,minite,sec);
+	va_start(args, format);
+	vsnprintf(buf+strlen(buf), 128-strlen(buf), format, args);
+	va_end(args);
+	//printf("%s", buf);
+	bluejoy_write_logfile(buf);
+}
+#endif
+
 #if 0
 /**
   \fn        void NetSocDisplay(UINT8 soc)