/****************************************************************************** * * Copyright (C) 2005 - 2014 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Use of the Software is limited solely to applications: * (a) running on a Xilinx device, or * (b) that interact with a Xilinx device through a bus or interconnect. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ /****************************************************************************/ /** * * @file xcan_polled_example.c * * Contains an example of how to use the XCan driver directly. The example here * shows using the driver/device in polled mode. * * @note * * * The Baud Rate Prescaler Register (BRPR) and Bit Timing Register (BTR) * are setup such that CAN baud rate equals 40Kbps, assuming that the * the CAN clock frequency is 24MHz. The user needs to modify these values * based on the desired baud rate and the CAN clock frequency. For more * information see the CAN 2.0A, CAN 2.0B, ISO 11898-1 specifications. * *
* MODIFICATION HISTORY: * * Ver Who Date Changes * ----- ----- -------- ----------------------------------------------- * 1.00a xd 04/12/05 First release * 2.00a ktn 10/22/09 Updated driver to use the HAL APIs/macros. * The macros have been renamed to remove _m from the name. ** ******************************************************************************/ /***************************** Include Files *********************************/ #include "xcan.h" #include "xparameters.h" #include "xstatus.h" /************************** Constant Definitions *****************************/ /* * The following constants map to the XPAR parameters created in the * xparameters.h file. They are defined here such that a user can easily * change all the needed parameters in one place. */ #define CAN_DEVICE_ID XPAR_CAN_0_DEVICE_ID /* * Maximum CAN frame length in words. */ #define XCAN_MAX_FRAME_SIZE_IN_WORDS (XCAN_MAX_FRAME_SIZE / sizeof(u32)) #define FRAME_DATA_LENGTH 8 /* Frame Data field length */ /* * Message Id Constant. */ #define TEST_MESSAGE_ID 2650 /* * The Baud Rate Prescaler Register (BRPR) and Bit Timing Register (BTR) * are setup such that CAN baud rate equals 40Kbps, assuming that the * the CAN clock frequency is 24MHz. The user needs to modify these values * based on the desired baud rate and the CAN clock frequency. For more * information see the CAN 2.0A, CAN 2.0B, ISO 11898-1 specifications. */ #define TEST_BRPR_BAUD_PRESCALAR 29 #define TEST_BTR_SYNCJUMPWIDTH 3 #define TEST_BTR_SECOND_TIMESEGMENT 2 #define TEST_BTR_FIRST_TIMESEGMENT 15 /**************************** Type Definitions *******************************/ /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ int XCanPolledExample(u16 DeviceId); static int SendFrame(XCan *InstancePtr); static int RecvFrame(XCan *InstancePtr); /************************** Variable Definitions *****************************/ /* * Buffers to hold frames to send and receive. These are declared as global so * that they are not on the stack. * These buffers need to be 32-bit aligned */ static u32 TxFrame[XCAN_MAX_FRAME_SIZE_IN_WORDS]; static u32 RxFrame[XCAN_MAX_FRAME_SIZE_IN_WORDS]; /* Driver instance */ static XCan Can; /*****************************************************************************/ /** * * Main function to call the example. This function is not included if the * example is generated from the TestAppGen test tool. * * @param None * * @return * - XST_SUCCESS if the example has completed successfully. * - XST_FAILURE if the example has failed. * * @note None * ******************************************************************************/ #ifndef TESTAPP_GEN int main(void) { /* * Run the Can Polled example, specify the Device ID that is generated * in xparameters.h . */ if (XCanPolledExample(CAN_DEVICE_ID)) { return XST_FAILURE; } return XST_SUCCESS; } #endif /*****************************************************************************/ /** * * The entry point for showing the XCan driver in polled mode. The example * configures the device for internal loopback mode, then sends a Can * frame, receives the same Can frame, and verifies the frame contents. * * @param DeviceId is the XPAR_CAN_