|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/** @} */
|