Switch to Normal Style Sheet
Site Icon The Lab Book Pages Andrew Greensted (Modified: 08 November 2007)
Electronics > EDK HOWTO 4

Xilinx EDK HOWTO 4

This HOWTO discusses some aspects of the OPB bus.

Note: This HOWTO uses Xilinx EDK version 9.1i

Divider Bar Go to page top

• Memory IO Code

Acessing devices connected to the OPB comes down to a couple of functions XIo_Out32 and XIo_In32. These are actually predefined macros rather than functions. They are define in xio.h that can be found in the EDK installation. The macros are shown below.

• File: $XILINX_EDK/sw/XilinxProcessorIPLib/drivers/cpu_v1_01_a/src/xio.h
#define XIo_Out32(OutputPtr, Value) \
    (*(volatile Xuint32 *)((OutputPtr)) = (Value))

#define XIo_In32(InputPtr) (*(volatile Xuint32 *)(InputPtr))

You can use the macros, or declare your own memory pointers. Both methods are shown below for a memory write. In this case XPAR_OPB_TEST_0_BASEADDR is the base address of a OPB based peripheral.

• File: exp1.c
#include "xparameters.h"
#include "xutil.h"
#include "xio.h"

int main(void)
{
   Xuint32 dataOut = 0x1234ABCD;

   volatile Xuint32 *dataPointer;
   dataPointer = (volatile Xuint32 *) XPAR_OPB_TEST_0_BASEADDR;
   *dataPointer = dataOut;

   XIo_Out32(XPAR_OPB_TEST_0_BASEADDR, dataOut);

   return 0;
}
Divider Bar Go to page top

• Memory Address Offsets

The OPB is addressed on a byte basis, but has a 32bit wide data bus. Therefore to access 32bit chunks of your perhiperal you'll need to add multiples of 4 to the peripherals base address.

OPB Address offsets
• File: exp1.c
#include "xparameters.h"
#include "xutil.h"
#include "xio.h"

int main(void)
{
   print("Starting OPB Test\n");

   Xuint32 dataIn;

   XIo_Out32(XPAR_OPB_TEST_0_BASEADDR,    0x1234ABCD);
   XIo_Out32(XPAR_OPB_TEST_0_BASEADDR+4,  0xFFEEFFEE);
   XIo_Out32(XPAR_OPB_TEST_0_BASEADDR+8,  0x80000001);
   XIo_Out32(XPAR_OPB_TEST_0_BASEADDR+12, 0x76543210);

   dataIn = XIo_In32(XPAR_OPB_TEST_0_BASEADDR);
   xil_printf("In: %08X\n", dataIn);

   dataIn = XIo_In32(XPAR_OPB_TEST_0_BASEADDR+4);
   xil_printf("In: %08X\n", dataIn);

   dataIn = XIo_In32(XPAR_OPB_TEST_0_BASEADDR+8);
   xil_printf("In: %08X\n", dataIn);

   dataIn = XIo_In32(XPAR_OPB_TEST_0_BASEADDR+12);
   xil_printf("In: %08X\n", dataIn);

   return 0;
}
Divider Bar Go to page top