205 lines
5.9 KiB
C
205 lines
5.9 KiB
C
![]() |
/******************************************************************************
|
||
|
*
|
||
|
* Copyright (C) 2010 - 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 xbram_example.c
|
||
|
*
|
||
|
* This file contains a self test example using the BRAM driver (XBram).
|
||
|
*
|
||
|
*
|
||
|
* <pre>
|
||
|
* 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)
|
||
|
*</pre>
|
||
|
*
|
||
|
******************************************************************************/
|
||
|
|
||
|
/***************************** Include Files *********************************/
|
||
|
|
||
|
#include "xparameters.h"
|
||
|
#include "xbram.h"
|
||
|
#include <stdio.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 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_<BRAM_instance>_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);
|
||
|
}
|
||
|
}
|