Browse Source

版本号:1.1,2.1,蓝牙串口优化,任务优先级更改

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
ec5e39f766

+ 7 - 5
FreeRTOS/Source/include/FreeRTOSConfig.h

@@ -58,7 +58,7 @@
 #define configENABLE_BACKWARD_COMPATIBILITY         1
 #define configUSE_POSIX_ERRNO                       0
 #define configUSE_APPLICATION_TASK_TAG              0
-#define configRECORD_STACK_HIGH_ADDRESS             1
+#define configRECORD_STACK_HIGH_ADDRESS             0
 
 /* Definition assert() function. */
 #define configASSERT(x)                             if((x)==0) { taskDISABLE_INTERRUPTS(); for( ;; ); }
@@ -72,7 +72,7 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 /* Memory allocation related definitions. */
 #define configSUPPORT_STATIC_ALLOCATION             0
 #define configSUPPORT_DYNAMIC_ALLOCATION            1
-#define configTOTAL_HEAP_SIZE                       (( size_t ) 8192*2 )
+#define configTOTAL_HEAP_SIZE                       (( size_t ) 8192*4 )
 #define configAPPLICATION_ALLOCATED_HEAP            0
 
 /* Hook function related definitions. */
@@ -91,7 +91,7 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 
 /* Co-routine related definitions. */
 #define configUSE_CO_ROUTINES                       0
-#define configMAX_CO_ROUTINE_PRIORITIES             14
+#define configMAX_CO_ROUTINE_PRIORITIES             2
 
 /* SEMAPHORES and MUTEXS */
 #define configUSE_MUTEXES                           1
@@ -100,10 +100,12 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 
 /* Software timer related definitions. */
 #define configUSE_TIMERS                            1
-#define configTIMER_TASK_PRIORITY                   2
+#define configTIMER_TASK_PRIORITY                   14
 #define configTIMER_QUEUE_LENGTH                    10
 #define configTIMER_TASK_STACK_DEPTH                256
 
+#define configIDLE_TASK_STACK_DEPTH					512
+
 /* Tickless Idle Mode */
 #define configUSE_TICKLESS_IDLE                     0
 
@@ -148,7 +150,7 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 
 /* The lowest interrupt priority that can be used in a call to a "set priority"
 function. */
-#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY  (0x0F)
+#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY  (0x01)
 
 /* Interrupt priorities used by the kernel port layer itself.  These are generic
 to all Cortex-M ports, and do not rely on any particular library functions. */

+ 1 - 1
generate/include/Lpuart_Uart_Ip_Defines.h

@@ -86,7 +86,7 @@ extern "C"{
 #define LPUART_UART_IP_TIMEOUT_TYPE                 (OSIF_COUNTER_SYSTEM)
 
 /* @brief Number of loops before returning LPUART_STATUS_TIMEOUT.*/
-#define LPUART_UART_IP_TIMEOUT_VALUE_US             (500000U)
+#define LPUART_UART_IP_TIMEOUT_VALUE_US             (10000U)  //zhengchao
 
 /* @brief LPUART DMA support */
 #define LPUART_UART_IP_HAS_DMA_ENABLED              (STD_ON)

+ 15 - 15
generate/src/IntCtrl_Ip_Cfg.c

@@ -61,12 +61,12 @@ extern "C" {
 
 /* List of configurations for interrupts */
 static const IntCtrl_Ip_IrqConfigType aIrqConfiguration[] = {
-    {DMA0_IRQn, (boolean)TRUE, 0U},
-    {DMA1_IRQn, (boolean)TRUE, 0U},
-    {DMA2_IRQn, (boolean)TRUE, 0U},
-    {DMA3_IRQn, (boolean)TRUE, 3U},
-    {DMA4_IRQn, (boolean)TRUE, 3U},
-    {DMA5_IRQn, (boolean)TRUE, 3U},
+    {DMA0_IRQn, (boolean)TRUE, 6U},
+    {DMA1_IRQn, (boolean)TRUE, 6U},
+    {DMA2_IRQn, (boolean)TRUE, 6U},
+    {DMA3_IRQn, (boolean)TRUE, 7U},
+    {DMA4_IRQn, (boolean)TRUE, 7U},
+    {DMA5_IRQn, (boolean)TRUE, 7U},
     {DMA6_IRQn, (boolean)FALSE, 0U},
     {DMA7_IRQn, (boolean)FALSE, 0U},
     {DMA8_IRQn, (boolean)FALSE, 0U},
@@ -83,16 +83,16 @@ static const IntCtrl_Ip_IrqConfigType aIrqConfiguration[] = {
     {FTFC_Read_Collision_IRQn, (boolean)FALSE, 0U},
     {LVD_LVW_IRQn, (boolean)FALSE, 0U},
     {FTFC_Fault_IRQn, (boolean)FALSE, 0U},
-    {WDOG_EWM_IRQn, (boolean)FALSE, 0U},
+    {WDOG_EWM_IRQn, (boolean)TRUE, 5U},
     {RCM_IRQn, (boolean)FALSE, 0U},
     {LPI2C0_Master_IRQn, (boolean)FALSE, 0U},
     {LPI2C0_Slave_IRQn, (boolean)FALSE, 0U},
     {LPSPI0_IRQn, (boolean)FALSE, 0U},
     {LPSPI1_IRQn, (boolean)FALSE, 0U},
     {LPSPI2_IRQn, (boolean)FALSE, 0U},
-    {LPUART0_RxTx_IRQn, (boolean)TRUE, 0U},
-    {LPUART1_RxTx_IRQn, (boolean)TRUE, 0U},
-    {LPUART2_RxTx_IRQn, (boolean)TRUE, 0U},
+    {LPUART0_RxTx_IRQn, (boolean)TRUE, 6U},
+    {LPUART1_RxTx_IRQn, (boolean)TRUE, 6U},
+    {LPUART2_RxTx_IRQn, (boolean)TRUE, 6U},
     {ADC0_IRQn, (boolean)FALSE, 0U},
     {ADC1_IRQn, (boolean)FALSE, 0U},
     {CMP0_IRQn, (boolean)FALSE, 0U},
@@ -115,11 +115,11 @@ static const IntCtrl_Ip_IrqConfigType aIrqConfiguration[] = {
     {SWI_IRQn, (boolean)FALSE, 0U},
     {PDB1_IRQn, (boolean)FALSE, 0U},
     {FLEXIO_IRQn, (boolean)TRUE, 3U},
-    {CAN0_ORed_IRQn, (boolean)TRUE, 3U},
-    {CAN0_Error_IRQn, (boolean)TRUE, 3U},
-    {CAN0_Wake_Up_IRQn, (boolean)TRUE, 3U},
-    {CAN0_ORed_0_15_MB_IRQn, (boolean)TRUE, 3U},
-    {CAN0_ORed_16_31_MB_IRQn, (boolean)TRUE, 3U},
+    {CAN0_ORed_IRQn, (boolean)TRUE, 7U},
+    {CAN0_Error_IRQn, (boolean)TRUE, 7U},
+    {CAN0_Wake_Up_IRQn, (boolean)TRUE, 7U},
+    {CAN0_ORed_0_15_MB_IRQn, (boolean)TRUE, 7U},
+    {CAN0_ORed_16_31_MB_IRQn, (boolean)TRUE, 7U},
     {CAN1_ORed_IRQn, (boolean)FALSE, 0U},
     {CAN1_Error_IRQn, (boolean)FALSE, 0U},
     {CAN1_ORed_0_15_MB_IRQn, (boolean)FALSE, 0U},

+ 1 - 1
generate/src/OsIf_Cfg.c

@@ -138,7 +138,7 @@ extern "C"{
 static const OsIf_ConfigType OsIf_xPredefinedConfig =
 {
     /*.counterId */         0U,
-    /*.counterFrequency */  2000000U
+    /*.counterFrequency */  48000000U
 };
 
 #define BASE_STOP_SEC_CONFIG_DATA_UNSPECIFIED

+ 1 - 1
src/AppGlobalVar.c

@@ -16,7 +16,7 @@
 
 #include "AppGlobalVar.h"
 //*全局变量*//
-uint32 BleVersion = 0x01010101;         // ble的软件版本
+uint32 BleVersion = 0x01010201;         // ble的软件版本
 uint8 BleMacAddr[6];
 uint8 BleTargetMacAddr[6] = {0xBE, 0x84, 0xCC, 0x29, 0x3B, 0xCB};
 uint8 BleCurrentRole = 0;

+ 24 - 3
src/AppTaskBle.c

@@ -53,16 +53,21 @@ void BleTask(void *pvParameters)
 			{
 				if (BleConnectEnable == 1 && BleConnectFlg == 0) //主机蓝牙主动请求连接
 				{
+					Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD, STD_OFF);
 					AtcmdTransmit(AT_Conn, BleTargetMacAddr, sizeof(BleTargetMacAddr), AtCmdRead, &ret);
 					if (ret == 0) //连接成功
 					{
+						bleWorkState = 1;
 						BleConnectEnable = 0;
+						BleConnectFlg = 1;
 						BleDisconnectFlg = 0;
+						xSemaphoreGive(ConnSemaphore);
 					}
 					else
 					{
 						BleConnectFlg = 0;
 					}
+					Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD, STD_ON);
 				}
 			}
 			memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
@@ -74,6 +79,7 @@ void BleTask(void *pvParameters)
 				if (retptr)
 				{
 					bleWorkState = 1;
+					BleConnectEnable = 0;
 					BleConnectFlg = 1;
 					BleDisconnectFlg = 0;
 					xSemaphoreGive(ConnSemaphore);
@@ -214,7 +220,7 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	ATCmd_SendLen = ATCmd_SendLen + SetValueLen;
 	/**/
 	memset(RX_Buffer[UART_LPUART2], 0x00, sizeof(RX_Buffer[UART_LPUART2]));
-	UART_Query_Data(UART_LPUART2, UART_LPUART2, ATCmd_Send, ATCmd_SendLen, RX_Buffer[UART_LPUART2],&ReadLen, 1000*10);
+	UART_Query_Data(UART_LPUART2, UART_LPUART2, ATCmd_Send, ATCmd_SendLen, RX_Buffer[UART_LPUART2],&ReadLen, 1000);
 	memcpy(CmdRead, RX_Buffer[UART_LPUART2], 50);
 	/*
 	UartTramsit(ATCmd_Send, ATCmd_SendLen, CmdRead, 1, osWaitForever);
@@ -235,9 +241,9 @@ static void bleInit(void)
 		{
 		case 0: // AT同步
 		{
-			//			UartTramsit(NULL, 0, AtCmdRead, 1, 100);
+			//UartTramsit(NULL, 0, AtCmdRead, 1, 100);
 			uint16 Readlen = 0;
-			UART_Receive_Data(UART_LPUART2, AtCmdRead,&Readlen, 1000);
+			UART_Receive_Data(UART_LPUART2, AtCmdRead,&Readlen, 100);
 			memset(AtCmdRead, 0x00, sizeof(AtCmdRead));
 			AtcmdTransmit(AT_Cmd_Test, NULL, 0, AtCmdRead, &ret);
 			if (ret == 0)
@@ -492,6 +498,21 @@ sint8 at_callbackFunc(uint8 *PSendStr, uint8 *ptr, BleAtCmd CmdIdx)
 		}
 		break;
 	}
+	case AT_Conn:
+	{
+		pReadLen = ATstrdel((char *)ptr);
+//		retptr = (uint8 *)strstr((char *)ptr, (char *)("OK"));
+//		if (retptr)
+//		{
+//			returnvalue = 0;
+//		}
+		retptr = (uint8 *)strstr((char *)ptr, (char *)("ERR=-14"));//利用最大连接数错误判断连接成功
+		if(retptr)
+		{
+			returnvalue = 0;
+		}
+		break;
+	}
 	default:
 	{
 		pReadLen = ATstrdel((char *)ptr);

+ 5 - 3
src/AppTaskUart0.c

@@ -24,7 +24,7 @@ void UartTask(void *pvParameters)
 	char AtCmdRead[50+7];
 	uint8 temp[6] = {0xBE, 0xC8, 0xD9, 0xA2, 0xE2, 0x2B};
 	memcpy(&AtCmdRead[strlen(AtCmdRead)], temp, sizeof(temp));
-	char McuAtCmdAns[150] = {0};
+	char McuAtCmdAns[300] = {0};
 	uint8 McuAtCmdAnsLen;
 	uint8 RecvRet = 1;
 	uint16 ReadLen = 0;
@@ -239,10 +239,12 @@ sint8 McuAtCallbackFunc(char *Readptr,uint16 ReadLen, McuAtCmd McuAtIdx, char *A
 						//需要转换为ASCII码发出
 						for(uint8 i=0;i<DataLen;i++)
 						{
-							*(AnsPtr + *AnsPtrLen + i) = HexToChar(*(RecvDatabuffer.DataPtr+i));
+							*(AnsPtr + *AnsPtrLen + i*2 + 0) = HexToChar((*(RecvDatabuffer.DataPtr+i)>>4)&0x0F);
+							*(AnsPtr + *AnsPtrLen + i*2 + 1) = HexToChar((*(RecvDatabuffer.DataPtr+i)&0x0F));
 						}
+						*AnsPtrLen = *AnsPtrLen + DataLen*2;
 						//直接发出memcpy(AnsPtr + *AnsPtrLen,RecvDatabuffer.DataPtr,DataLen);
-						*AnsPtrLen = *AnsPtrLen + DataLen;
+						//*AnsPtrLen = *AnsPtrLen + DataLen;
 					}
 					else
 					{

+ 18 - 14
src/hal_adapter.c

@@ -84,15 +84,6 @@ UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UI
  {
      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);
@@ -101,12 +92,25 @@ UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UI
      Uart_Abort(transChannel, UART_SEND);
      return E_NOT_OK;
  }
+ 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;
+ }
 
  /* 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);
+	 if(Uart_TransmitStatus != UART_STATUS_NO_ERROR)
+	 {
+		 Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
+	 }
+	 if(Uart_ReceiveStatus != UART_STATUS_NO_ERROR)
+	 {
+		 Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
+	 }
      vTaskDelay(pdMS_TO_TICKS(1));
  } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
 
@@ -119,11 +123,11 @@ UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UI
  {
      retVal = E_OK;
  }
-
  if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
  {
      Uart_Abort(recvChannel, UART_RECEIVE);
-     //    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+     *rxlen = bufferIdx[recvChannel];
+     //IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
      retVal = E_NOT_OK;
  }
  else
@@ -221,7 +225,7 @@ UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UI
      if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
      {
          Uart_Abort(recvChannel, UART_RECEIVE);
-         *rxlen = 0;
+         *rxlen = bufferIdx[recvChannel];
          retVal = E_NOT_OK;
      }
      else

+ 3 - 3
src/main.c

@@ -175,9 +175,9 @@ int main(void)
     Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_BT_POW_EN,STD_ON);
     Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_BT_MOD,STD_ON);
 
-    xTaskCreate( BleTask, ( const char * const ) "BleTask", 256 + 64, (void*)0, main_TASK_PRIORITY , NULL );
-    xTaskCreate( CanTask, ( const char * const ) "CanTask" , 512, (void*)0, main_TASK_PRIORITY + 2, NULL );
-    xTaskCreate( UartTask, ( const char * const ) "UartTask" , 256, (void*)0, main_TASK_PRIORITY + 1, NULL );
+    xTaskCreate( BleTask, ( const char * const ) "BleTask", 512, (void*)0, main_TASK_PRIORITY + 2 , NULL );
+    xTaskCreate( UartTask, ( const char * const ) "UartTask" , 512, (void*)0, main_TASK_PRIORITY + 1, NULL );
+    xTaskCreate( CanTask, ( const char * const ) "CanTask" , 512, (void*)0, main_TASK_PRIORITY + 0, NULL );
     vTaskStartScheduler();
     for( ;; )
     {