|
BD图见:http://bbs.risc-v.org.cn/thread-251-1-1.html
实验现象就是:在vivado的Hardware manager中将VIO的输出从0设置为1,则就会进入microblaze的VIO对应的中断函数。
实验图示如下:
实验源码如下:
xbram_example.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.
- *
- * 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
- * XILINX 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)
- * 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>
- #include "sys_intc.h"
- #include <xintc.h>
- #include <sleep.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
- #define LMB_DEVICE_ID XPAR_LMB_BRAM_IF_CNTLR_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 */
- XBram lmbBram;
- #define VIO_INTR_ID XPAR_INTC_0_DEVICE_ID
- static XIntc Intc;
- void VioHandler(void *CallbackRef);
- void init_intr_sys(void);
- /****************************************************************************/
- /**
- *
- * 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 Failed\r\n");
- return XST_FAILURE;
- }
- init_intr_sys();
- while(1){}
- xil_printf("Successfully ran Bram Example\r\n");
- return XST_SUCCESS;
- }
- void init_intr_sys(void)
- {
- Init_Intr_System(&Intc);
- XIntc_Connect(&Intc, VIO_INTR_ID,
- (Xil_ExceptionHandler)VioHandler, 0);
- Intc_Enable(&Intc, VIO_INTR_ID);
- Intc_Start(&Intc);
- Setup_Intr_Exception(&Intc);
- }
- void VioHandler(void *CallbackRef)
- {
- usleep(5000);
- }
- #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;
- }
- /********joe code start****************/
- XBram_Out8(ConfigPtr->MemBaseAddress,(u8)0x36);
- volatile u8 data = XBram_In8(ConfigPtr->MemBaseAddress);
- XBram_Out8(ConfigPtr->MemBaseAddress,(u8)0x37);
- volatile u8 data2 = XBram_In8(ConfigPtr->MemBaseAddress);
- // if(data != data2)
- // {
- // return XST_SUCCESS;
- // }
- // else
- // {
- // return XST_FAILURE;
- // }
- XBram_Config *lmbConfigPtr;
- lmbConfigPtr = XBram_LookupConfig(LMB_DEVICE_ID);
- if (lmbConfigPtr == (XBram_Config *) NULL) {
- return XST_FAILURE;
- }
- Status = XBram_CfgInitialize(&lmbBram, lmbConfigPtr,
- lmbConfigPtr->CtrlBaseAddress);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- InitializeECC(lmbConfigPtr, lmbConfigPtr->CtrlBaseAddress);
- // XBram_Out8(lmbConfigPtr->MemBaseAddress,(u8)0x36);
- data2 = XBram_In8(lmbConfigPtr->MemBaseAddress);
- XBram_Out8(lmbConfigPtr->MemBaseAddress,(u8)0x37);
- data = XBram_In8(lmbConfigPtr->MemBaseAddress);
- if(data != data2)
- {
- return XST_SUCCESS;
- }
- else
- {
- return XST_FAILURE;
- }
- /********joe code end****************/
- 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);
- }
- }
复制代码 sys_intc.h:
- #ifndef SYS_INTR_H_
- #define SYS_INTR_H_
- #include "xparameters.h"
- #include "xil_exception.h"
- #include "xdebug.h"
- #include "XIntc.h"
- int Init_Intr_System(XIntc * IntcInstancePtr);
- void Intc_Enable(XIntc *IntcInstancePtr,u16 Intr_Id);
- int Intc_Start(XIntc *IntcInstancePtr);
- void Setup_Intr_Exception(XIntc * IntcInstancePtr);
- #endif /* SYS_INTR_H_ */
复制代码 sys_intc.c:
- /*
- * sys_intc.c
- *
- * Created on: 2022年4月8日
- * Author: joe
- */
- #include "sys_intc.h"
- #include "xil_types.h"
- #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
- void Setup_Intr_Exception(XIntc * IntcInstancePtr)
- {
- /* Enable interrupts from the hardware */
- Xil_ExceptionInit();
- Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
- (Xil_ExceptionHandler)XIntc_InterruptHandler,
- (void *)IntcInstancePtr);
- Xil_ExceptionEnable();
- }
- int Init_Intr_System(XIntc * IntcInstancePtr)
- {
- int Status;
- Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
- if (Status != XST_SUCCESS) {
- return XST_FAILURE;
- }
- return XST_SUCCESS;
- }
- void Intc_Enable(XIntc *IntcInstancePtr,u16 Intr_Id)
- {
- XIntc_Enable(IntcInstancePtr, Intr_Id);
- }
- int Intc_Start(XIntc *IntcInstancePtr)
- {
- int Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
- if(Status != XST_SUCCESS){
- return XST_FAILURE;
- }
- return XST_SUCCESS;
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|