risc-v中文社区

 找回密码
 立即注册
查看: 1813|回复: 0

[原创] microblaze访问LMB和AXI BRAM Controller

[复制链接]

347

主题

564

帖子

2237

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2237
发表于 2022-4-8 10:28:00 | 显示全部楼层 |阅读模式
BD图如下:


  1. #include "xparameters.h"
  2. #include "xbram.h"
  3. #include <stdio.h>

  4. /************************** Constant Definitions *****************************/

  5. /*
  6. * The following constants map to the XPAR parameters created in the
  7. * xparameters.h file. They are defined here such that a user can easily
  8. * change all the needed parameters in one place.
  9. */
  10. #define BRAM_DEVICE_ID                XPAR_BRAM_0_DEVICE_ID
  11. #define LMB_DEVICE_ID                XPAR_LMB_BRAM_IF_CNTLR_0_DEVICE_ID

  12. /************************** Function Prototypes ******************************/

  13. int BramExample(u16 DeviceId);
  14. static void InitializeECC(XBram_Config *ConfigPtr, u32 EffectiveAddr);


  15. /************************** Variable Definitions *****************************/

  16. /*
  17. * The following are declared globally so they are zeroed and so they are
  18. * easily accessible from a debugger
  19. */
  20. XBram Bram;        /* The Instance of the BRAM Driver */
  21. XBram lmbBram;

  22. /****************************************************************************/
  23. /**
  24. *
  25. * This function is the main function of the BRAM example.
  26. *
  27. * @param        None.
  28. *
  29. * @return
  30. *                - XST_SUCCESS to indicate success.
  31. *                - XST_FAILURE to indicate failure.
  32. *
  33. * @note                None.
  34. *
  35. *****************************************************************************/
  36. #ifndef TESTAPP_GEN
  37. int main(void)
  38. {
  39.         int Status;

  40.         Status = BramExample(BRAM_DEVICE_ID);
  41.         if (Status != XST_SUCCESS ) {
  42.                 xil_printf("Bram Example Failed\r\n");
  43.                 return XST_FAILURE;
  44.         }

  45.         xil_printf("Successfully ran Bram Example\r\n");
  46.         return XST_SUCCESS;
  47. }
  48. #endif

  49. /*****************************************************************************/
  50. /**
  51. *
  52. * This is the entry point for the BRAM example.
  53. *
  54. * @param        DeviceId is the XPAR_<BRAM_instance>_DEVICE_ID value from
  55. *                xparameters.h
  56. *
  57. * @return
  58. *                - XST_SUCCESS to indicate success.
  59. *                - XST_FAILURE to indicate failure.
  60. *
  61. * @note                None.
  62. *
  63. ******************************************************************************/
  64. int BramExample(u16 DeviceId)
  65. {
  66.         int Status;
  67.         XBram_Config *ConfigPtr;

  68.         /*
  69.          * Initialize the BRAM driver. If an error occurs then exit
  70.          */

  71.         /*
  72.          * Lookup configuration data in the device configuration table.
  73.          * Use this configuration info down below when initializing this
  74.          * driver.
  75.          */
  76.         ConfigPtr = XBram_LookupConfig(DeviceId);
  77.         if (ConfigPtr == (XBram_Config *) NULL) {
  78.                 return XST_FAILURE;
  79.         }

  80.         Status = XBram_CfgInitialize(&Bram, ConfigPtr,
  81.                                      ConfigPtr->CtrlBaseAddress);
  82.         if (Status != XST_SUCCESS) {
  83.                 return XST_FAILURE;
  84.         }


  85.         InitializeECC(ConfigPtr, ConfigPtr->CtrlBaseAddress);


  86.         /*
  87.          * Execute the BRAM driver selftest.
  88.          */
  89.         Status = XBram_SelfTest(&Bram, 0);
  90.         if (Status != XST_SUCCESS) {
  91.                 return XST_FAILURE;
  92.         }
  93.         /********joe code start****************/
  94.         XBram_Out8(ConfigPtr->MemBaseAddress,(u8)0x36);
  95.         volatile u8 data = XBram_In8(ConfigPtr->MemBaseAddress);
  96.         XBram_Out8(ConfigPtr->MemBaseAddress,(u8)0x37);
  97.         volatile u8 data2 = XBram_In8(ConfigPtr->MemBaseAddress);
  98. //        if(data != data2)
  99. //        {
  100. //                return XST_SUCCESS;
  101. //        }
  102. //        else
  103. //        {
  104. //                return XST_FAILURE;
  105. //        }
  106.         XBram_Config *lmbConfigPtr;
  107.         lmbConfigPtr = XBram_LookupConfig(LMB_DEVICE_ID);
  108.                 if (lmbConfigPtr == (XBram_Config *) NULL) {
  109.                         return XST_FAILURE;
  110.                 }

  111.                 Status = XBram_CfgInitialize(&lmbBram, lmbConfigPtr,
  112.                                 lmbConfigPtr->CtrlBaseAddress);
  113.                 if (Status != XST_SUCCESS) {
  114.                         return XST_FAILURE;
  115.                 }
  116.                 InitializeECC(lmbConfigPtr, lmbConfigPtr->CtrlBaseAddress);
  117. //                XBram_Out8(lmbConfigPtr->MemBaseAddress,(u8)0x36);
  118.                 data2 = XBram_In8(lmbConfigPtr->MemBaseAddress);
  119.                 XBram_Out8(lmbConfigPtr->MemBaseAddress,(u8)0x37);
  120.                 data = XBram_In8(lmbConfigPtr->MemBaseAddress);
  121.                 if(data != data2)
  122.                 {
  123.                         return XST_SUCCESS;
  124.                 }
  125.                 else
  126.                 {
  127.                         return XST_FAILURE;
  128.                 }
  129.         /********joe code end****************/
  130.         return XST_SUCCESS;
  131. }


  132. /****************************************************************************/
  133. /**
  134. *
  135. * This function ensures that ECC in the BRAM is initialized if no hardware
  136. * initialization is available. The ECC bits are initialized by reading and
  137. * writing data in the memory. This code is not optimized to only read data
  138. * in initialized sections of the BRAM.
  139. *
  140. * @param        ConfigPtr is a reference to a structure containing information
  141. *                about a specific BRAM device.
  142. * @param         EffectiveAddr is the device base address in the virtual memory
  143. *                address space.
  144. *
  145. * @return
  146. *                None
  147. *
  148. * @note                None.
  149. *
  150. *****************************************************************************/
  151. void InitializeECC(XBram_Config *ConfigPtr, u32 EffectiveAddr)
  152. {
  153.         u32 Addr;
  154.         volatile u32 Data;

  155.         if (ConfigPtr->EccPresent &&
  156.             ConfigPtr->EccOnOffRegister &&
  157.             ConfigPtr->EccOnOffResetValue == 0 &&
  158.             ConfigPtr->WriteAccess != 0) {
  159.                 for (Addr = ConfigPtr->MemBaseAddress;
  160.                      Addr < ConfigPtr->MemHighAddress; Addr+=4) {
  161.                         Data = XBram_In32(Addr);
  162.                         XBram_Out32(Addr, Data);
  163.                 }
  164.                 XBram_WriteReg(EffectiveAddr, XBRAM_ECC_ON_OFF_OFFSET, 1);
  165.         }
  166. }
复制代码
LMB和axi bram controller都可以访问到各自对应的BRAM中的数据,实验成功。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



Archiver|手机版|小黑屋|risc-v中文社区

GMT+8, 2024-4-19 10:43 , Processed in 0.019434 second(s), 18 queries .

risc-v中文社区论坛 官方网站

Copyright © 2018-2021, risc-v open source

快速回复 返回顶部 返回列表