University of Toronto ECE532 Digital Hardware Module m03 Adding IP and Device Drivers Timers and Interrupts Version for EDK 10 1 03 as of January 7 2009 Acknowledgement This lab is derived from a Xilinx lab given at the University of Toronto EDK workshop in November 2003 Many thanks to Xilinx for allowing us to use and modify their material Goals Use Xilinx tools to add to the Microblaze system that was built in Modules m01 and m02 A primary goal of this lab is to understand the details of adding IP and device drivers that use interrupts IP cores including the General Purpose I O GPIO Timer and Interrupt Controller are used in this lab together with the associated device drivers Many complex embedded systems use interrupt driven I O rather than polled I O and as such learning how to use interrupts is important The Interrupt Controller and Timer will be added to the project and used to create a periodic interrupt that can be used to schedule other processing The GPIO will be used to get input from switch User Input 1 This switch will control the flashing rate of User LED 0 from Module m02 Prerequisites Module m02 Adding IP and Device Drivers GPIO and Polling Preparation Find the overviews of the XPS Timer Counter and the XPS Interrupt Controller in the EDK documentation look in the IP Reference Processor IP Catalog From there you will find a link to the datasheets Familiarize yourself with how these blocks work Copy the XPS project directory lab2 folder of the previous lab and rename the copy to lab3 This will be the working project directory for this lab Extract m03 zip into the directory containing the lab3 directory to add the source files required for this module to the lab3 code directory If you like you can delete the existing lab3 code directory before extracting m03 zip to clean up the files from Module m02 In this lab you will be modifying the file lab3 c which you just extracted into your copy of your Module m02 project Have a look at this file to understand what it does In this lab you will be filling in the TO BE DONE sections after XPS generates the header files to support the hardware Launch XPS and open the project for Module m03 i e lab3 system xmp Background This lab builds from Module m02 and assumes that the user has completed Module m02 A basic understanding of adding IP and device drivers should have been gained from Module m02 Adding A Timer Counter And Interrupt Controller 1 Add an XPS Timer xps timer and an XPS Interrupt Controller xps intc Set the address range of the timer to 0x80040200 0x800402ff and the range of the interrupt controller to 0x80040300 0x8004031f Attach both peripherals to the PLB bus as slaves 1 University of Toronto ECE532 Digital Hardware Module m03 Adding IP and Device Drivers Timers and Interrupts 2 Select Ports The interrupt output signal of the timer should be connected to the interrupt input Intr of the interrupt controller The interrupt output signal Irq of the interrupt controller should be connected to the interrupt input of the processor Connect the signals by entering the same name into the Net fields for both signals Both cores can be left with the default configuration values for their paramters 3 Rebuild the bitstream and download it to the board If you deleted lab2 c earlier don t forget to remove it from Project mb0 default Sources on the Applications tab before building Adding Software To Use The Timer And Interrupt Controller 4 Remove the source file lab2 c from the project if you haven t already done so and add lab3 c which should be in the code directory of your project 5 Make sure you have regenerated the libraries Why 6 Using the source file lab3 c make the appropriate changes to the source file such that it will compile Reference xparameters h and the device driver documentation or header files for help 7 Compile the program and download using GDB Verify that the code works correctly with the software debugger 8 Close the software debugger and switch to the XMD window From the XMD window enter dow mb0 default executable elf to download the binary to the MicroBlaze Type run to start running the program and confirm that it is operating as it did when you ran it via the software debugger Type stop to stop the program Look at the PC where did the program stop hint use the rrd command Reset the PC to the start address of your program remember it s 0x800 using the rwr command and type con to start your program over from the beginning Notice that this time the timer initialization fails and the message Timer counter initialization error is printed to the serial port Why do you suppose this is Restart the program this time using the run command and notice the difference What changed Why Can you use the debugger to explain the different behaviour between continuing from the start address of the program and running the program While trying to figure out what happened you may find it difficult to debug the driver code If you consult your system log or libgen log and look for the messages relating to building the libraries you ll notice that they re still built with optimization enabled O2 even though you disabled optimizations for your application code in Module m02 To recompile the drivers in debug mode select the Software menu and the Software Platform Settings submenu Select microblaze 0 from the Processor Instance drop down list and enter g O0 in the extra compiler flags field If you rebuild the libraries you might notice that both the O2 and O0 flags are set If you then look at the Makefile for the drivers you ll notice that the EXTRA COMPILER FLAGS appears after COMPILER FLAGS in the build command If you further look at the man page for gcc you ll note that if multiple O flags are included in the gcc command line the last one takes precendence You should now be able to step through the XTmrCtr Initialize function after stopping the program resetting the PC and continuing from 0x800 You ll now notice that it fails because the timer is already running from the last time your program was run and the function exits before completing the initialization To fix this you should make sure the timer is not running at the start of your program However you cannot call the XTmrCtr Stop function before calling XTmrCtr Initialize so you must use the level 0 driver interface to disable the timer Look in microblaze 0 include xtmrctr l h to determine how to do this and add it to the beginning of your program Similarly you should
View Full Document