bram example阅读:xbram_example.c
Posted iwanna
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bram example阅读:xbram_example.c相关的知识,希望对你有一定的参考价值。
/** * 这个example比较简单,主要是用config初始化真设备,然后用虚址写bram * @file xbram_example.c * 用XBram测 * 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) * 4.1 ms 01/23/17 Modified xil_printf statement in main function to * ensure that "Successfully ran" and "Failed" strings are * available in all examples. This is a fix for CR-965028. *</pre> * ******************************************************************************/ /***************************** Include Files *********************************/ #include "xparameters.h" #include "xbram.h" #include <stdio.h> /************************** Constant Definitions *****************************/ /*xpar是xparameters.h(这个文件是特异的吗?怎么找自己的硬件地址?)里的 *用来定义bram的id * 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//这个是ctr的地址 /************************** 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 */ //BRAM驱动实例,之后赋值 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);//BRAM_DEVICE_ID就是之前那个宏定义, //应该传自己的ctr的设备号,去哪里找?? if (Status != XST_SUCCESS ) { xil_printf("Bram Example Failed "); return XST_FAILURE; } xil_printf("Successfully ran Bram Example "); 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;//bram设置 /*初始化BRAM驱动 * Initialize the BRAM driver. If an error occurs then exit */ /*给设备设置数据(pl设的一堆参数什么的)赋值(基本操作,直接抄就行 * 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; } //把cfg连上?用cfg数据,给Bram驱动实例赋值,初始化? Status = XBram_CfgInitialize(&Bram, ConfigPtr, ConfigPtr->CtrlBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } //这个是自定义函数,ecc是加密方式(错误检查和纠正 InitializeECC(ConfigPtr, ConfigPtr->CtrlBaseAddress); /*用自带的seltest,干什么的?查ecc * 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. * * 这里讲函数的两个参数: *证实了猜测,configPtr就是数据结构体,就用来从pl传过来数据,用来初始化设备 * @param ConfigPtr is a reference to a structure containing information * about a specific BRAM device. * *实际的虚拟地址,注意是虚存的地址, *base和ctl的id号不是一回事,ctl的地址是方便给参数的,不是真正的存东西的地址 *需要复习一下OS * @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); } //写bram函数,基地址(虚址,偏移,数据 XBram_WriteReg(EffectiveAddr, XBRAM_ECC_ON_OFF_OFFSET, 1); } }
以上是关于bram example阅读:xbram_example.c的主要内容,如果未能解决你的问题,请参考以下文章
Xilinx 使用shift_RAM消耗分布式RAM(LUTRAM)还是BRAM (Block RAM)?