Xcell Journal issue 84

Page 47

X P L A N AT I O N : F P G A 1 0 1

Figure 5 – Selecting the peripheral driver

driver next to it; in the first instance the driver will be named “generic.” Using the peripheral within the SDK, the generic driver is not an issue. If you wish to use it, you will need to include the header file #include "xil_io.h." This allows you to use the function calls Xil_in32(addr) or Xil_out32(addr) to read and write from the peripheral. To use this method you will also need to know the base address of the peripheral, which is given in xparameters.h, and the offset between registers. In this case, because of the 32-bit addressing in our example design, the registers are separated by 0x04. However, if you enabled the driver-creation option when you created the peripheral using XPS, then a separate driver will have been specially built for your peripheral. This driver too will be located within the drivers subdirectory of your PlanAhead sources directory. You can use this type of specially built driver in place of the generic drivers within your design, but first you Third Quarter 2013

must set the software repositories to point to the directory to see the new drivers. You can define the repositories under the Xilinx Tools -> Repositories menu (Figure 4). Once you have set the repositories to point to the correct directory, you can re-scan the repositories and close the dialog window. The next step is to update the board support package with the new driver selection. Open the board support package settings by right-clicking on the BSP icon under the Project Explorer. Click on the drivers tab and you will see a list of all the peripherals and their drivers. You can change the driver selection for your peripheral by selecting the appropriate driver from a list of drivers applicable to that device (Figure 5). Select the driver for your peripheral by name and click OK; your project will be recompiled if you have automatic compilation selected. Once the code has been rebuilt, you are then nearly ready to communicate with

the peripheral using the supplied drivers. Within your source code you will need to include the driver header file #include "led_if.h" and use the base address of the peripheral from xparameters.h to enable the interface to know the address within the memory space. It is then a simple case of calling the commands provided by the driver within the “include” file. In the case of our design, one example was LED_IF_mWriteSlaveReg0(LED_ ADDR, LED_IF_SLV_REG0_OFFSET, 0x01); With this command written, it is then time to test the software within the hardware environment and confirm that it functions as desired. As you can see, making your own peripheral within a Zynq SoC design is not as complicated as you may at first think. Creation of a peripheral offers several benefits for your Zynq SoC processing system and, ultimately, your overall solution. Xcell Journal

47


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.