Browse Source

4G联网及数据发送测试完成

CHENJIE-PC\QiXiang_CHENJIE 2 years ago
parent
commit
20c663dbdd

+ 1 - 1
.cproject

@@ -176,12 +176,12 @@
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.debug.222968549.Project_Settings/Debugger" name="Debugger" rcbsApplicability="disable" resourcePath="Project_Settings/Debugger" toolsToInvoke=""/>
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.debug.222968549.Project_Settings/Linker_Files" name="Linker_Files" rcbsApplicability="disable" resourcePath="Project_Settings/Linker_Files" toolsToInvoke=""/>
 					<sourceEntries>
+						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 						<entry excluding="Linker_Files|Debugger" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Project_Settings"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="RTD"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="generate"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
-						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>

+ 1 - 0
Project_Settings/Debugger/S32K146_4G_Debug_FLASH_PNE.launch

@@ -216,4 +216,5 @@
 </listAttribute>
 <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#13;&#10;"/>
 <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="0x1fff0167,0x237a0,0x1fff4218,0x1fff01fc,0x1fff01c8,0x1fff4228,0x237d8,0x1fff01d7,0x1fff01d5,0x1fff01d3,0x1fff01d6,0x1fff01d4,0x1fff01d2,0x1fff01d0,0x1fff01c0"/>
 </launchConfiguration>

+ 1 - 1
generate/include/Dio_Cfg.h

@@ -92,7 +92,7 @@ extern "C" {
 /**
 * @brief          Function @p Dio_FlipChannel() enable switch.
 */
-#define DIO_FLIP_CHANNEL_API    (STD_OFF)
+#define DIO_FLIP_CHANNEL_API    (STD_ON)
 
 /**
 * @brief          Function @p Dio_MaskedWritePort() enable switch.

+ 332 - 0
src/AppFuncLib.c

@@ -0,0 +1,332 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-01-21 09:28:20
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 16:28:11
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppFuncLib.c
+ */
+/*
+ * AppFuncLib.c
+ *应用层函数库
+ *  Created on: 2022年1月21日
+ *      Author: QiXiang_CHENJIE
+ */
+
+#include "AppFuncLib.h"
+uint16 ATstrdel(char *str)
+{
+    char *p = str;
+    bool flag = false;
+    while (*str)
+    {
+        if (*str > 0x20)
+        {
+            *(p) = *str;
+            p = p + 1;
+            flag = false;
+        }
+        else
+        {
+            if (!flag)
+            {
+                *(p) = ',';
+                p = p + 1;
+                flag = true;
+            }
+        }
+        str++;
+    }
+    *p = '\0';
+    return 0;
+}
+uint16 mstrlen(const char *s)
+{
+    uint16 out = 0;
+    const char *ss = s;
+    while (*ss)
+        ss++;
+    out = (ss - s);
+    return out;
+}
+int mstrncmp(const char *s1, const char *s2, int n)
+{
+    const unsigned char *c1 = (const unsigned char *)s1;
+    const unsigned char *c2 = (const unsigned char *)s2;
+    unsigned char ch;
+    int d = 0;
+    while (n--)
+    {
+        d = (int)(ch = *c1++) - (int)*c2++;
+        if (d || !ch)
+            break;
+    }
+    return d;
+}
+unsigned char HexToChar(unsigned char bHex)
+{
+    if ((bHex >= 0) && (bHex <= 9))
+        bHex += 0x30;
+    else if ((bHex >= 10) && (bHex <= 15)) //大写字母
+        bHex += 0x37;
+    else
+        bHex = 0xff;
+    return bHex;
+}
+unsigned char CharToHex(unsigned char bChar)
+{
+    if ((bChar >= 0x30) && (bChar <= 0x39))
+        bChar -= 0x30;
+    else if ((bChar >= 0x41) && (bChar <= 0x46)) //大写字母
+        bChar -= 0x37;
+    else if ((bChar >= 0x61) && (bChar <= 0x66)) //小写字母
+        bChar -= 0x57;
+    else
+        bChar = 0xff;
+    return bChar;
+}
+uint8 AtStrCompare(const char *a, const char *b)
+{
+    uint8 out = 1;
+    while (1)
+    {
+        if (*a == '\0' || *b == '\0') //判断其中是否有字符串结束
+        {
+            if (strlen(a) == strlen(b))
+            {
+                out = 1;
+                break;
+            }
+            else
+            {
+                out = 0;
+                break;
+            }
+        }
+        else
+        {
+            if (*a != *b)
+            {
+                out = 0;
+                break;
+            }
+            else if (*a == '=' && *b == '=')
+            {
+                out = 1;
+                break;
+            }
+        }
+        a++;
+        b++;
+    }
+    return out;
+}
+unsigned short CRC16_Modbus(unsigned char *pdata, int len)
+{
+    unsigned short crc = 0xFFFF;
+    int i, j;
+    for (j = 0; j < len; j++)
+    {
+        crc = crc ^ pdata[j];
+        for (i = 0; i < 8; i++)
+        {
+            if ((crc & 0x0001) > 0)
+            {
+                crc = crc >> 1;
+                crc = crc ^ 0xa001;
+            }
+            else
+                crc = crc >> 1;
+        }
+    }
+    return crc;
+}
+char *Myitoa(int value, char *result, int base)
+{
+    // check that the base if valid
+    if (base < 2 || base > 36)
+    {
+        *result = '\0';
+        return result;
+    }
+
+    char *ptr = result, *ptr1 = result, tmp_char;
+    int tmp_value;
+
+    do
+    {
+        tmp_value = value;
+        value /= base;
+        *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
+    } while (value);
+
+    // Apply negative sign
+    if (tmp_value < 0)
+        *ptr++ = '-';
+    *ptr-- = '\0';
+    while (ptr1 < ptr)
+    {
+        tmp_char = *ptr;
+        *ptr-- = *ptr1;
+        *ptr1++ = tmp_char;
+    }
+    return result;
+}
+
+/************************************************************************
+* @brief 整数转字符串
+* @param[in] num 整数
+* @param[out] buf 字符串
+* @return 返回字符串长度
+************************************************************************/
+inline int _itoa(int num, char buf[32])
+{
+	return _i2a(num, buf, 10);
+}
+
+/************************************************************************
+* @brief 整数转字符串
+* @param[in] num 整数
+* @param[out] buf 字符串
+* @param[in] radix 进位制整数
+* @return 返回字符串长度
+************************************************************************/
+int _i2a(int num, char buf[32], int radix)
+{
+	static const char s[] = "0123456789abcdef";
+	int n = num, R = radix;
+	char *dst = buf;
+	if (n < 0) { *dst++ = '-'; n = -n; }
+	if (n < 10)
+	{
+		*dst++ = s[n]; *dst = 0;
+	}else
+	{
+		char tmp[32], *p = tmp;
+		while (n) { *p++ = s[n % R]; n /= R; }
+		while (--p != tmp) *dst++ = *p;
+		*dst++ = *tmp; *dst = 0;
+	}
+	return dst-buf;
+}
+
+/************************************************************************
+* @brief 浮点数转字符串
+* @param[in] val 浮点数
+* @param[out] buf 字符串
+* @param[in] eps 精度(小数位)
+* @return 返回字符串长度
+************************************************************************/
+int _ftoa(double val, char buf[32], int eps)
+{
+	double f = val;
+	char *p = buf;
+	if (val < 0) { *p++ = '-'; f = -f; }
+	int n = f;
+	int len = _itoa(n, p);
+	return len + __ftoa(f - n, p + len, eps);
+}
+
+/************************************************************************
+* @brief 浮点数转字符串:范围(-1, 1)
+* @param[in] val 浮点数
+* @param[out] buf 字符串
+* @param[in] eps 精度(小数位)
+* @return 返回字符串长度
+************************************************************************/
+int __ftoa(double val, char buf[32], int eps)
+{
+	double f = val;
+	char *p = buf;
+	static const char s[] = "0123456789";
+	if (f<0){*p++ = '-'; f = -f;}*p++ = '.';
+	for (int i = eps+1, n; --i; ++p, f -= n)
+		*p = s[n = f *= 10.0];
+	*p = 0;
+	return p-buf;
+}
+
+/************************************************************************
+* @brief 替换sprintf
+* @ref 可变长参数列表误区与陷阱——va_arg不可接受的类型
+* http://www.cppblog.com/ownwaterloo/archive/2009/04/21/80655.aspx
+************************************************************************/
+int _sprintf(char *dst, const char *format, ...)
+{
+	char *s = dst;
+	const char *f = format;
+	va_list ap, another;
+	va_start(ap, format);
+	va_copy(another, ap);
+	while (*f)
+	{
+		int n = 1;
+		if ('%' != *f)
+		{
+			*s = *f;
+		}else{
+			++f;
+			switch (*f)
+			{
+			case 's':// 字符串
+				{
+					const char *p = va_arg(ap, char*);
+					n = strlen(p);
+					memcpy(s, p, n);
+				}
+				break;
+
+			case 'd': case 'u':// 整数
+				{
+					char buf[32];
+					n = _itoa(va_arg(ap, int), buf);
+					memcpy(s, buf, n);
+				}
+				break;
+
+			case 'f':// 浮点数
+				{
+					char buf[32];
+					n = _ftoa(va_arg(ap, double), buf,6);
+					memcpy(s, buf, n);
+				}
+				break;
+
+			case 'x':// 16进制数
+				{
+					char buf[32];
+					n = _i2a(va_arg(ap, int), buf, 16);
+					memcpy(s, buf, n);
+				}
+				break;
+
+			case 'c':// 字符
+				{
+					*s = va_arg(ap, int);
+				}
+				break;
+
+			case '%':// 百分号
+				{
+					*s = '%';
+				}
+				break;
+
+			default:
+				{
+					va_end(ap);
+					int x = vsprintf(dst, format, another);
+					va_end(another);
+					return x;
+				}
+				break;
+			}
+		}
+		++f;
+		s += n;
+	}
+	*s = 0;
+	va_end(ap);
+	return s-dst;
+}

+ 46 - 0
src/AppFuncLib.h

@@ -0,0 +1,46 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-01-23 13:45:09
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 16:28:19
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppFuncLib.h
+ */
+/*
+ * AppFunc.h
+ *应用层函数库
+ *  Created on: 2022年1月21日
+ *      Author: QiXiang_CHENJIE
+ */
+
+#ifndef APPFUNCLIB_H_
+#define APPFUNCLIB_H_
+#include "hal_adapter.h"
+#include <stdarg.h>
+#include "stdio.h"
+#ifndef va_copy
+#define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list))
+#endif
+uint16 ATstrdel(char *str);
+uint16 mstrlen(const char *s);
+int mstrncmp(const char *s1, const char *s2, int n);
+unsigned char HexToChar(unsigned char bHex);
+unsigned char CharToHex(unsigned char bChar);
+uint8 AtStrCompare(const char *a, const char *b);
+unsigned short CRC16_Modbus(unsigned char *pdata, int len);
+char *Myitoa(int value, char *result, int base);
+// 整数转字符串
+int _itoa(int num, char buf[32]);
+
+int _i2a(int num, char buf[32], int radix);
+
+// 浮点转字符串
+int _ftoa(double val, char buf[32], int eps);
+
+// 浮点转字符串,范围(-1,1)
+int __ftoa(double val, char buf[32], int eps);
+
+// 替代sprintf
+int _sprintf(char *dst, const char *format, ...);
+#endif /* APPFUNCLIB_H_ */

+ 33 - 0
src/AppGlobalVar.c

@@ -0,0 +1,33 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-01-23 13:45:09
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 11:34:32
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppGlobalVar.c
+ */
+/*
+ * AppGlobalVar.c
+ *应用层全局变量
+ *  Created on: 2022年1月19日
+ *      Author: QiXiang_CHENJIE
+ */
+
+#include "AppGlobalVar.h"
+//*全局变量*//
+char ImeiNum[15] = {0};
+char IccidNum[20] = {0};
+uint8 CSQValue = 0;
+sint8 SocketId = -1;
+char WebSiteIp[15] = {0};
+/*Can*/
+uint8 CanIf_u8TxConfirmCnt = 0U;
+boolean CanIf_bTxFlag = false;
+uint8 CanIf_u8RxIndicationCnt = 0U;
+boolean CanIf_bRxFlag = false;
+QueueHandle_t CanRecvQueueHandle;
+
+// Const 变量
+const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
+const uint8 WebSitePort = 8712;

+ 41 - 0
src/AppGlobalVar.h

@@ -0,0 +1,41 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-01-23 13:45:09
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 11:03:59
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppGlobalVar.h
+ */
+/*
+ * AppGlobal.h
+ *应用层全局变量
+ *  Created on: 2022年1月19日
+ *      Author: QiXiang_CHENJIE
+ */
+#ifndef APPGLOBALVAR_H_
+#define APPGLOBALVAR_H_
+
+#include "hal_adapter.h"
+//*全局变量*//
+extern char ImeiNum[15];
+extern char IccidNum[20];
+extern uint8 CSQValue;
+extern sint8 SocketId;
+extern char WebSiteIp[15];
+typedef struct
+{
+    uint8 RealLen;
+    uint8 *DataPtr;
+} QueueDataTrans_Type;
+/*Can*/
+extern uint8 CanIf_u8TxConfirmCnt;
+extern boolean CanIf_bTxFlag;
+extern uint8 CanIf_u8RxIndicationCnt;
+extern boolean CanIf_bRxFlag;
+extern QueueHandle_t CanRecvQueueHandle;
+
+extern const char WebSiteName[];
+extern const uint8 WebSitePort;
+
+#endif /* APPGLOBALVAR_H_ */

+ 593 - 0
src/AppTaskUart1.c

@@ -0,0 +1,593 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-02-10 11:43:56
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 16:28:49
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppTaskUart1.c
+ */
+/*
+ * AppTaskUart2.c
+ *  4G的串口函数
+ *  Created on: 2022年2月10日
+ *      Author: QiXiang_CHENJIE
+ */
+#include "AppTaskUart1.h"
+const ATCmdFunc Atcmdfunc[] = {
+	{AT_CMD_TEST, "AT\r\n", at_callbackFunc},
+	{AT_SIMREADY, "AT+CPIN?\r\n", at_callbackFunc},
+	{AT_GETICCID, "AT+CICCID\r\n", at_callbackFunc},
+	{AT_CGREG, "AT+CGREG?\r\n", at_callbackFunc},
+	{AT_CSQ, "AT+CSQ\r\n", at_callbackFunc},
+	{AT_NETOPEN, "AT+NETOPEN\r\n", at_callbackFunc},
+	{AT_CGIP, "AT+CDNSGIP=", at_callbackFunc},
+	{AT_CONNECT, "AT+CIPOPEN=0,\"TCP\",\"120.26.68.165\",14319\r\n", at_callbackFunc},
+	{AT_CONNECTCHK, "AT+CIPOPEN?\r\n", at_callbackFunc},
+	{AT_SEND, "AT+CIPSEND=", at_callbackFunc},
+	{AT_GETTIME,"AT+CCLK?\r\n",at_callbackFunc},
+	{AT_DISCON, "AT+CIPCLOSE=0\r\n", at_callbackFunc},
+	{AT_NETCLOSE, "AT+NETCLOSE\r\n", at_callbackFunc}};
+
+static process_Tcp gProcess_Tcp_Task = PROCESS_TCP_IDLE;
+#define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
+void InitFunc(void);
+sint8 TcpConnectFunc(sint8 *ConnectId);
+sint8 TcpDataSendFunc(sint8 ConnectId);
+sint8 TcpRegisterChkFunc(void);
+static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc);
+void Uart_4G_Task(void *pvParameters)
+{
+	(void)pvParameters;
+	// 4G开机
+	Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
+	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
+	Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
+	_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
+	// LED测试
+	Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
+	vTaskDelay(pdMS_TO_TICKS(5000));
+	uint8 pReadLen = 0;
+	InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
+	for (;;)
+	{
+		switch (gProcess_Tcp_Task)
+		{
+		case PROCESS_TCP_IDLE: //空闲状态
+		{
+			Dio_FlipChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1);
+			vTaskDelay(pdMS_TO_TICKS(1000));
+			if (SocketId < 0)
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
+			}
+			else
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
+			}
+			break;
+		}
+		case PROCESS_TCP_ATSYS:
+		{
+			sint8 ATRet = -1;
+			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+			}
+			else
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+			}
+			break;
+		}
+		case PROCESS_TCP_REGCHK: //驻网检查,包括SIM,CPIN检查,ICCID获取
+		{
+			sint8 RegChkRet = 0;
+			RegChkRet = TcpRegisterChkFunc();
+			if (RegChkRet > 0) //检查通过,SIM卡已就绪,已进行驻网
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_CONNECT);
+			}
+			else
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+			}
+			break;
+		}
+		case PROCESS_TCP_CONNECT: //网络连接,包括域名转换
+		{
+			if (SocketId < 0)
+			{
+				sint8 ConnectRet = 0;
+				ConnectRet = TcpConnectFunc(&SocketId);
+				if (ConnectRet > 0)
+				{
+					PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+				}
+				else
+				{
+					PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+				}
+			}
+			break;
+		}
+		case PROCESS_TCP_SEND: //网络数据发送
+		{
+			sint8 SendRet = -1;
+			SendRet = TcpDataSendFunc(SocketId);
+			if(SendRet==0)
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+			}
+			else
+			{
+				SocketId = -1;
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+			}
+			break;
+		}
+		case PROCESS_TCP_RECV: //网络数据接收(不应采用定时调用),空闲状态下即可接收
+		{
+			break;
+		}
+		case PROCESS_TCP_HEART: //心跳包发送
+		{
+			break;
+		}
+		case PROCESS_TCP_SLEEP: //网络休眠状态
+		{
+			break;
+		}
+		case PROCESS_TCP_ERROR: //错误状态
+		{
+			PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+			break;
+		}
+		}
+	}
+}
+sint8 TcpDataSendFunc(sint8 ConnectId)
+{
+	sint8 outValue = -1;
+	char *pSendData = "Hello World!";
+	uint8 DataSendLen = 0;
+	DataSendLen = mstrlen(pSendData);
+
+	//数据准备完成,下面开始发送
+	sint8 ATRet = -1;
+
+	//AtcmdTransmit(AT_GETTIME, NULL, 0, &ATRet);4G模块的时间获取
+	uint8 ReadLen = 0;
+	char AtCmdSend[10] = {0};
+	uint8 AtCmdSendTotalLen = 0;
+	sprintf(AtCmdSend,"%d,%d\r\n",ConnectId,DataSendLen);//此处需要优化
+//	Myitoa(ConnectId, Strtemp, 10);
+//	memcpy(AtCmdSend, Strtemp, mstrlen(Strtemp));
+//	AtCmdSendTotalLen = AtCmdSendTotalLen + mstrlen(Strtemp);
+//	memcpy(AtCmdSend + AtCmdSendTotalLen, (char *)(","), 1);
+//	AtCmdSendTotalLen = AtCmdSendTotalLen + 1;
+//	memset(Strtemp, 0x00, sizeof(Strtemp));
+//	Myitoa(DataSendLen, Strtemp, 10);
+//	memcpy(AtCmdSend + AtCmdSendTotalLen, Strtemp, mstrlen(Strtemp));
+//	AtCmdSendTotalLen = AtCmdSendTotalLen + mstrlen(Strtemp);
+//	memcpy(AtCmdSend + AtCmdSendTotalLen, CRLF, mstrlen(CRLF));
+	AtCmdSendTotalLen = mstrlen(AtCmdSend);
+	AtcmdTransmit(AT_SEND, AtCmdSend, AtCmdSendTotalLen, &ATRet);
+	if (ATRet == 0)
+	{
+		memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
+		UART_Query_Data(UART_LPUART1, UART_LPUART1, pSendData, DataSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 10);
+		if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
+		{
+			outValue = 0;
+		}
+	}
+	return outValue;
+}
+sint8 TcpConnectFunc(sint8 *ConnectId)
+{
+	uint8 ConnectStep = 0;
+	sint8 ChkState = 0;
+	sint8 ATRet = -1;
+	while (1)
+	{
+		switch (ConnectStep)
+		{
+		case 0: // AT指令同步
+		{
+			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				ConnectStep++;
+			}
+			else
+			{
+				ChkState = -ConnectStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 1: // Netopen
+		{
+			AtcmdTransmit(AT_NETOPEN, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				ConnectStep++;
+			}
+			else
+			{
+				ChkState = -ConnectStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 2: //连接检查
+		{
+			AtcmdTransmit(AT_CONNECTCHK, NULL, 0, &ATRet); // ATret返回的值是连接id,如果未连接返回-1
+			if (ATRet >= 0)
+			{
+				*ConnectId = ATRet;
+				return 1;
+			}
+			else
+			{
+				ConnectStep++;
+			}
+			break;
+		}
+		case 3: //域名转换
+		{
+			char AtCmdSend[30] = {0};
+			uint8 AtCmdSendLen = 0;
+			AtCmdSendLen = mstrlen(WebSiteName);
+			memcpy(AtCmdSend, WebSiteName, AtCmdSendLen);
+			memcpy(AtCmdSend + AtCmdSendLen, (char *)CRLF, sizeof(CRLF));
+			AtCmdSendLen = AtCmdSendLen + 2;
+			AtcmdTransmit(AT_CGIP, AtCmdSend, AtCmdSendLen, &ATRet);
+			if (ATRet == 0)
+			{
+				ConnectStep++;
+			}
+			else
+			{
+				ChkState = -ConnectStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 4: //创建连接
+		{
+			AtcmdTransmit(AT_CONNECT, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				ConnectStep++;
+			}
+			else
+			{
+				ChkState = -ConnectStep;
+				return ChkState;
+			}
+			break;
+		}
+		default:
+			ChkState = ConnectStep;
+			return ChkState;
+		}
+	}
+}
+sint8 TcpRegisterChkFunc(void)
+{
+	uint8 RegChkStep = 0;
+	sint8 ChkState = 0; //默认为0
+	sint8 ATRet = -1;
+	while (1)
+	{
+		switch (RegChkStep)
+		{
+		case 0: // AT指令同步
+		{
+			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				RegChkStep++;
+			}
+			else
+			{
+				ChkState = -RegChkStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 1: // CPIN检查
+		{
+			AtcmdTransmit(AT_SIMREADY, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				RegChkStep++;
+			}
+			else
+			{
+				ChkState = -RegChkStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 2: // ICCID获取
+		{
+			AtcmdTransmit(AT_GETICCID, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				RegChkStep++;
+			}
+			else
+			{
+				ChkState = -RegChkStep;
+				return ChkState;
+			}
+			break;
+		}
+		case 3:
+		{
+			AtcmdTransmit(AT_CGREG, NULL, 0, &ATRet); //驻网检查,返回值1和5是驻网成功
+			if (ATRet == 1 || ATRet == 5)
+			{
+				RegChkStep++;
+			}
+			else
+			{
+				ChkState = -RegChkStep;
+				return ChkState;
+			}
+			break;
+		}
+		default:
+			ChkState = RegChkStep;
+			return ChkState;
+			break;
+		}
+	}
+}
+void InitFunc(void)
+{
+	// 4G模块初始化
+	uint8 _4G_InitStep = 0;
+	sint8 ATRet = -1;
+	uint8 ReadLen = 0;
+	char *ATCmdSend = NULL;
+	uint8 ATCmdSendLen = 0;
+	while (1)
+	{
+		switch (_4G_InitStep)
+		{
+		case 0: // AT指令同步
+		{
+			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
+			if (ATRet == 0)
+			{
+				_4G_InitStep++;
+			}
+			else
+			{
+				_4G_InitStep = 0;
+			}
+			break;
+		}
+		case 1: //关闭回显
+		{
+			ATCmdSend = (char *)("ATE0\r\n");
+			ATCmdSendLen = mstrlen(ATCmdSend);
+			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 10);
+			uint8 *retptr = NULL;
+			if (ReadLen > 0)
+			{
+				retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK"));
+				if (retptr)
+				{
+					_4G_InitStep++;
+				}
+				else
+				{
+					_4G_InitStep = 0;
+				}
+			}
+			else
+			{
+				_4G_InitStep = 0;
+			}
+			break;
+		}
+		case 2: // IMEI获取
+		{
+			ATCmdSend = (char *)("AT+SIMEI?\r\n");
+			ATCmdSendLen = mstrlen(ATCmdSend);
+			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 10);
+			uint8 *retptr = NULL;
+			if (ReadLen > 0)
+			{
+				retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("+SIMEI"));
+				if (retptr)
+				{
+					memcpy(ImeiNum, retptr + 8, 15);
+					_4G_InitStep++;
+				}
+				else
+				{
+					_4G_InitStep = 0;
+				}
+			}
+			else
+			{
+				_4G_InitStep = 0;
+			}
+			break;
+		}
+		default:
+		{
+			return;
+			break;
+		}
+		}
+	}
+}
+static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc)
+{
+	uint8 *ATCmdRead;
+	uint16 ReadLen = 0;
+	uint8 *PtrATCmdSend = NULL;
+	uint8 ATCmdFixedLen = 0;
+	uint16 ATCmdTotalLen = 0;
+	ATCmdFixedLen = mstrlen(Atcmdfunc[CmdIdx].str);
+	ATCmdTotalLen = ATCmdFixedLen + SetValueLen;
+	PtrATCmdSend = malloc(ATCmdTotalLen);
+	memset(PtrATCmdSend, 0x00, ATCmdTotalLen);
+	memcpy(PtrATCmdSend, Atcmdfunc[CmdIdx].str, ATCmdFixedLen);
+	if (SetValuePtr != NULL)
+	{
+		memcpy(PtrATCmdSend + ATCmdFixedLen, SetValuePtr, SetValueLen);
+	}
+	memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
+	UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 100);
+	ATCmdRead = RX_Buffer[UART_LPUART1];
+	*retFunc = Atcmdfunc[CmdIdx].cb(PtrATCmdSend, ATCmdRead, CmdIdx, ReadLen);
+	if (PtrATCmdSend != NULL)
+	{
+		free(PtrATCmdSend);
+	}
+	PtrATCmdSend = NULL;
+	return;
+}
+sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen)
+{
+	sint8 OutValue = -1;
+	uint8 *retptr = NULL;
+	char *OkAns = "OK";
+	retptr = (uint8 *)strstr((char *)pReadStr, OkAns);
+	switch (CmdIdx)
+	{
+	case AT_CMD_TEST:
+	{
+		if (retptr)
+		{
+			OutValue = 0;
+		}
+		break;
+	}
+	case AT_SIMREADY:
+	{
+		if (retptr)
+		{
+			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("READY"));
+			if (retptr)
+			{
+				OutValue = 0;
+			}
+		}
+		break;
+	}
+	case AT_GETICCID:
+	{
+		if (retptr)
+		{
+			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("ICCID"));
+			if (retptr)
+			{
+				memcpy(IccidNum, retptr + 7, 20);
+				OutValue = 0;
+			}
+		}
+		break;
+	}
+	case AT_CGREG:
+	{
+		if (retptr)
+		{
+			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("CGREG"));
+			if (retptr)
+			{
+				uint8 RegN = 0;
+				uint8 RegState = 0;
+				RegN = CharToHex(*(retptr + 7));
+				RegState = CharToHex(*(retptr + 9));
+				OutValue = (RegState + RegN);
+				return OutValue;
+			}
+		}
+
+		break;
+	}
+	case AT_NETOPEN:
+	{
+		if (retptr)
+		{
+			OutValue = 0;
+		}
+		retptr = (uint8 *)strstr((char *)pReadStr, (char *)("opened")); //重复打开
+		if (retptr)
+		{
+			OutValue = 0;
+		}
+		break;
+	}
+	case AT_CONNECTCHK:
+	{
+		if (retptr)
+		{
+			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("TCP"));
+			if (retptr)
+			{
+				OutValue = CharToHex(*(retptr - 3));
+				return OutValue;
+			}
+		}
+		break;
+	}
+	case AT_CGIP:
+	{
+		if (retptr)
+		{
+			for (uint8 i = 0; i < 30; i++)
+			{
+				if (*(retptr - i) == ',')
+				{
+					memcpy(WebSiteIp, retptr - i + 1, 15);
+					OutValue = 0;
+					break;
+				}
+			}
+		}
+		break;
+	}
+	case AT_CONNECT:
+	{
+		if (retptr)
+		{
+			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("CIPOPEN"));
+			SocketId = CharToHex(*(retptr + 9));
+			OutValue = 0;
+		}
+		break;
+	}
+	case AT_SEND:
+	{
+		retptr = (uint8 *)strstr((char *)pReadStr, (char *)(">"));
+		if (retptr)
+		{
+			OutValue = 0;
+		}
+		break;
+	}
+	case AT_GETTIME:
+	{
+		if(retptr)
+		{
+			OutValue = 0;
+		}
+	}
+	default:
+		break;
+	}
+	return OutValue;
+}

+ 61 - 0
src/AppTaskUart1.h

@@ -0,0 +1,61 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-02-10 11:44:08
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-02-11 10:44:55
+ * @Description  : file content
+ * @FilePath     : \S32K146_4G\src\AppTaskUart1.h
+ */
+/*
+ * AppTaskUart2.h
+ *4G的串口函数
+ *  Created on: 2022年2月10日
+ *      Author: QiXiang_CHENJIE
+ */
+
+#ifndef APPTASKUART1_H_
+#define APPTASKUART1_H_
+#include "hal_adapter.h"
+#include "AppFunclib.h"
+#include "AppGlobalVar.h"
+#define CRLF "\r\n"
+typedef enum
+{
+    AT_CMD_TEST = 0,
+    AT_SIMREADY,
+    AT_GETICCID,
+    AT_CGREG,
+    AT_CSQ,
+    AT_NETOPEN,
+    AT_CGIP,
+    AT_CONNECT,
+    AT_CONNECTCHK,
+    AT_SEND,
+	AT_GETTIME,
+    AT_DISCON,
+    AT_NETCLOSE,
+} ATCmd;
+typedef sint8 (*pFunc)(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen);
+sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen);
+typedef struct
+{
+    ATCmd cmd; /*指令序号*/
+    char *str; /*指令内容*/
+    pFunc cb;  /*对应的执行*/
+} ATCmdFunc;
+typedef enum
+{
+    PROCESS_TCP_IDLE = 0,
+    PROCESS_TCP_ATSYS,
+    PROCESS_TCP_REGCHK,
+    PROCESS_TCP_CONNECT,
+    PROCESS_TCP_SEND,
+    PROCESS_TCP_RECV,
+    PROCESS_TCP_HEART,
+    PROCESS_TCP_SLEEP,
+    PROCESS_TCP_ERROR
+} process_Tcp;
+void Uart_4G_Task(void *pvParameters);
+
+#endif /* APPTASKUART1_H_ */

+ 344 - 0
src/hal_adapter.c

@@ -0,0 +1,344 @@
+/*
+ * hal_adapter.c
+ *中间层函数调用库
+ *  Created on: 2022年1月18日
+ *      Author: QiXiang_CHENJIE
+ */
+#include "hal_adapter.h"
+#include "AppGlobalVar.h"
+
+ uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];
+ uint32_t bufferIdx[3] = {0};
+ Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout)
+ {
+     volatile Std_ReturnType R_Uart_Status;
+     volatile Std_ReturnType T_Uart_Status;
+     volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
+     volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
+     uint32 T_bytesRemaining;
+     uint32 R_bytesRemaining;
+     uint32 timeout = T_timeout;
+     uint32 retVal = E_NOT_OK;
+     //    uint8 Rx_Buffer[MSG_LEN];
+
+     /* Uart_AsyncReceive transmit data */
+ //    IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(0);
+     bufferIdx[recvChannel]=0;
+ 	switch(recvChannel)
+ 	{
+ 	case 0:
+ 		IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+ 		break;
+ 	case 1:
+ 		IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
+ 		break;
+ 	case 2:
+ 		IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
+ 		break;
+ 	default:
+ 		break;
+ 	}
+ if (txBuffer == NULL || rxBuffer == NULL)
+ {
+     return retVal;
+ }
+
+ Uart_SetBuffer(recvChannel, &RX_Buffer[recvChannel][0], DMA_SIZE, UART_RECEIVE);
+ R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
+ if (E_OK != R_Uart_Status)
+ {
+     Uart_Abort(recvChannel, UART_RECEIVE);
+     return E_NOT_OK;
+ }
+
+ /* Uart_AsyncSend transmit data */
+ Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
+ T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
+ if (E_OK != T_Uart_Status)
+ {
+     Uart_Abort(transChannel, UART_SEND);
+     return E_NOT_OK;
+ }
+
+ /* Check for no on-going transmission */
+ do
+ {
+     Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
+     Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
+ } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
+
+ if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
+ {
+     Uart_Abort(transChannel, UART_SEND);
+     retVal = E_NOT_OK;
+ }
+ else
+ {
+     retVal = E_OK;
+ }
+
+ if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
+ {
+     Uart_Abort(recvChannel, UART_RECEIVE);
+     //    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+     retVal = E_NOT_OK;
+ }
+ else
+ {
+	 *rxlen = bufferIdx[recvChannel];
+     retVal = E_OK;
+ }
+ return retVal;
+ }
+
+ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
+ {
+
+     volatile Std_ReturnType T_Uart_Status;
+     volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
+     uint32 T_bytesRemaining;
+     uint32 timeout = T_timeout;
+     uint32 retVal = E_NOT_OK;
+     //    uint8 Rx_Buffer[MSG_LEN];
+
+     if (txBuffer == NULL)
+     {
+         return retVal;
+     }
+
+     /* Uart_AsyncSend transmit data */
+//     Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
+     T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
+     if (E_OK != T_Uart_Status)
+     {
+         Uart_Abort(transChannel, UART_SEND);
+         return E_NOT_OK;
+     }
+
+     /* Check for no on-going transmission */
+     do
+     {
+         Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
+     } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));
+
+     if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
+     {
+         //Uart_Abort(transChannel, UART_SEND);
+         retVal = E_NOT_OK;
+     }
+     else
+     {
+         retVal = E_OK;
+     }
+     return retVal;
+ }
+
+ Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen,sint32 T_timeout)
+ {
+     volatile Std_ReturnType R_Uart_Status=E_NOT_OK;
+     volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
+     uint32 T_bytesRemaining = 0;
+     uint32 retVal = E_NOT_OK;
+     //    uint8 Rx_Buffer[MSG_LEN];
+     bufferIdx[recvChannel]=0;
+     *rxlen = 0;
+     if (rxBuffer == NULL)
+     {
+         return retVal;
+     }
+     /* Uart_AsyncReceive transmit data */
+	switch(recvChannel)
+	{
+	case 0:
+		IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+		break;
+	case 1:
+		IP_LPUART1->CTRL |= LPUART_CTRL_ILIE(1);
+		break;
+	case 2:
+		IP_LPUART2->CTRL |= LPUART_CTRL_ILIE(1);
+		break;
+	default:
+		break;
+	}
+     Uart_SetBuffer(recvChannel, rxBuffer, DMA_SIZE, UART_RECEIVE);
+     R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
+     if (E_OK != R_Uart_Status)
+     {
+         Uart_Abort(recvChannel, UART_RECEIVE);
+         return E_NOT_OK;
+     }
+     /* Check for no on-going transmission */
+     do
+     {
+         Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
+         vTaskDelay(pdMS_TO_TICKS(1));
+
+     } while ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus)&& 0<T_timeout--);
+     if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
+     {
+         Uart_Abort(recvChannel, UART_RECEIVE);
+         *rxlen = 0;
+         retVal = E_NOT_OK;
+     }
+     else
+     {
+    	 *rxlen = bufferIdx[recvChannel];
+         retVal = E_OK;
+     }
+     return retVal;
+ }
+ void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event )
+ {
+ //    (void)userData;
+     uint32_t temp;
+     /* Check the event type */
+     if (event == LPUART_UART_IP_EVENT_RX_FULL)
+     {
+         /* The reception stops when receiving idle is detected or the buffer is full */
+         if (bufferIdx[hwInstance] <= (BUFFER_SIZE - DMA_SIZE))
+         {
+             /* Update the buffer index and the rx buffer */
+        	 bufferIdx[hwInstance] += DMA_SIZE;
+         	Uart_SetBuffer(hwInstance,&RX_Buffer[hwInstance][bufferIdx[hwInstance]],DMA_SIZE,UART_RECEIVE);
+             //Lpuart_Uart_Ip_SetRxBuffer(hwInstance, &RX_Buffer[bufferIdx], DMA_SIZE);
+         }
+     }
+     if (event == LPUART_UART_IP_EVENT_ERROR)
+     {
+//     	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
+//     	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
+//     	/*Add the remaining data size to the sum of the received size*/
+//     	bufferIdx[hwInstance] += temp;
+         /*Abort the receiving after detecting IDLE receiving*/
+     	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
+ //    	bufferIdx = 0;
+     }
+     if( event == LPUART_UART_IP_EVENT_RECV_IDLE)
+     {
+     	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
+ 		temp = DMA_SIZE - (uint32_t)IP_DMA->TCD[hwInstance].CITER.ELINKNO;
+ 		/*Add the remaining data size to the sum of the received size*/
+ 		bufferIdx[hwInstance] += temp;
+ 		/*Abort the receiving after detecting IDLE receiving*/
+ 		Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
+ //		rxSuccess = true;
+     }
+ }
+
+ /*CAN*/
+ Can_PduType Can_CreatePduInfo(Can_IdType id, CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8 *sdu)
+ {
+     Can_PduType PduInfo;
+     switch (idFrame)
+     {
+     case CAN_STANDARD_ID_TYPE:
+         id = id & 0x7FF;
+         break;
+     case CANFD_STANDARD_ID_TYPE:
+         id = (id & 0x7FF) | 0x40000000;
+         break;
+     case CAN_EXTENDED_ID_TYPE:
+         id = id | 0x80000000;
+         break;
+     case CANFD_EXTENDED_ID_TYPE:
+         id = id | 0xC0000000;
+         break;
+     default:
+         id = id & 0x7FF;
+         break;
+     }
+     PduInfo.id = id;
+     PduInfo.swPduHandle = swPduHandle;
+     PduInfo.length = length;
+     PduInfo.sdu = sdu;
+
+     return PduInfo;
+ }
+ Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg)
+ {
+     volatile Can_PduType Can_PduInfo;
+     volatile Std_ReturnType CAN_Write_Status;
+     Std_ReturnType retVal = E_NOT_OK;
+     uint32 u8TimeOut = 100*100;
+     Can_HwHandleType Hth = Can0HardwareObject_TX + (Can_HwHandleType)ControllerId; // controller 0 --> Can0HardwareObject_TX
+
+     Can_PduInfo = Can_CreatePduInfo(CanMsg.id, CanMsg.idFrame, 0, CanMsg.length, CanMsg.sdu);
+
+     CAN_Write_Status = Can_Write(Hth, &Can_PduInfo);
+
+     CanIf_bTxFlag = FALSE;
+     if (CAN_Write_Status == E_OK)
+     {
+         while ((!CanIf_bTxFlag) && (u8TimeOut != 0U))
+         {
+             Can_MainFunction_Write();
+             u8TimeOut--;
+         }
+     }
+
+     if (CanIf_bTxFlag == TRUE)
+     {
+         retVal = E_OK;
+     }
+     else
+     {
+         retVal = E_NOT_OK;
+     }
+     return retVal;
+ }
+ Can_Msg_Type Can_GetMsgInfo(Can_IdType id, uint8 length, uint8 *sdu)
+ {
+     Can_Msg_Type CanMsgInfo;
+
+     CanMsgInfo.idFrame = (CAN_IdFrameType)((id >> 30) & 0x03);
+     if (CanMsgInfo.idFrame & 0x01)
+     {
+         CanMsgInfo.id = id & 0x7FF;
+     }
+     else
+     {
+         CanMsgInfo.id = id & 0x1FFFFFFF;
+     }
+     CanMsgInfo.length = length;
+     CanMsgInfo.sdu = sdu;
+
+     return CanMsgInfo;
+ }
+
+ void CanIf_ControllerBusOff(uint8 ControllerId)
+ {
+     (void)ControllerId;
+ }
+
+ void CanIf_ControllerModeIndication(uint8 ControllerId, Can_ControllerStateType ControllerMode)
+ {
+     (void)ControllerId;
+     (void)ControllerMode;
+ }
+ void CanIf_TxConfirmation(PduIdType CanTxPduId)
+ {
+     CanIf_u8TxConfirmCnt++;
+     CanIf_bTxFlag = TRUE;
+     (void)CanTxPduId;
+ }
+
+ void CanIf_RxIndication(const Can_HwType *Mailbox, const PduInfoType *PduInfoPtr)
+ {
+	 static portBASE_TYPE xHigherPriorityTaskWoken;
+	 xHigherPriorityTaskWoken = pdFALSE;
+	 Can_Msg_Type canRxMsg_Buff;
+     CanIf_bRxFlag = TRUE; // should not be delete
+     // should put the msg into message queue
+     canRxMsg_Buff = Can_GetMsgInfo(Mailbox->CanId, PduInfoPtr->SduLength, PduInfoPtr->SduDataPtr);
+     xQueueSendFromISR(CanRecvQueueHandle,&canRxMsg_Buff,&xHigherPriorityTaskWoken);
+//     xQueueSend(CanRecvQueueHandle,&canRxMsg_Buff,1000);
+ }
+
+ void CanIf_CurrentIcomConfiguration(uint8 ControllerId, IcomConfigIdType ConfigurationId, IcomSwitch_ErrorType Error)
+ {
+     (void)ControllerId;
+     (void)ConfigurationId;
+     (void)Error;
+ }
+

+ 86 - 0
src/hal_adapter.h

@@ -0,0 +1,86 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2022-01-23 13:52:10
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2022-01-23 16:10:21
+ * @Description  : file content
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AT_CMD\hal_adapter.h
+ */
+/*
+ * hal_adapter.h
+ *中间层函数调用库
+ *  Created on: 2022年1月18日
+ *      Author: QiXiang_CHENJIE
+ */
+
+#ifndef HAL_ADAPTER_H_
+#define HAL_ADAPTER_H_
+ #include "Mcal.h"
+ #include "CAN.h"
+ #include "SchM_Can.h"
+ #include "Mcu.h"
+ #include "Mcl.h"
+ #include "Port.h"
+ #include "Dio.h"
+ #include "Uart.h"
+ #include "Platform.h"
+ #include "Lpuart_Uart_Ip_Irq.h"
+ #include "Flexio_Uart_Ip_Irq.h"
+ #include <string.h>
+ #include <stdlib.h>
+ #include "Dma_Ip.h"
+ #include "Dma_Ip_Irq.h"
+ #include "Lpuart_Uart_Ip.h"
+ #include "FreeRTOS.h"
+ #include "timers.h"
+ #include "task.h"
+ #include "semphr.h"
+ #define UART_LPUART0 0
+ #define UART_LPUART1 1
+ #define UART_LPUART2 2
+ #define FLEXIO_RX 3
+ #define FLEXIO_TX 4
+ #define main_TASK_PRIORITY                ( tskIDLE_PRIORITY + 2 )
+
+ #define MSG_LEN 50U
+ #define TJA1153_START_ID (uint32_t)(0x555u)
+ #define TJA1153_CONFIG_ID (uint32_t)(0x18DA00F1u)
+
+ #define BUFFER_SIZE 200
+ #define DMA_SIZE 20
+ extern uint8_t RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];
+ Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout);
+ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout);
+ Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer,uint16 *rxlen, sint32 T_timeout);
+ void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event);
+
+ /*CAN*/
+ typedef enum
+ {
+     CAN_STANDARD_ID_TYPE = 0x00,   /**< * -00b CAN message with Standard CAN ID  */
+     CANFD_STANDARD_ID_TYPE = 0x01, /**< * -01b CAN FD frame with Standard CAN ID  */
+     CAN_EXTENDED_ID_TYPE = 0x02,   /**< * -10b CAN message with Extended CAN ID  */
+     CANFD_EXTENDED_ID_TYPE = 0x03, /**< * -11b CAN FD frame with Extended CAN ID  */
+ } CAN_IdFrameType;
+
+ typedef struct
+ {
+     Can_IdType id;
+
+     CAN_IdFrameType idFrame;
+
+     uint8 length; /**< @brief DLC = Data Length Code (part of L-PDU that describes
+                                             the SDU length). */
+     uint8 *sdu;   /**< @brief CAN L-SDU = Link Layer Service Data
+                                                            Unit. Data that is transported inside
+                                                            the L-PDU. */
+ } Can_Msg_Type;
+ typedef struct
+ {
+	 Can_IdType id;
+	 uint8 length;
+	 uint8 data[8];
+ }Can_Msg_Type_Data;
+ extern Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg);
+#endif /* HAL_ADAPTER_H_ */

+ 59 - 705
src/main.c

@@ -23,12 +23,11 @@
 ==================================================================================================*/
 
 /**
-*   @file main.c
-*
-*   @addtogroup main_module main module documentation
-*   @{
-*/
-
+ *   @file main.c
+ * 主函数入口
+ *   @addtogroup main_module main module documentation
+ *   @{
+ */
 
 /* Including necessary configuration files. */
 #include "Mcal.h"
@@ -42,747 +41,102 @@
 #include "Platform.h"
 #include "Lpuart_Uart_Ip_Irq.h"
 #include "Flexio_Uart_Ip_Irq.h"
-
-//extern ISR(CAN0_ORED_IRQHandler);
-//extern ISR(CAN0_ORED_0_31_MB_IRQHandler);
-//extern ISR(CAN0_ORED_32_63_MB_IRQHandler);
-//extern ISR(CAN0_ORED_64_95_MB_IRQHandler);
-//extern ISR(CAN1_ORED_IRQHandler);
-//extern ISR(CAN1_ORED_0_31_MB_IRQHandler);
-//extern ISR(CAN1_ORED_32_63_MB_IRQHandler);
-
-
-
-
-
-
-/* User includes */
-
-#include <string.h>
-
-
-#define UART_LPUART0  0
-#define UART_LPUART1  1
-#define UART_LPUART2  2
-#define FLEXIO_RX  3
-#define FLEXIO_TX  4
-
-//#define UART_LPUART6_RS485  3
-
-
-/* Welcome messages displayed at the console */
-#define WELCOME_MSG_1 "AT"
-#define WELCOME_MSG_2 "123345678\r\n"
-#define WELCOME_MSG_3 "\r\nThis example is an simple echo using LPUART\r\n\
-		it will send back any character you send to it.\r\n\
-		The board will greet you if you send 'Hello Board'\r\
-		\nNow you can begin typing:\r\n"
-
-
-/* Error message displayed at the console, in case data is received erroneously */
-#define ERROR_MSG "An error occurred! The application will stop!\r\n"
-
-/* Length of the message to be received from the console */
-#define MSG_LEN  50U
-#define TJA1153_START_ID   (uint32_t)(0x555u)
-#define TJA1153_CONFIG_ID  (uint32_t)(0x18DA00F1u)
-
 #include "Dma_Ip.h"
 #include "Dma_Ip_Irq.h"
 #include "Lpuart_Uart_Ip.h"
-
-#define BUFFER_SIZE 500
-#define DMA_SIZE 200
-/*the Rx buffer need to be put in non cacheable section when cache enabled*/
-uint8_t __attribute__ ((section(".non_cacheable_data"))) RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];
-
-/*==================================================================================================
-*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
-==================================================================================================*/
-
-
-/*==================================================================================================
-*                                       LOCAL MACROS
-==================================================================================================*/
-
-
-/*==================================================================================================
-*                                      LOCAL CONSTANTS
-==================================================================================================*/
-
-
-/*==================================================================================================
-*                                      LOCAL VARIABLES
-==================================================================================================*/
-
-
-/*==================================================================================================
-*                                      GLOBAL CONSTANTS
-==================================================================================================*/
-
-uint8 Can_au8Sdu8bytes[8U] = {0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08};
-volatile uint8 pinValue = STD_LOW;
-uint8 dummyData[64] = {1,2,3,4,5,6,7,8};
-
-/*==================================================================================================
-*                                      GLOBAL VARIABLES
-==================================================================================================*/
-uint8 CanIf_u8TxConfirmCnt = 0U;
-boolean CanIf_bTxFlag = FALSE;
-uint8 CanIf_u8RxIndicationCnt = 0U;
-boolean CanIf_bRxFlag = FALSE;
-
-
-/*==================================================================================================
-*                                   LOCAL FUNCTION PROTOTYPES
-==================================================================================================*/
-void TestDelay(uint32 delay);
-
-/*==================================================================================================
-*                                       LOCAL FUNCTIONS
-==================================================================================================*/
-
-
-/*==================================================================================================
-*                                       GLOBAL FUNCTIONS
-==================================================================================================*/
-#if 1
-typedef enum
-{
-    CAN_STANDARD_ID_TYPE            =  0x00, /**< * -00b CAN message with Standard CAN ID  */
-	CANFD_STANDARD_ID_TYPE  		=  0x01, /**< * -01b CAN FD frame with Standard CAN ID  */
-	CAN_EXTENDED_ID_TYPE            =  0x02, /**< * -10b CAN message with Extended CAN ID  */
-	CANFD_EXTENDED_ID_TYPE       	=  0x03, /**< * -11b CAN FD frame with Extended CAN ID  */
-} CAN_IdFrameType;
-
-typedef struct
-{
-    Can_IdType id;
-
-    CAN_IdFrameType idFrame;
-
-    uint8 length; /**< @brief DLC = Data Length Code (part of L-PDU that describes
-                                            the SDU length). */
-    uint8 * sdu; /**< @brief CAN L-SDU = Link Layer Service Data
-                                                          Unit. Data that is transported inside
-                                                          the L-PDU. */
-} Can_Msg_Type;
-
-
-Can_Msg_Type canRxMsg_Buff[100];
-
-Can_PduType Can_CreatePduInfo(Can_IdType id,CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8* sdu)
-{
-    Can_PduType PduInfo;
-    switch(idFrame)
-    {
-    case CAN_STANDARD_ID_TYPE:
-    	id = id & 0x7FF;
-    	break;
-    case CANFD_STANDARD_ID_TYPE:
-    	id = (id & 0x7FF) | 0x40000000;
-    	break;
-    case CAN_EXTENDED_ID_TYPE:
-    	id = id | 0x80000000;
-    	break;
-    case CANFD_EXTENDED_ID_TYPE:
-    	id = id | 0xC0000000;
-    	break;
-    default:
-    	id = id & 0x7FF;
-    	break;
-
-    }
-    PduInfo.id = id;
-    PduInfo.swPduHandle = swPduHandle;
-    PduInfo.length = length;
-    PduInfo.sdu = sdu;
-
-    return PduInfo;
-}
-
-Can_Msg_Type Can_GetMsgInfo(Can_IdType id, uint8 length, uint8* sdu)
-{
-	Can_Msg_Type CanMsgInfo;
-
-
-	CanMsgInfo.idFrame = (CAN_IdFrameType)((id>>30) &0x03);
-	if(CanMsgInfo.idFrame&0x01)
-	{
-		CanMsgInfo.id = id&0x7FF;
-	}
-	else
-	{
-		CanMsgInfo.id = id&0x1FFFFFFF;
-	}
-	CanMsgInfo.length = length;
-	CanMsgInfo.sdu = sdu;
-
-    return CanMsgInfo;
-}
-
-void CanIf_ControllerBusOff(uint8 ControllerId)
-{
-    (void)ControllerId;
-}
-
-void CanIf_ControllerModeIndication(uint8 ControllerId, Can_ControllerStateType ControllerMode )
-{
-    (void)ControllerId;
-    (void)ControllerMode;
-}
-void CanIf_TxConfirmation(PduIdType CanTxPduId)
-{
-    CanIf_u8TxConfirmCnt++;
-    CanIf_bTxFlag = TRUE;
-    (void)CanTxPduId;
-}
-
-void CanIf_RxIndication(const Can_HwType* Mailbox, const PduInfoType* PduInfoPtr )
-{
-
-    CanIf_bRxFlag = TRUE;  //should not be delete
-//    (void)Mailbox;
-//    (void)PduInfoPtr;
-
-    // should put the msg into message quene
-    canRxMsg_Buff[CanIf_u8RxIndicationCnt] = Can_GetMsgInfo(Mailbox->CanId,PduInfoPtr->SduLength,PduInfoPtr->SduDataPtr);
-    CanIf_u8RxIndicationCnt++;
-}
-
-void CanIf_CurrentIcomConfiguration( uint8 ControllerId, IcomConfigIdType  ConfigurationId, IcomSwitch_ErrorType Error)
-{
-	(void)ControllerId;
-	(void)ConfigurationId;
-	(void)Error;
-}
-
-void Can_DummyDelay(uint32 loops)
-{
-    VAR( volatile uint32, CAN_VAR) data = 0xAA55AA55;
-    VAR( volatile uint32, CAN_VAR) contor1 = 0;
-    VAR( volatile uint32, CAN_VAR) contor2 = loops;
-
-    do
-    {
-        for (contor1 = 0; contor1 < 0x2FF; contor1++)
-        {
-            data ^= (1 << contor1) | (0xAAAAAA | contor2);
-        }
-        contor2--;
-    } while( contor2 > 0);
-}
-
-
-
-Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg)
-{
-	volatile Can_PduType Can_PduInfo;
-	volatile Std_ReturnType CAN_Write_Status;
-	Std_ReturnType retVal = E_NOT_OK;
-	uint8 u8TimeOut = 100U;
-	Can_HwHandleType Hth = Can0HardwareObject_TX + (Can_HwHandleType)ControllerId;  //controller 0 --> Can0HardwareObject_TX
-
-	Can_PduInfo = Can_CreatePduInfo(CanMsg.id,CanMsg.idFrame, 0, CanMsg.length, CanMsg.sdu);
-
-	CAN_Write_Status = Can_Write(Hth, &Can_PduInfo);
-
-	CanIf_bTxFlag = FALSE;
-	if(CAN_Write_Status == E_OK)
-	{
-		while((!CanIf_bTxFlag) && (u8TimeOut != 0U))
-		{
-			Can_MainFunction_Write();
-			Can_DummyDelay(100U);
-			u8TimeOut--;
-		}
-	}
-
-	if(CanIf_bTxFlag == TRUE)
-	{
-		retVal = E_OK;
-	}
-	else
-	{
-		retVal = E_NOT_OK;
-	}
-	return retVal;
-}
-
-#endif
-
-
-void TestDelay(uint32 delay)
-{
-    static volatile uint32 DelayTimer = 0;
-    while(DelayTimer<delay)
-    {
-        DelayTimer++;
-    }
-    DelayTimer=0;
-}
-
-//boolean User_Str_Cmp(const uint8 * txBuffer1, const uint8 * txBuffer2, const uint32 length)
-//{
-//    uint32 idx = 0;
-//    for (idx = 0; idx < length; idx++)
-//    {
-//        if(txBuffer1[idx] != txBuffer2[idx])
-//        {
-//            return FALSE;
-//        }
-//    }
-//    return TRUE;
-//}
-
-
-uint32_t bufferIdx;
-uint8 rxSuccess = false;
-
-Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8* txBuffer,  uint32 sendLength, uint8* rxBuffer, uint32 T_timeout)
-{
-    volatile Std_ReturnType R_Uart_Status;
-    volatile Std_ReturnType T_Uart_Status;
-    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
-    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
-    uint32 T_bytesRemaining;
-    uint32 timeout = T_timeout;
-    uint32 retVal = E_NOT_OK;
-    bufferIdx = 0;
-//    uint8 Rx_Buffer[MSG_LEN];
-
-
-    /* Uart_AsyncReceive transmit data */
-//    IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(0);
-    if(txBuffer == NULL || rxBuffer == NULL)
-    {
-    	return retVal;
-    }
-
-   	Uart_SetBuffer(recvChannel,&RX_Buffer[recvChannel][0],DMA_SIZE,UART_RECEIVE);
-   	R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
-   	if (E_OK != R_Uart_Status)
-   	{
-   		Uart_Abort(recvChannel,UART_RECEIVE);
-   		return E_NOT_OK;
-   	}
-
-
-    /* Uart_AsyncSend transmit data */
-    Uart_SetBuffer(transChannel,txBuffer,sendLength,UART_SEND);
-    T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
-    if (E_OK != T_Uart_Status)
-    {
-    	Uart_Abort(transChannel,UART_SEND);
-        return E_NOT_OK;
-    }
-
-
-    /* Check for no on-going transmission */
-    do
-    {
-        Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
-        Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
-    } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
-
-    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
-	{
-    	Uart_Abort(transChannel,UART_SEND);
-    	retVal = E_NOT_OK;
-	}
-    else
-    {
-    	retVal = E_OK;
-    }
-
-    if((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
-    {
-    	Uart_Abort(recvChannel,UART_RECEIVE);
-//    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
-    	retVal = E_NOT_OK;
-    }
-    else
-    {
-    	retVal = E_OK;
-    }
-    return retVal;
-}
-
-Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8* txBuffer,  uint32 sendLength, uint32 T_timeout)
-{
-
-    volatile Std_ReturnType T_Uart_Status;
-    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
-    uint32 T_bytesRemaining;
-    uint32 timeout = T_timeout;
-    uint32 retVal = E_NOT_OK;
-//    uint8 Rx_Buffer[MSG_LEN];
-
-    if(txBuffer == NULL)
-    {
-    	return retVal;
-    }
-
-    /* Uart_AsyncSend transmit data */
-    Uart_SetBuffer(transChannel,txBuffer,sendLength,UART_SEND);
-    T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
-    if (E_OK != T_Uart_Status)
-    {
-    	Uart_Abort(transChannel,UART_SEND);
-        return E_NOT_OK;
-    }
-
-    /* Check for no on-going transmission */
-    do
-    {
-        Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
-    } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));
-
-    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
-	{
-    	Uart_Abort(transChannel,UART_SEND);
-    	retVal = E_NOT_OK;
-	}
-    else
-    {
-    	retVal = E_OK;
-    }
-    return retVal;
-}
-
-uint32 UART_Receive_Data(uint8 recvChannel, uint8* rxBuffer, uint32 T_timeout)
-{
-    volatile Std_ReturnType R_Uart_Status;
-    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
-    uint32 T_bytesRemaining;
-    uint32 timeout = T_timeout;
-    uint32 retVal = E_NOT_OK;
-//    uint8 Rx_Buffer[MSG_LEN];
-    bufferIdx = 0;
-
-    if(rxBuffer == NULL)
-    {
-    	return retVal;
-    }
-    /* Uart_AsyncReceive transmit data */
-//   	Uart_SetBuffer(recvChannel,rxBuffer,DMA_SIZE,UART_RECEIVE);
-   	R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
-   	if (E_OK != R_Uart_Status)
-   	{
-//   		Uart_Abort(recvChannel,UART_RECEIVE);
-   		return E_NOT_OK;
-   	}
-
-    /* Check for no on-going transmission */
-    do
-    {
-        Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
-    } while ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus ) && 0< timeout--);
-
-
-    if((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
-    {
-    	Uart_Abort(recvChannel,UART_RECEIVE);
-    	retVal = E_NOT_OK;
-    }
-    else
-    {
-    	retVal = E_OK;
-    }
-    return retVal;
-}
-
-
-
-
 /* User includes */
 
-
-void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event)
-{
-
-
-//    (void)userData;
-    uint32_t temp;
-
-
-    /* Check the event type */
-    if (event == LPUART_UART_IP_EVENT_RX_FULL)
-    {
-        /* The reception stops when receiving idle is detected or the buffer is full */
-        if (bufferIdx <= (BUFFER_SIZE - DMA_SIZE))
-        {
-            /* Update the buffer index and the rx buffer */
-        	bufferIdx += DMA_SIZE;
-        	Uart_SetBuffer(hwInstance,&RX_Buffer[hwInstance][bufferIdx],DMA_SIZE,UART_RECEIVE);
-            //Lpuart_Uart_Ip_SetRxBuffer(hwInstance, &RX_Buffer[bufferIdx], DMA_SIZE);
-        }
-    }
-    if (event == LPUART_UART_IP_EVENT_ERROR)
-    {
-    	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
-    	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
-    	/*Add the remaining data size to the sum of the received size*/
-    	bufferIdx += temp;
-        /*Abort the receiving after detecting IDLE receiving*/
-    	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
-//    	bufferIdx = 0;
-    }
-    if( event == LPUART_UART_IP_EVENT_RECV_IDLE)
-    {
-
-    	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
-		temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
-		/*Add the remaining data size to the sum of the received size*/
-		bufferIdx += temp;
-		/*Abort the receiving after detecting IDLE receiving*/
-
-		Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
-		//Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2,STD_ON);
-//		rxSuccess = true;
-    }
-}
-/*!
-  \brief The main function for the project.
-  \details The startup initialization sequence is the following:
- * - startup asm routine
- * - main()
-*/
+#include <string.h>
+#include "hal_adapter.h"
 #include "Lpuart_Uart_Ip.h"
+
+#include "AppTaskUart1.h"
 int main(void)
 {
-    /* Write your code here */
-	volatile Std_ReturnType T_Uart_Status1;
-	volatile Std_ReturnType T_Uart_Status2;
-	volatile Std_ReturnType T_Uart_Status3;
-	volatile Std_ReturnType R_Uart_Status1;
-	volatile Std_ReturnType R_Uart_Status2;
-	static Can_Msg_Type Can_MsgInfo;
-//	static Can_PduType Can_PduInfo1;
-	volatile Std_ReturnType CAN_Write_Status;
-	uint8 rxBuffer[100];
-
-	uint8 u8TimeOut = 100U;
-	CanIf_bTxFlag = FALSE;
-	CanIf_bRxFlag = FALSE;
-
-
-
-    /* Initialize the Mcu driver */
+	volatile int exit_code = 0;
+	/* Initialize the Mcu driver */
 #if (MCU_PRECOMPILE_SUPPORT == STD_ON)
-    Mcu_Init(NULL_PTR);
+	Mcu_Init(NULL_PTR);
 #elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
-    Mcu_Init(&Mcu_Config_VS_0);
+	Mcu_Init(&Mcu_Config_VS_0);
 #endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */
 
 	Mcu_InitClock(McuClockSettingConfig_0);
 
 	/* Wait until PLL is locked */
-	//while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
+	// while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
 	{
 		/* Busy wait until the System PLL is locked */
 	}
-	//Mcu_DistributePllClock();
+	// Mcu_DistributePllClock();
 	/* Initialize Mcl module */
 	Mcl_Init(NULL_PTR);
 
 	Mcu_SetMode(McuModeSettingConf_0);
 	OsIf_Init(NULL_PTR);
 	Platform_Init(NULL_PTR);
-    Platform_InstallIrqHandler(LPUART0_RxTx_IRQn, LPUART_UART_IP_0_IRQHandler, NULL_PTR);
-//    Platform_InstallIrqHandler(LPUART1_RxTx_IRQn, LPUART_UART_IP_1_IRQHandler, NULL_PTR);
-//    Platform_InstallIrqHandler(LPUART2_RxTx_IRQn, LPUART_UART_IP_2_IRQHandler, NULL_PTR);
-//    Platform_InstallIrqHandler(FLEXIO_IRQn, MCL_FLEXIO_ISR, NULL_PTR);
-//    Platform_InstallIrqHandler(DMA0_IRQn,Dma0_Ch0_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(DMA1_IRQn,Dma0_Ch1_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(DMA2_IRQn,Dma0_Ch2_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(DMA3_IRQn,Dma0_Ch3_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(DMA4_IRQn,Dma0_Ch4_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(DMA5_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
-
-//    Platform_InstallIrqHandler(CAN0_ORed_IRQn,IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(CAN0_Error_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(CAN0_Wake_Up_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(CAN0_ORed_0_15_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
-//    Platform_InstallIrqHandler(CAN0_ORed_16_31_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(LPUART0_RxTx_IRQn, LPUART_UART_IP_0_IRQHandler, NULL_PTR);
+	//    Platform_InstallIrqHandler(LPUART1_RxTx_IRQn, LPUART_UART_IP_1_IRQHandler, NULL_PTR);
+	//    Platform_InstallIrqHandler(LPUART2_RxTx_IRQn, LPUART_UART_IP_2_IRQHandler, NULL_PTR);
+	//    Platform_InstallIrqHandler(FLEXIO_IRQn, MCL_FLEXIO_ISR, NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA0_IRQn,Dma0_Ch0_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA1_IRQn,Dma0_Ch1_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA2_IRQn,Dma0_Ch2_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA3_IRQn,Dma0_Ch3_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA4_IRQn,Dma0_Ch4_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(DMA5_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
+
+	//    Platform_InstallIrqHandler(CAN0_ORed_IRQn,IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(CAN0_Error_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(CAN0_Wake_Up_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(CAN0_ORed_0_15_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
+	//    Platform_InstallIrqHandler(CAN0_ORed_16_31_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
 
 	/* Initialize all pins*/
-#if(PORT_PRECOMPILE_SUPPORT == STD_ON)
+#if (PORT_PRECOMPILE_SUPPORT == STD_ON)
 	Port_Init(NULL_PTR);
-#elif(PORT_PRECOMPILE_SUPPORT == STD_OFF)
+#elif (PORT_PRECOMPILE_SUPPORT == STD_OFF)
 	Port_Init(&Port_Config_VS_0);
 #endif
 
 	/* Initializes an UART driver*/
 #if (UART_PRECOMPILE_SUPPORT == STD_ON)
 	Uart_Init(NULL_PTR);
-#elif(UART_PRECOMPILE_SUPPORT == STD_OFF)
+#elif (UART_PRECOMPILE_SUPPORT == STD_OFF)
 	Uart_Init(&Uart_xConfig_VS_0);
 #endif
 
-
-
-#if 1	/* Initialize Platform driver */
-
-
+#if 1 /* Initialize Platform driver */
 #if (CAN_PRECOMPILE_SUPPORT == STD_ON)
 	Can_Init(NULL_PTR);
-#elif(CAN_PRECOMPILE_SUPPORT == STD_OFF)
+#elif (CAN_PRECOMPILE_SUPPORT == STD_OFF)
 	Can_Init(&Can_Config_VS_0);
 #endif
 	Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
-
 #endif
-#if 0
-	Platform_InstallIrqHandler(FlexCAN0_0_IRQn, CAN0_ORED_IRQHandler, NULL);
-	Platform_SetIrq(FlexCAN0_0_IRQn, TRUE);
-	Platform_InstallIrqHandler(FlexCAN0_1_IRQn, CAN0_ORED_0_15_MB_IRQHandler, NULL);
-	Platform_SetIrq(FlexCAN0_1_IRQn, TRUE);
-	Platform_InstallIrqHandler(FlexCAN0_2_IRQn, CAN0_ORED_16_31_MB_IRQHandler, NULL);
-	Platform_SetIrq(FlexCAN0_2_IRQn, TRUE);
-
-
-//	Platform_InstallIrqHandler(FlexCAN1_0_IRQn, CAN1_ORED_IRQHandler, NULL);
-//	Platform_SetIrq(FlexCAN1_0_IRQn, TRUE);
-//	Platform_InstallIrqHandler(FlexCAN0_1_IRQn, CAN1_ORED_0_31_MB_IRQHandler, NULL);
-//	Platform_SetIrq(FlexCAN1_1_IRQn, TRUE);
-//	Platform_InstallIrqHandler(FlexCAN1_2_IRQn, CAN1_ORED_32_63_MB_IRQHandler, NULL);
-//	Platform_SetIrq(FlexCAN1_2_IRQn, TRUE);
-#endif
-
-
-	//Dio_WriteChannel(DioConf_DioChannel_LED, STD_HIGH);
-
-	//Dio_WriteChannel(DioConf_DioChannel_DIO_TEST, value);
-	/* Send greeting string 1 from Flexio_0_Tx */
-	//T_Uart_Status1 = Send_Data(UART_LPUART0_INTERNAL_CHANNEL, (const uint8 *)WELCOME_MSG_1, strlen(WELCOME_MSG_1));
-
-	/* Send greeting string 2 from Flexio_0_Tx */
-	//T_Uart_Status2 = Send_Data(UART_LPUART0_INTERNAL_CHANNEL, (const uint8 *)WELCOME_MSG_2, strlen(WELCOME_MSG_2));
-
-	/* Can_CreatePduInfo(id, swPduHandle,length, sdu) */
-//	Can_PduInfo = Can_CreatePduInfo(0x55U, CAN_EXTENDED_ID_TYPE, 0U, 8U, Can_au8Sdu8bytes);
-//	Can_PduInfo1 = Can_CreatePduInfo(0x66U, 0U, 2U, Can_au8Sdu8bytes);
-	Can_MsgInfo.id = 0x18123456;
-	Can_MsgInfo.idFrame = CAN_EXTENDED_ID_TYPE;
-	Can_MsgInfo.length = 8;
-	Can_MsgInfo.sdu = Can_au8Sdu8bytes;
-
-	  /* Initilize Can driver */
-
-	//Can_Init(&Can_Config_VS_0);
-
-//	Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
-//	Dio_WriteChannel(DioConf_DioChannel_PTE4_GPIO_OUT_MCU_4G_POW_EN,STD_ON);  //使能power
-//	Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_ON); //正向脉冲使其开机
-	//TestDelay(5000000);
-	//Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_OFF);
-
-//	Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_ON); //DTR 拉低
-//	TestDelay(80000000);
-	//Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_OFF); //DTR 拉低
-
-//	Dio_WriteChannel(PortConfigSet_PortContainer_GPIO_PTE7_GPIO_OUT_MCU_BT_MOD,STD_ON);
-	Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN,STD_ON);
-	//TestDelay(100000);
-	//Dio_WriteChannel(DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET,STD_OFF);
-	//DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET
-	//My_Tja1153_Init();
-//	Uart_SetBuffer(UART_LPUART0,&RX_Buffer[UART_LPUART0][0],DMA_SIZE,UART_RECEIVE);
-
-	/*Config LPUART0 idle length*/
-//	IP_LPUART0->CTRL |= LPUART_CTRL_IDLECFG(7);
-		/*Start count idle bit when detected stop bit*/
-	IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
-	while (1)
-	  {
-		//Can_MainFunction_Write();
-		//Can_MainFunction_Read();
-		 /* Toggle the LED when the Gpt notification is called */
-
-		  pinValue = ~pinValue;
-//		  Dio_WriteChannel(PortConfigSet_PortContainer_GPIO_PTE9_GPIO_OUT_MCU_BT_POW_EN,pinValue);
-//		  Dio_WriteChannel(DioConf_DioChannel_PTA29_GPIO_OUT_MCU_LED3,pinValue);
-//		  Dio_WriteChannel(DioConf_DioChannel_DioChannel_LED0,pinValue);
-//		  Dio_WriteChannel(DioConf_DioChannel_DioChannel_LED1,pinValue);
-
-//		  CAN_Write_Status = Can_Write(Can0HardwareObject_TX, &Can_PduInfo);
-		  //Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_IdType id,CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8* sdu)
-//		  CanIf_SendMessage(0,Can_MsgInfo);
-
-//		  if(CAN_Write_Status == E_OK)
-//		  {
-//			  while((!CanIf_bTxFlag) && (u8TimeOut != 0U))
-//			  {
-//					Can_MainFunction_Write();
-//					Can_DummyDelay(100U);
-//					u8TimeOut--;
-//			  }
-//		  }
-//		  u8TimeOut = 100U;
-//		  CanIf_bTxFlag = false;
-//		  TestDelay(100000);
-//		  while((!CanIf_bRxFlag) && (u8TimeOut != 0U))
-//		  {
-//			  Can_MainFunction_Read();
-//			  Can_DummyDelay(100U);
-//			  u8TimeOut--;
-//		  }
-//		  u8TimeOut = 100U;
-//		  CanIf_bRxFlag = false;
-//
-//
-//
-//		  TestDelay(10000);
-
-//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
-//		  bufferIdx = 0;
-//		  /* Send greeting string 2 from Flexio_0_Tx */
-//		  T_Uart_Status1 = UART_Query_Data(UART_LPUART2,UART_LPUART2, (const uint8 *)WELCOME_MSG_1,y  strlen(WELCOME_MSG_1), RX_Buffer[UART_LPUART2], 100000);
-
-		  //Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1,STD_ON);
-
-
-
-		  memset(RX_Buffer[UART_LPUART0],0,BUFFER_SIZE);
-		  IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
-		  Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN,STD_OFF);
-//		  TestDelay(100);
-		  UART_Receive_Data(UART_LPUART0, RX_Buffer[UART_LPUART0], 100000000);
-
-
-//		  TestDelay(1000);
-
-		  if(strlen(RX_Buffer[UART_LPUART0]) != 0)
-		  {
-			  Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN,STD_ON);
-			  RX_Buffer[UART_LPUART0][0] = 0x30;
-			  UART_Send_Data(UART_LPUART0, (const uint8 *)RX_Buffer[UART_LPUART0],  strlen(RX_Buffer[UART_LPUART0]), 100000);
-		  }
-//
-//
-//
-//		  TestDelay(1000);
-//
-
-
-
-
-
-//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
-//		  bufferIdx = 0;
-//		  T_Uart_Status2 = UART_Query_Data(UART_LPUART0_RS232,UART_LPUART0_RS232, (const uint8 *)WELCOME_MSG_2,  strlen(WELCOME_MSG_2), RX_Buffer[UART_LPUART0_RS232], 100000);
-//		  //TestDelay(1000);
-////		  memset(rxBuffer,0,100);
-////		  R_Uart_Status2 = Rece_Data(UART_LPUART0_RS232, rxBuffer, strlen(WELCOME_MSG_2),0xFFFF);
-//		  //TestDelay(2000000);
-//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
-//		  bufferIdx = 0;
-//		  T_Uart_Status3 = UART_Query_Data(UART_LPUART0_RS232,UART_LPUART0_RS232, (const uint8 *)WELCOME_MSG_3,  strlen(WELCOME_MSG_3), RX_Buffer[UART_LPUART0_RS232], 100000);
-
-	 }
-
-
+	//	Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
+	//	Dio_WriteChannel(DioConf_DioChannel_PTE4_GPIO_OUT_MCU_4G_POW_EN,STD_ON);  //使能power
+	//	Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_ON);
+	// Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_OFF);
+
+	//	Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_ON); //DTR 拉低
+	// Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_OFF); //DTR 拉低
+
+	//	Dio_WriteChannel(PortConfigSet_PortContainer_GPIO_PTE7_GPIO_OUT_MCU_BT_MOD,STD_ON);
+	//	Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN,STD_ON);
+	// Dio_WriteChannel(DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET,STD_OFF);
+	// DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET
+	IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
+	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 256 + 64, (void *)0, main_TASK_PRIORITY, NULL);
+	vTaskStartScheduler();
+	for (;;)
+	{
+		if (exit_code != 0)
+		{
+			break;
+		}
+	}
+	return exit_code;
 }
 
 /** @} */