|
@@ -6,276 +6,443 @@
|
|
|
*/
|
|
|
#include "hal_adapter.h"
|
|
|
#include "AppGlobalVar.h"
|
|
|
-/*NB*/
|
|
|
-/**
|
|
|
- * @brief :??????
|
|
|
- * @param {UINT8} *pSend
|
|
|
- * @param {UINT32} sendLen
|
|
|
- * @param {UINT8} *pRead
|
|
|
- * @param {UINT32} readLen
|
|
|
- * @param {UINT32} timeout
|
|
|
- * @return {*}
|
|
|
- */
|
|
|
-/*
|
|
|
-UINT8 UartTramsit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UINT32 timeout)
|
|
|
+uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[3][BUFFER_SIZE];
|
|
|
+uint32_t bufferIdx[3] = {0};
|
|
|
+
|
|
|
+ volatile Uart_StatusType Uart_TransmitStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
|
|
|
+ QueueHandle_t UartRecvQueue[3];
|
|
|
+ QueueHandle_t UartSendQueue[3];
|
|
|
+ QueueHandle_t UartHalQueueHandle;
|
|
|
+ void Uart_Hal_RecvTask(void *pvParameters);
|
|
|
+ void Uart_Hal_SendTask(void *pvParameters);
|
|
|
+ Std_ReturnType UartStartRecvFunc(uint8 channel);
|
|
|
+Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 **rxBuffer, uint16 *rxlen, uint32 T_timeout)
|
|
|
{
|
|
|
- UartBufferPtr UartData = {NULL, 0};
|
|
|
- uint8 ReadLen = 0;
|
|
|
- if (pSend)
|
|
|
- {
|
|
|
- HAL_UART_SendStr(PORT_USART_0, pSend, sendLen);
|
|
|
- }
|
|
|
- if (readLen > 0)
|
|
|
- {
|
|
|
- osStatus_t ret = osMessageQueueGet(uart0DataHandle, &UartData, 0, timeout);
|
|
|
- if (ret == osOK)
|
|
|
- {
|
|
|
- if (UartData.dataPtr != NULL)
|
|
|
- {
|
|
|
- memcpy(pRead, (UINT8 *)UartData.dataPtr, UartData.len);
|
|
|
- free(UartData.dataPtr);
|
|
|
- }
|
|
|
- UartData.dataPtr = NULL;
|
|
|
- ReadLen = UartData.len;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- osDelayUntil(1000);
|
|
|
- osMessageQueueReset(uart0DataHandle);
|
|
|
- memset(pRead, 0x00, readLen);
|
|
|
- ReadLen = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- return ReadLen;
|
|
|
+ UartMsg_t UartRecvMsg;
|
|
|
+ UartMsg_t UartSendMsg;
|
|
|
+ BaseType_t Sendret = pdFALSE;
|
|
|
+ BaseType_t Recvret = pdFALSE;
|
|
|
+ uint32 retVal = E_NOT_OK;
|
|
|
+ UartSendMsg.DataLen = sendLength;
|
|
|
+ UartSendMsg.dataPrt = txBuffer;
|
|
|
+ *rxlen = 0;
|
|
|
+ Sendret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,10);
|
|
|
+
|
|
|
+ memset(&UartRecvMsg,0,sizeof(UartMsg_t));
|
|
|
+
|
|
|
+ if(Sendret == pdTRUE)
|
|
|
+ {
|
|
|
+ Recvret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
|
|
|
+ if(Recvret == pdTRUE)
|
|
|
+ {
|
|
|
+ *rxlen = UartRecvMsg.DataLen;
|
|
|
+ *rxBuffer = UartRecvMsg.dataPrt;
|
|
|
+ retVal = E_OK;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
}
|
|
|
-*/
|
|
|
- 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_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;
|
|
|
- }
|
|
|
- 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)
|
|
|
+Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 **rxBuffer, uint16 *rxlen, sint32 T_timeout)
|
|
|
+{
|
|
|
+ UartMsg_t UartRecvMsg;
|
|
|
+ BaseType_t ret = pdFALSE;
|
|
|
+ uint32 retVal = E_NOT_OK;
|
|
|
+ *rxlen = 0;
|
|
|
+ ret = xQueueReceive(UartRecvQueue[recvChannel],&UartRecvMsg,T_timeout);
|
|
|
+ if(ret == pdTRUE)
|
|
|
+ {
|
|
|
+ *rxlen = UartRecvMsg.DataLen;
|
|
|
+ *rxBuffer = UartRecvMsg.dataPrt;
|
|
|
+ retVal = E_OK;
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
+}
|
|
|
+Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout)
|
|
|
+{
|
|
|
+ UartMsg_t UartSendMsg;
|
|
|
+ BaseType_t ret = pdFALSE;
|
|
|
+ uint32 retVal = E_NOT_OK;
|
|
|
+ UartSendMsg.DataLen = sendLength;
|
|
|
+ UartSendMsg.dataPrt = txBuffer;
|
|
|
+ ret = xQueueSend(UartSendQueue[transChannel],&UartSendMsg,T_timeout);
|
|
|
+ if(ret == pdTRUE)
|
|
|
+ {
|
|
|
+ retVal = E_OK;
|
|
|
+ }
|
|
|
+ return retVal;
|
|
|
+}
|
|
|
+ void UartInit(void)
|
|
|
{
|
|
|
- Uart_Abort(recvChannel, UART_RECEIVE);
|
|
|
- return E_NOT_OK;
|
|
|
+ UartRecvQueue[0] = xQueueCreate(3, sizeof(UartMsg_t));
|
|
|
+ UartRecvQueue[1] = xQueueCreate(3, sizeof(UartMsg_t));
|
|
|
+ UartRecvQueue[2] = xQueueCreate(3, sizeof(UartMsg_t));
|
|
|
+ UartSendQueue[0] = xQueueCreate(1, sizeof(UartMsg_t));
|
|
|
+ UartSendQueue[1] = xQueueCreate(1, sizeof(UartMsg_t));
|
|
|
+ UartSendQueue[2] = xQueueCreate(1, sizeof(UartMsg_t));
|
|
|
+ UartHalQueueHandle = xQueueCreate(6, sizeof(UartHalMsg_t));
|
|
|
+
|
|
|
+ xTaskCreate(Uart_Hal_RecvTask, (const char *const)"UartRecv", 1024, (void *)0, main_TASK_PRIORITY + 3, NULL);
|
|
|
+ xTaskCreate(Uart_Hal_SendTask, (const char *const)"UartSend", 1024, (void *)0, main_TASK_PRIORITY + 2, NULL);
|
|
|
}
|
|
|
-
|
|
|
- /* Check for no on-going transmission */
|
|
|
- do
|
|
|
+ Std_ReturnType UartStartRecvFunc(uint8 channel)
|
|
|
{
|
|
|
- if(Uart_TransmitStatus != UART_STATUS_NO_ERROR)
|
|
|
- {
|
|
|
- Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
|
|
|
- }
|
|
|
- if(Uart_ReceiveStatus != UART_STATUS_NO_ERROR)
|
|
|
+ sint8 out = 0;
|
|
|
+ volatile Std_ReturnType R_Uart_Status=E_NOT_OK;
|
|
|
+ bufferIdx[channel]=0;
|
|
|
+ memset(RX_Buffer[channel],0x00,BUFFER_SIZE);
|
|
|
+ switch(channel)
|
|
|
{
|
|
|
- Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
|
|
|
+ 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;
|
|
|
}
|
|
|
- vTaskDelay(pdMS_TO_TICKS(1));
|
|
|
- } 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;
|
|
|
+ Uart_SetBuffer(channel, RX_Buffer[channel], DMA_SIZE, UART_RECEIVE);
|
|
|
+ R_Uart_Status = Uart_AsyncReceive(channel, RX_Buffer[channel], DMA_SIZE);
|
|
|
+ if (E_OK != R_Uart_Status)
|
|
|
+ {
|
|
|
+ Uart_Abort(channel, UART_RECEIVE);
|
|
|
+ out = E_NOT_OK;
|
|
|
+ }
|
|
|
+ return out;
|
|
|
}
|
|
|
- else
|
|
|
+ void Uart_Hal_RecvTask(void *pvParameters)
|
|
|
{
|
|
|
- retVal = E_OK;
|
|
|
- }
|
|
|
- if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
|
|
|
- {
|
|
|
- Uart_Abort(recvChannel, UART_RECEIVE);
|
|
|
- *rxlen = bufferIdx[recvChannel];
|
|
|
- //IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
|
|
|
- retVal = E_NOT_OK;
|
|
|
+ UartMsg_t UartMsg;
|
|
|
+ UartHalMsg_t UartHalMsgRecv;
|
|
|
+ BaseType_t ret = pdFALSE;
|
|
|
+ uint32 T_bytesRemaining[3] = {0};
|
|
|
+ uint16 T_timeout[3] = {0};
|
|
|
+ volatile Uart_StatusType Uart_ReceiveStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
|
|
|
+ uint8 UartIdx = UART_LPUART0;
|
|
|
+ uint8 UartState[3] = {UartAbortRecv,UartAbortRecv,UartAbortRecv};
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ if((T_timeout[UartIdx]>1000) && (Uart_ReceiveStatus[UartIdx] != UART_STATUS_NO_ERROR) )//判定UART停止,超时停止,不是接收状态则停止
|
|
|
+ {
|
|
|
+ Uart_Abort(UartIdx, UART_RECEIVE);
|
|
|
+ UartState[UartIdx] = UartAbortRecv;
|
|
|
+ T_timeout[UartIdx] = 0;
|
|
|
+ }
|
|
|
+ else if(Uart_ReceiveStatus[UartIdx] == UART_STATUS_NO_ERROR)
|
|
|
+ {
|
|
|
+ UartState[UartIdx] = UartRecvComplete;
|
|
|
+ }
|
|
|
+
|
|
|
+ if((UartState[UartIdx] == UartAbortRecv) || (UartState[UartIdx] == UartRecvComplete)) //判定UART开始接收:UART停止后开始接收
|
|
|
+ {
|
|
|
+ if(E_OK == UartStartRecvFunc(UartIdx))
|
|
|
+ {
|
|
|
+ UartState[UartIdx] = UartStartRecv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = xQueueReceive(UartHalQueueHandle,&UartHalMsgRecv,1);
|
|
|
+
|
|
|
+ Uart_ReceiveStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_RECEIVE);
|
|
|
+ T_timeout[UartIdx]++;
|
|
|
+ UartIdx = (UartIdx + 1) > 2 ? 0 : (UartIdx + 1);
|
|
|
+
|
|
|
+
|
|
|
+ if(ret==pdTRUE)
|
|
|
+ {
|
|
|
+ if(UartHalMsgRecv.event==LPUART_UART_IP_EVENT_RECV_IDLE)
|
|
|
+ {
|
|
|
+ UartMsg.DataLen = UartHalMsgRecv.value;
|
|
|
+// UartMsg.dataPrt = RX_Buffer[UartHalMsgRecv.Channel];
|
|
|
+
|
|
|
+ UartMsg.dataPrt = malloc(UartMsg.DataLen);
|
|
|
+ memset(UartMsg.dataPrt,0,UartMsg.DataLen);
|
|
|
+ memcpy(UartMsg.dataPrt,RX_Buffer[UartHalMsgRecv.Channel],UartMsg.DataLen);
|
|
|
+
|
|
|
+ xQueueSendToFront(UartRecvQueue[UartHalMsgRecv.Channel],&UartMsg,1);
|
|
|
+
|
|
|
+ T_timeout[UartHalMsgRecv.Channel] = 0;
|
|
|
+ UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
|
|
|
+
|
|
|
+// Uart_ReceiveStatus[UartHalMsgRecv.Channel] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_RECEIVE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ void Uart_Hal_SendTask(void *pvParameters)
|
|
|
{
|
|
|
- *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);
|
|
|
- vTaskDelay(pdMS_TO_TICKS(1));
|
|
|
- } 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;
|
|
|
- }
|
|
|
+ UartMsg_t UartSendMsg;
|
|
|
+ BaseType_t ret = pdFALSE;
|
|
|
+ uint32 T_bytesRemaining[3] = {0};
|
|
|
+ uint16 T_timeout[3] = {0};
|
|
|
+ volatile Std_ReturnType T_Uart_Status[3];
|
|
|
+ uint8 UartIdx = UART_LPUART0;
|
|
|
+ uint8 UartSendState[3] = {UartNoDataSend,UartNoDataSend,UartNoDataSend};
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ ret = xQueueReceive(UartSendQueue[UartIdx],&UartSendMsg,1);
|
|
|
+ if(ret==pdTRUE)
|
|
|
+ {
|
|
|
+ T_Uart_Status[UartIdx] = Uart_AsyncSend(UartIdx, UartSendMsg.dataPrt, UartSendMsg.DataLen);
|
|
|
+ if (E_OK != T_Uart_Status[UartIdx])
|
|
|
+ {
|
|
|
+ Uart_Abort(UartIdx, UART_SEND);
|
|
|
+ UartSendState[UartIdx] = UartAbortSend;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UartSendState[UartIdx] = UartStartSend;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*开始发送后的判定*/
|
|
|
+ if(UartSendState[UartIdx] == UartStartSend)
|
|
|
+ {
|
|
|
+ Uart_TransmitStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_SEND);
|
|
|
+ T_timeout[UartIdx]++;
|
|
|
+ }
|
|
|
+ if(T_timeout[UartIdx]>=1000 || ((Uart_TransmitStatus[UartIdx] != UART_STATUS_OPERATION_ONGOING) && (UartSendState[UartIdx] == UartStartSend)))
|
|
|
+ {
|
|
|
+ if(T_timeout[UartIdx]>=1000)
|
|
|
+ {
|
|
|
+ Uart_Abort(UartIdx, UART_SEND);
|
|
|
+ UartSendState[UartIdx] = UartAbortSend;
|
|
|
+ }
|
|
|
+ else if(Uart_TransmitStatus[UartIdx] == UART_STATUS_NO_ERROR)
|
|
|
+ {
|
|
|
+ UartSendState[UartIdx] = UartSendComplete;
|
|
|
+ }
|
|
|
+ T_timeout[UartIdx] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ UartIdx = (UartIdx + 1) > 2 ? 0 : (UartIdx + 1);
|
|
|
+ }
|
|
|
|
|
|
- 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 = bufferIdx[recvChannel];
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- else 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;
|
|
|
- }
|
|
|
- else 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;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- temp = 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;
|
|
|
+// 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_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;
|
|
|
+// }
|
|
|
+// 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
|
|
|
+// {
|
|
|
+// 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));
|
|
|
+// 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);
|
|
|
+// *rxlen = bufferIdx[recvChannel];
|
|
|
+// 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;
|
|
|
+// if (txBuffer == NULL)
|
|
|
+// {
|
|
|
+// return retVal;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /* Uart_AsyncSend transmit data */
|
|
|
+// 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);
|
|
|
+// vTaskDelay(pdMS_TO_TICKS(1));
|
|
|
+// } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));
|
|
|
+//
|
|
|
+// if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
|
|
|
+// {
|
|
|
+// 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 = bufferIdx[recvChannel];
|
|
|
+// retVal = E_NOT_OK;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// *rxlen = bufferIdx[recvChannel];
|
|
|
+// retVal = E_OK;
|
|
|
+// }
|
|
|
+// return retVal;
|
|
|
+//}
|
|
|
+extern Lpuart_Uart_Ip_StateStructureType *Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
|
|
|
+void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event)
|
|
|
+{
|
|
|
+ // (void)userData;
|
|
|
+ Lpuart_Uart_Ip_StateStructureType * UartState;
|
|
|
+ UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[hwInstance];
|
|
|
+ /* 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);
|
|
|
+ Lpuart_Uart_Ip_AbortSendingData(hwInstance);
|
|
|
+ // bufferIdx = 0;
|
|
|
+ }
|
|
|
+ if (event == LPUART_UART_IP_EVENT_RECV_IDLE)
|
|
|
+ {
|
|
|
+ uint32_t temp;
|
|
|
+ UartHalMsg_t UartHalMsg;
|
|
|
+ UartHalMsg.Channel = hwInstance;
|
|
|
+ UartHalMsg.event = event;
|
|
|
+ /*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*/
|
|
|
+ UartState->IsRxBusy = FALSE;
|
|
|
+ UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
|
|
|
+ Lpuart_Uart_Ip_CompleteReceiveUsingDma(hwInstance);
|
|
|
+ UartHalMsg.value = bufferIdx[hwInstance];
|
|
|
+ xQueueSendFromISR(UartHalQueueHandle,&UartHalMsg,pdFALSE);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
/*CAN*/
|
|
|
Can_PduType Can_CreatePduInfo(Can_IdType id, CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8 *sdu)
|