void CANFD0_TxTest(CANFD_T *psCanfd, uint8_t cnt)
{
switch (cnt)
{
case 0:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt0 == 0) break;
}
psCanfd->TXBAR = 1 << 0 ;
break;
case 1:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt0 == 0) break;
}
psCanfd->TXBAR = 1 << 1 ;
break;
default:
break ;
}
}
void CANFD1_TxTest(CANFD_T *psCanfd, uint8_t cnt)
{
switch (cnt)
{
case 0:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt1 == 0) break;
}
psCanfd->TXBAR = 1 << 0 ;
break;
case 1:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt1 == 0) break;
}
psCanfd->TXBAR = 1 << 1 ;
break;
default:
break ;
}
}
void CANFD2_TxTest(CANFD_T *psCanfd, uint8_t cnt)
{
switch (cnt)
{
case 0:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt2 == 0) break;
}
psCanfd->TXBAR = 1 << 0 ;
break;
case 1:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt2 == 0) break;
}
psCanfd->TXBAR = 1 << 1 ;
break;
default:
break ;
}
}
void CANFD3_TxTest(CANFD_T *psCanfd, uint8_t cnt)
{
switch (cnt)
{
case 0:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt3 == 0) break;
}
psCanfd->TXBAR = 1 << 0 ;
break;
case 1:
while (CANFD_GET_COMMUNICATION_STATE(psCanfd) != eCANFD_IDLE)
{
if (--u32TimeOutCnt3 == 0) break;
}
psCanfd->TXBAR = 1 << 1 ;
break;
default:
break ;
}
}
void CANFD0_Init(void)
{
CANFD_FD_T sCANFD_Config0;
SYS_ResetModule(CANFD0_RST);
CANFD_GetDefaultConfig(&sCANFD_Config0, CANFD_OP_CAN_FD_MODE);
sCANFD_Config0.sBtConfig.sNormBitRate.u32BitRate = 500000;
sCANFD_Config0.sBtConfig.sDataBitRate.u32BitRate = 2000000;
CANFD_Open(CANFD0, &sCANFD_Config0);
}
void CANFD1_Init(void)
{
CANFD_FD_T sCANFD_Config1;
SYS_ResetModule(CANFD1_RST);
CANFD_GetDefaultConfig(&sCANFD_Config1, CANFD_OP_CAN_FD_MODE);
sCANFD_Config1.sBtConfig.sNormBitRate.u32BitRate = 500000;
sCANFD_Config1.sBtConfig.sDataBitRate.u32BitRate = 2000000;
CANFD_Open(CANFD1, &sCANFD_Config1);
}
void CANFD2_Init(void)
{
CANFD_FD_T sCANFD_Config2;
SYS_ResetModule(CANFD2_RST);
CANFD_GetDefaultConfig(&sCANFD_Config2, CANFD_OP_CAN_FD_MODE);
sCANFD_Config2.sBtConfig.sNormBitRate.u32BitRate = 500000;
sCANFD_Config2.sBtConfig.sDataBitRate.u32BitRate = 2000000;
CANFD_Open(CANFD2, &sCANFD_Config2);
}
void CANFD3_Init(void)
{
CANFD_FD_T sCANFD_Config3;
SYS_ResetModule(CANFD3_RST);
CANFD_GetDefaultConfig(&sCANFD_Config3, CANFD_OP_CAN_FD_MODE);
sCANFD_Config3.sBtConfig.sNormBitRate.u32BitRate = 500000;
sCANFD_Config3.sBtConfig.sDataBitRate.u32BitRate = 2000000;
CANFD_Open(CANFD3, &sCANFD_Config3);
}
int32_t main(void)
{
SYS_UnlockReg(); // Unlock protected registers
SYS_Init(); // Init System, peripheral clock and multi-function I/O
UART_Open(UART0, 115200); // Init UART to 115200-8n1 for print message
SYS_ResetModule(CANFD0_RST);
CANFD0->CCCR = CANFD_CCCR_CCE_Msk | CANFD_CCCR_INIT_Msk | CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk;
SYS_ResetModule(CANFD1_RST);
CANFD1->CCCR = CANFD_CCCR_CCE_Msk | CANFD_CCCR_INIT_Msk | CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk;
SYS_ResetModule(CANFD2_RST);
CANFD2->CCCR = CANFD_CCCR_CCE_Msk | CANFD_CCCR_INIT_Msk | CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk;
SYS_ResetModule(CANFD3_RST);
CANFD3->CCCR = CANFD_CCCR_CCE_Msk | CANFD_CCCR_INIT_Msk | CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk;
CANFD0_Init();
CANFD1_Init();
CANFD2_Init();
CANFD3_Init();
CANFD0_TX_fifo_Init();
CANFD1_TX_fifo_Init();
CANFD2_TX_fifo_Init();
CANFD3_TX_fifo_Init();
CANFD0_Tx_Init(CANFD0, 2, 7, 0);
CANFD0->CCCR = CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk ; // Write is OK after 2 CLKs
CANFD1_Tx_Init(CANFD1, 2, 7, 0);
CANFD1->CCCR = CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk ; // Write is OK after 2 CLKs
CANFD2_Tx_Init(CANFD2, 2, 7, 0);
CANFD2->CCCR = CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk ; // Write is OK after 2 CLKs
CANFD3_Tx_Init(CANFD3, 2, 7, 0);
CANFD3->CCCR = CANFD_CCCR_BRSE_Msk | CANFD_CCCR_FDOE_Msk ; // Write is OK after 2 CLKs
SYS_LockReg();
TIM1_Init();
u32TimeOutCnt0 = CANFD_TIMEOUT;
u32TimeOutCnt1 = CANFD_TIMEOUT;
u32TimeOutCnt2 = CANFD_TIMEOUT;
u32TimeOutCnt3 = CANFD_TIMEOUT;
while (1)
{
CANFD0_TxTest(CANFD0, u8Item);
CANFD1_TxTest(CANFD1,u8Item);
CANFD2_TxTest(CANFD2,u8Item);
CANFD3_TxTest(CANFD3,u8Item);
}
}
|