/****************************************************************************** * * (c) Copyright 2010-2013 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 xbram_example.c * * This file contains a self test example using the BRAM driver (XBram). * * *
* MODIFICATION HISTORY:
*
* Ver   Who  Date	 Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a sa   05/11/10 Initial release.
* 3.01a sa   13/01/12 Changed XBram_SelfTest(InstancePtr) to
* 			 XBram_SelfTest(InstancePtr,0) as per
*			 new API (CR 639274)
*
* ******************************************************************************/ /***************************** Include Files *********************************/ #include "xparameters.h" #include "xbram.h" #include /************************** 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 BRAM_DEVICE_ID XPAR_BRAM_0_DEVICE_ID /************************** Function Prototypes ******************************/ int BramExample(u16 DeviceId); static void InitializeECC(XBram_Config *ConfigPtr, u32 EffectiveAddr); /************************** Variable Definitions *****************************/ /* * The following are declared globally so they are zeroed and so they are * easily accessible from a debugger */ XBram Bram; /* The Instance of the BRAM Driver */ /****************************************************************************/ /** * * This function is the main function of the BRAM example. * * @param None. * * @return * - XST_SUCCESS to indicate success. * - XST_FAILURE to indicate failure. * * @note None. * *****************************************************************************/ #ifndef TESTAPP_GEN int main(void) { int Status; Status = BramExample(BRAM_DEVICE_ID); if (Status != XST_SUCCESS ) { xil_printf("Bram Example Test FAILED.\r\n"); return XST_FAILURE; } xil_printf("Bram Example Test PASSED.\r\n"); return XST_SUCCESS; } #endif /*****************************************************************************/ /** * * This is the entry point for the BRAM example. * * @param DeviceId is the XPAR__DEVICE_ID value from * xparameters.h * * @return * - XST_SUCCESS to indicate success. * - XST_FAILURE to indicate failure. * * @note None. * ******************************************************************************/ int BramExample(u16 DeviceId) { int Status; XBram_Config *ConfigPtr; /* * Initialize the BRAM driver. If an error occurs then exit */ /* * Lookup configuration data in the device configuration table. * Use this configuration info down below when initializing this * driver. */ ConfigPtr = XBram_LookupConfig(DeviceId); if (ConfigPtr == (XBram_Config *) NULL) { return XST_FAILURE; } Status = XBram_CfgInitialize(&Bram, ConfigPtr, ConfigPtr->CtrlBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } InitializeECC(ConfigPtr, ConfigPtr->CtrlBaseAddress); /* * Execute the BRAM driver selftest. */ Status = XBram_SelfTest(&Bram, 0); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; } /****************************************************************************/ /** * * This function ensures that ECC in the BRAM is initialized if no hardware * initialization is available. The ECC bits are initialized by reading and * writing data in the memory. This code is not optimized to only read data * in initialized sections of the BRAM. * * @param ConfigPtr is a reference to a structure containing information * about a specific BRAM device. * @param EffectiveAddr is the device base address in the virtual memory * address space. * * @return * None * * @note None. * *****************************************************************************/ void InitializeECC(XBram_Config *ConfigPtr, u32 EffectiveAddr) { u32 Addr; volatile u32 Data; if (ConfigPtr->EccPresent && ConfigPtr->EccOnOffRegister && ConfigPtr->EccOnOffResetValue == 0 && ConfigPtr->WriteAccess != 0) { for (Addr = ConfigPtr->MemBaseAddress; Addr < ConfigPtr->MemHighAddress; Addr+=4) { Data = XBram_In32(Addr); XBram_Out32(Addr, Data); } XBram_WriteReg(EffectiveAddr, XBRAM_ECC_ON_OFF_OFFSET, 1); } }