Sfoglia il codice sorgente

Fix: 修复GPS自动调整波特率造成内核句柄耗尽问题

juni 7 mesi fa
parent
commit
e07c224d78

+ 1 - 1
app_public/fuxi_public/fuxi_bsp/source/dido.c

@@ -397,7 +397,7 @@ void dido_qd_set_keeptime(u32 us)
 void dido_di_poll(SHM_SAMPLE_T *sample_data)
 {
 	u32 di,di_num,slot;
-	u32 us0;
+	u64 us0;
 
 	// 如果交流延时失电信号有,闭锁遥信
 	if(pRunSet->dSDYX_T && g_run_stu.dcjlsd_t)

+ 38 - 12
app_public/fuxi_public/fuxi_bsp/source/uart.c

@@ -25,7 +25,22 @@
 #define UART_MAX_FD	256 //noted by sunxi: 因为传进来的UART_CHANNEL[i]不一定是连续的。
 
 //static int am335x_uarts_fd[CFG_UART_NUM_MAX];
-static int am335x_uarts_fd[UART_MAX_FD];
+static int am335x_uarts_fd[UART_MAX_FD] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+											-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,};
 
 
 static void am335x_uarts_init(int channel)
@@ -232,16 +247,19 @@ int uart_open(int channel, uint32_t baudRate, int setting)
 		return -1;
 	}
 
-	am335x_uarts_init(channel);
-	memset(tty_name,0,sizeof(tty_name));
-	sprintf(tty_name, "/dev/ttyAS%d", channel);	//sprintf(tty_name, "/dev/ttyO%d", channel); by ygl 2025.6.13
-	am335x_uarts_fd[channel] = open(tty_name, O_RDWR, 0);
-	if(am335x_uarts_fd[channel] < 0)
+	if (am335x_uarts_fd[channel] < 0)
 	{
-		printf("open %s failed!\n", tty_name);
-		return am335x_uarts_fd[channel];
-	}
-
+		am335x_uarts_init(channel);
+		memset(tty_name,0,sizeof(tty_name));
+		sprintf(tty_name, "/dev/ttyAS%d", channel);	//sprintf(tty_name, "/dev/ttyO%d", channel); by ygl 2025.6.13
+		am335x_uarts_fd[channel] = open(tty_name, O_RDWR, 0);
+		if(am335x_uarts_fd[channel] < 0)
+		{
+			printf("inside open %s failed!\n", tty_name);
+			return am335x_uarts_fd[channel];
+		}
+	} 
+	
 	switch(setting)
 	{
 		case PARITY_EVEN://偶校验
@@ -379,7 +397,7 @@ void uart_putchar2 (int channel, char ch)
 
 int uart_init(void)
 {
-	int i;
+	int i, ret;
 
 	for(i = 0; i < CFG_UART_NUM_MAX; i++)
 	{
@@ -388,7 +406,15 @@ int uart_init(void)
 			continue;
 		}
 
-		uart_open(i,115200,PARITY_NONE);
+		ret = uart_open(i,115200,PARITY_NONE);
+		if (ret < 0)
+		{
+			printf("%s: outside uart %d open failed!\n", __FUNCTION__, i);
+		}
+		else
+		{
+			printf("%s: outside uart %d open success!\n", __FUNCTION__, i);
+		}
 	}
 
 	return 0;

+ 2 - 2
app_public/fuxi_public/rt_lite/source/rt_socket.c

@@ -666,7 +666,7 @@ int rt_if_ip_get(int index, unsigned char *ip)
 	sock = rt_socket(AF_INET, SOCK_DGRAM, 0);
 	if (sock == RT_SOCKET_ERR)
 	{
-		rt_printf("rt_if_ip_get:: rt_socket::error\n");
+		rt_printf("%s:: rt_socket [%d]::error\n", __FUNCTION__, index);
 		return -1;
 	}
 
@@ -1222,7 +1222,7 @@ int rt_if_ip_get2(int eth_id, int index, unsigned char *ip)
 	sock = rt_socket(AF_INET, SOCK_DGRAM, 0);
 	if (sock == RT_SOCKET_ERR)
 	{
-		rt_printf("rt_if_ip_get2:: rt_socket::error\n");
+		rt_printf("%s:: rt_socket [%d][%d]::error\n", __FUNCTION__, eth_id, index);
 		return -1;
 	}
 

+ 16 - 3
app_public/gps/gps_uart.c

@@ -751,7 +751,7 @@ int GpsRecvDataFrameHandler(GPS_COMM* data)
 
 void GpsSwitchBaudrateFun(GPS_COMM* data, GpsCtrlCmdEnumType GpsCtrlCmd)
 {
-
+    int ret;
     u8 chnl=data->chnl;
     GpsModuleRunStepEnum LocalGpsModuleRunStep=data->GpsModuleRunStep;
 
@@ -764,7 +764,11 @@ void GpsSwitchBaudrateFun(GPS_COMM* data, GpsCtrlCmdEnumType GpsCtrlCmd)
 #if defined(BSP_DTU3) || defined(BSP_DTU2) || defined(BSP_DTU4)	
 	uart_open(UART_CHANNEL[chnl],GpsCommBuadrateTbl[GpsCtrlCmd],PARITY_NONE1);
 #else
-    uart_open(UART_CHANNEL[chnl],GpsCommBuadrateTbl[GpsCtrlCmd],PARITY_NONE_1);  //????′??ú
+    ret = uart_open(UART_CHANNEL[chnl],GpsCommBuadrateTbl[GpsCtrlCmd],PARITY_NONE_1);
+    if (ret < 0)
+    {
+        printf("%s: outside uart %d open failed!\n", __FUNCTION__, UART_CHANNEL[chnl]);
+    }
 #endif    
 	RS_Ena_Init(chnl);
     RS_Recv_Enable(chnl);
@@ -779,6 +783,7 @@ void GpsModuleFunInit(GPS_COMM* data)
     static GpsCtrlCmdEnumType GpsSwitchBaudrate;
     static uint32_t us0=0;
     u8 count,chnl=data->chnl,i;
+    int ret;
 
     if(us0==0)
         us0=ustimer_get_origin();
@@ -817,7 +822,15 @@ void GpsModuleFunInit(GPS_COMM* data)
                 g_tRsComm[chnl].ptBuf=(BYTE*)&g_tRsIEC[chnl];
                 GPSCommInit((GPS_COMM *)g_tRsComm[chnl].ptBuf,chnl);   //运行步骤恢复初始状态
                 
-                uart_open(UART_CHANNEL[chnl],tRunPara.tUartPara[chnl].wBaud,tRunPara.tUartPara[chnl].wParity);
+                ret = uart_open(UART_CHANNEL[chnl],tRunPara.tUartPara[chnl].wBaud,tRunPara.tUartPara[chnl].wParity);
+                if (ret < 0)
+                {
+                    printf("%s: outside uart %d open failed!\n", __FUNCTION__, UART_CHANNEL[chnl]);
+                }
+                else
+                {
+                    printf("%s: outside uart %d open success!\n", __FUNCTION__, UART_CHANNEL[chnl]);
+                }
                 RS_Ena_Init(chnl);
                 RS_Recv_Enable(chnl);
 			#endif

+ 10 - 2
dtu/dtu_main_t536/app/IECComm.c

@@ -390,7 +390,7 @@ bool getIecLink101Status(void)
 ***************************************************************************/
 void IEC_CommInit(void)                     // 外部通信初始化 
 {
-	int i;
+	int i, ret;
 	
 	s_stat_reset(1);//初始串口统计信息
 	
@@ -500,7 +500,15 @@ void IEC_CommInit(void)                     // 
 			rt_printf("UART_CHANNEL[%d]=%d,tRunPara.tUartPara[%d].wProtocol=%d,tRunPara.tUartPara[%d].wBaud=%d tUartPara[%d].wParity=%d\r\n",\
 					i,UART_CHANNEL[i],i,tRunPara.tUartPara[i].wProtocol,i,tRunPara.tUartPara[i].wBaud,i,tRunPara.tUartPara[i].wParity);
 		#endif
-			uart_open(UART_CHANNEL[i],tRunPara.tUartPara[i].wBaud,tRunPara.tUartPara[i].wParity);
+			ret = uart_open(UART_CHANNEL[i],tRunPara.tUartPara[i].wBaud,tRunPara.tUartPara[i].wParity);
+			if (ret < 0)
+			{
+				printf("%s: outside uart %d open failed!\n", __FUNCTION__, UART_CHANNEL[i]);
+			}
+			else
+			{
+				printf("%s: outside uart %d open success!\n", __FUNCTION__, UART_CHANNEL[i]);
+			}
 
 			RS_Ena_Init(i);
 			RS_Recv_Enable(i);

+ 7 - 1
dtu/dtu_main_t536/app/LcdComm.c

@@ -392,7 +392,13 @@ void HMI_Comm_App(void)  /*10
 				{	
 					if(tRunPara.tUartPara[i].wProtocol == PROTOCOL_HMI)  // Ãæ°å¹æÔ¼
 					{
-						uart_open(UART_CHANNEL[i],tRunPara.tUartPara[i].wBaud,tRunPara.tUartPara[i].wParity);
+						int ret;
+						ret = uart_open(UART_CHANNEL[i],tRunPara.tUartPara[i].wBaud,tRunPara.tUartPara[i].wParity);
+						if (ret < 0) {
+							printf("%s: outside uart %d open failed!\n", __FUNCTION__, UART_CHANNEL[i]);
+						} else {
+							printf("%s: outside uart %d open success!\n", __FUNCTION__, UART_CHANNEL[i]);
+						}
 						RS_Ena_Init(i);
 						RS_Recv_Enable(i);
 						g_h_boj[0].fd = UART_CHANNEL[i];

+ 1 - 1
dtu/dtu_main_t536/app/SOE.c

@@ -1480,7 +1480,7 @@ void soe_save(void)
 	EVENT_SAVE es,*esp;
 	uint32_t  flags;
 	u8 soe_type;
-	u32 us0;
+	u64 us0;
 
 	// Ñ­»·±£´æËùÓмǼ
 	us0 = bsp_ustimer_get_origin();

+ 2 - 2
dtu/dtu_main_t536/app/protect.c

@@ -329,8 +329,8 @@ void yc_refresh_en(int sw)
 */
 int protect_polling(void)
 {
-	u32 us0;
-	u32 dTDelta;	// 5ms巡检时间片
+	u64 us0;
+	u64 dTDelta;	// 5ms巡检时间片
 	// 首次进入初始化
 	if (!g_protect.update)
 	{

+ 1 - 1
dtu/dtu_main_t536/app/record.c

@@ -2506,7 +2506,7 @@ int _rcd_open(u32 sw)
 #endif
 int _rcd_save(struct rcd *prcd)
 {
-	uint32_t us0;
+	uint64_t us0;
 	
 	int i,loop;
 	u32 dt_end; 

+ 1 - 1
dtu/dtu_main_t536/app/switch.c

@@ -3595,7 +3595,7 @@ void _sw_cal_pq(void)
 int _sw_cal_mea(void)
 {
 	static int g_cal_step = 0;
-  	uint32_t us0;
+  	uint64_t us0;
 
 	us0 = bsp_ustimer_get_origin();
 

+ 13 - 4
dtu/dtu_main_t536/main_mod.c

@@ -16,6 +16,7 @@
 #include "rt.h"
 #include "app.h"
 #include "head.h"
+#include "tmp/bsp_share/bsp_ustimer.h"
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/syscall.h>
@@ -278,12 +279,12 @@ int di_do_adc (void *unused)
 	pid_t tid;
     cpu_set_t set;
     struct sched_param sch_par;
-    sch_par.sched_priority = 10;
+    sch_par.sched_priority = 99;
 
-	// Set CPU affinity [CK860-CPU-1]
+	// Set CPU affinity [T536-CPU-3]
     tid = gettid();
     CPU_ZERO(&set);
-    CPU_SET(1, &set);
+    CPU_SET(3, &set);
     sched_setaffinity(tid, sizeof(cpu_set_t), &set);
 
 	while(SystemInit_finish_flag == false)
@@ -301,7 +302,7 @@ int di_do_adc (void *unused)
     //adc_init();
     dido_init();
 	rt_stat_init(&g_stat_periodus_5ms, "pit_5ms_priod(1us)");
-    pthread_setschedparam(pthread_self(), SCHED_RR, &sch_par);   // 设置当前线程优先级
+    pthread_setschedparam(pthread_self(), SCHED_FIFO, &sch_par);   // 设置当前线程优先级
 	prctl(PR_SET_NAME, "di_do_adc");
 	rt_printf("Thread created successfully: %s, PID: %d LWP: %d\r\n", 
               	"di_do_adc", (int)getpid(), (int)syscall(SYS_gettid));
@@ -312,6 +313,14 @@ int di_do_adc (void *unused)
 		unsigned long origin_ext = 0;
 
         usleep(1000);
+		// bsp_ustimer_delay(1000); // 1ms
+
+		// 检查是否需要退出。
+		if(g_exit_flag)
+		{
+			//complete_and_exit(&exit_completion2, 1);
+			break;
+		}
 
 		origin_ext = bsp_ustimer_get_origin();
 		if (flags) {