/* $Id: xcan_polled_example.c,v 1.1.2.1 2009/12/02 11:23:41 svemula Exp $ */ /****************************************************************************** * * (c) Copyright 2005-2009 Xilinx, Inc. All rights reserved. * * This file contains confidential and proprietary information of Xilinx, Inc. * and is protected under U.S. and international copyright and other * intellectual property laws. * * DISCLAIMER * This disclaimer is not a license and does not grant any rights to the * materials distributed herewith. Except as otherwise provided in a valid * license issued to you by Xilinx, and to the maximum extent permitted by * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; * and (2) Xilinx shall not be liable (whether in contract or tort, including * negligence, or under any other theory of liability) for any loss or damage * of any kind or nature related to, arising under or in connection with these * materials, including for any direct, or any indirect, special, incidental, * or consequential loss or damage (including loss of data, profits, goodwill, * or any type of loss or damage suffered as a result of any action brought by * a third party) even if such damage or loss was reasonably foreseeable or * Xilinx had been advised of the possibility of the same. * * CRITICAL APPLICATIONS * Xilinx products are not designed or intended to be fail-safe, or for use in * any application requiring fail-safe performance, such as life-support or * safety devices or systems, Class III medical devices, nuclear facilities, * applications related to the deployment of airbags, or any other applications * that could lead to death, personal injury, or severe property or * environmental damage (individually and collectively, "Critical * Applications"). Customer assumes the sole risk and liability of any use of * Xilinx products in Critical Applications, subject only to applicable laws * and regulations governing limitations on product liability. * * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE * AT ALL TIMES. * ******************************************************************************/ /****************************************************************************/ /** * * @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_