/*===========================================================================*/ /* Project: F1x StarterKit V3 Sample Software */ /* Module : r_canfd.c */ /* Version: V1.00 */ /*===========================================================================*/ /* COPYRIGHT */ /*===========================================================================*/ /* Copyright (c) 2016 by Renesas Electronics Europe GmbH, */ /* a company of the Renesas Electronics Corporation */ /*===========================================================================*/ /* In case of any question please do not hesitate to contact: */ /* */ /* ABG Software Tool Support */ /* */ /* Renesas Electronics Europe GmbH */ /* Arcadiastrasse 10 */ /* D-40472 Duesseldorf, Germany */ /* */ /* e-mail: software_support-eu@lm.renesas.com */ /* FAX: +49 - (0)211 / 65 03 - 11 31 */ /* */ /*===========================================================================*/ /* Warranty Disclaimer */ /* */ /* Because the Product(s) is licensed free of charge, there is no warranty */ /* of any kind whatsoever and expressly disclaimed and excluded by Renesas, */ /* either expressed or implied, including but not limited to those for */ /* non-infringement of intellectual property, merchantability and/or */ /* fitness for the particular purpose. */ /* Renesas shall not have any obligation to maintain, service or provide bug */ /* fixes for the supplied Product(s) and/or the Application. */ /* */ /* Each User is solely responsible for determining the appropriateness of */ /* using the Product(s) and assumes all risks associated with its exercise */ /* of rights under this Agreement, including, but not limited to the risks */ /* and costs of program errors, compliance with applicable laws, damage to */ /* or loss of data, programs or equipment, and unavailability or */ /* interruption of operations. */ /* */ /* Limitation of Liability */ /* */ /* In no event shall Renesas be liable to the User for any incidental, */ /* consequential, indirect, or punitive damage (including but not limited */ /* to lost profits) regardless of whether such liability is based on breach */ /* of contract, tort, strict liability, breach of warranties, failure of */ /* essential purpose or otherwise and even if advised of the possibility of */ /* such damages. Renesas shall not be liable for any services or products */ /* provided by third party vendors, developers or consultants identified or */ /* referred to the User by Renesas in connection with the Product(s) and/or */ /* the Application. */ /* */ /*===========================================================================*/ /* History: */ /* V1.00: Initial version */ /* */ /*===========================================================================*/ /* */ /* Functions for CAN-FD initialization and testing. */ /* */ /*===========================================================================*/ /*===========================================================================*/ /* Includes */ /*===========================================================================*/ #include "r_device.h" #include "rscanfd/r_rscanfd.h" /* Peripheral Includes */ #include "port/r_port.h" /*===========================================================================*/ /* Variables */ /*===========================================================================*/ /* Create Can_FrameType for send and receive data */ const Canfd_FrameType CANFD_TraStandData={ //ID 0x18, 0, 0, 0, //DLC 0x0000, 0x00, 0x0, //0xB, //20 data bytes 0xF, //64 data bytes //Status 1, //ESI 1, //BRS 1, //FDF 0x0000, //data 64 { 0x12, //DB0 0x34, //DB1 0x56, //DB2 0x78, //DB3 // 0x87, //DB4 0x65, //DB5 0x43, //DB6 0x21, //DB7 0x12, //DB8 0x34, //DB9 0x56, //DB10 0x78, //DB11 // 0x87, //DB12 0x65, //DB13 0x43, //DB14 0x21, //DB15 0x12, //DB16 0x34, //DB17 0x56, //DB18 0x78, //DB19 // 0x87, //DB20 0x65, //DB21 0x43, //DB22 0x21, //DB23 0x12, //DB24 0x34, //DB25 0x56, //DB26 0x78, //DB27 // 0x87, //DB28 0x65, //DB29 0x43, //DB30 0x21, //DB31 0x12, //DB32 0x34, //DB33 0x56, //DB34 0x78, //DB35 // 0x87, //DB36 0x65, //DB37 0x43, //DB38 0x21, //DB39 0x12, //DB40 0x34, //DB41 0x56, //DB42 0x78, //DB43 // 0x87, //DB44 0x65, //DB45 0x43, //DB46 0x21, //DB47 0x12, //DB48 0x34, //DB49 0x56, //DB50 0x78, //DB51 // 0x87, //DB52 0x65, //DB53 0x43, //DB54 0x21, //DB55 0x12, //DB56 0x34, //DB57 0x56, //DB58 0x78, //DB59 // 0x87, //DB60 0x65, //DB61 0x43, //DB62 0x21 //DB63 //*/ } }; Canfd_FrameType CANFDRxFIFOData; /*===========================================================================*/ /* Variables */ /*===========================================================================*/ /***************************************************************************** ** Function: R_CANFD_Init ** Description: Configures CAN0 Channel 3 & 4 and the corresponding pins. ** Parameter: None ** Return: None ******************************************************************************/ void R_CANFD_Init(void) { R_PORT_SetAltFunc(Port1, 2, Alt1, Input); /* CAN3 RX */ R_PORT_SetAltFunc(Port1, 3, Alt1, Output); /* CAN3 TX*/ R_PORT_SetAltFunc(Port1, 12, Alt1, Input); /* CAN4 TX*/ R_PORT_SetAltFunc(Port1, 13, Alt1, Output); /* CAN4 RX */ /* Enable Transceiver CAN0 */ R_PORT_SetGpioOutput(Port1, 1, High); /* Enable Transceiver CAN1 */ R_PORT_SetGpioOutput(Port2, 6, High); R_RSCAN0FD_Init(); /* Initialize CAN3 and CAN4 into CANFD mode*/ } /***************************************************************************** ** Function: R_CANFD_Deinit ** Description: Configures used pins back to default. ** Parameter: None ** Return: None ******************************************************************************/ void R_CANFD_Deinit(void) { R_PORT_SetGpioHighZ(Port1, 2); R_PORT_SetGpioHighZ(Port1, 3); R_PORT_SetGpioHighZ(Port1, 12); R_PORT_SetGpioHighZ(Port1, 13); R_PORT_SetGpioHighZ(Port1, 1); R_PORT_SetGpioHighZ(Port2, 6); } /***************************************************************************** ** Function: R_CANFD_Test ** Description: Sends a CAN frame on channel 3 and compares with received data ** on channel 4. ** Parameter: None ** Return: R_OK - Received frame matches sent frame. ** R_ERROR - Mismatch detected. ******************************************************************************/ r_Error_t R_CANFD_Test(void) { uint32_t i, data_number; R_RSCAN0FD_C3TrmByTxBuf(0,&CANFD_TraStandData); //CANFD sending by CH 3 for(i=0; i<100000; i++) { __nop(); } ; //delay for CANFD receiving R_RSCANFD_ReadRxFIFOBuffer(&CANFDRxFIFOData); //CANFD CH4 receiving for(data_number=0; data_number<64; data_number++) { if(CANFDRxFIFOData.DB[data_number] != CANFD_TraStandData.DB[data_number]) { return R_ERROR; } } return R_OK; }