University of Toronto ECE532 Digital Hardware LAB 3 Adding IP And Device Drivers That Use Interrupts Version 1 1 1 22 2004 9 34 PM 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 Lab1 and Lab2 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 such that 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 0 This switch will control the flashing rate of User LED 0 from Lab2 Preparation 1 Find the overviews of the OPB Timer Counter and the OPB Interrupt Controller v1 00c in the Processor IP Reference Guide From there you will find a link to the data sheets Familiarize yourself with how these blocks work The data sheets will also be posted on the course web page 2 In this lab you will be modifying the file lab2b c which should be in the code directory of your Lab2 project The file was copied from the User Area when you started Lab1 Have a look at this file to understand what it does In this lab you will be filling in the TO BE DONE xxx sections after XPS generates the header files to support the hardware 3 You should look at the Xilinx Lecture slides starting at slide 119 for an overview of the driver organization and conventions You can get more details in the EST Tools Guide in the Driver section Background This lab builds from Lab2 and assumes that the user has completed Lab2 A basic understanding of adding IP and device drivers should have been gained from Lab2 1 University of Toronto ECE532 Digital Hardware LAB 3 Adding IP And Device Drivers That Use Interrupts Setup 1 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 2 Start XPS by selecting Start Programs Xilinx Embedded Development Kit 6 1 Xilinx Platform Studio from the Windows desktop 3 Select the File menu select Open Project and browse to the system xmp file of lab3 Click Open to open the project This is the project you completed in Lab2 Adding A Timer Counter And Interrupt Controller 4 Using the Add Edit Cores feature of XPS add an OPB Timer opb timer and an OPB Interrupt Controller opb intc Set the address range of the timer to 0x00030300 0x000303ff and the range of the interrupt controller to 0x00030400 0x0003041f Attach both peripherals to the OPB bus as slaves 5 Select the Ports tab and add the Interrupt signal of the timer the Intr and Irq signals of the interrupt controller and the INTERRUPT signal of the Microblaze processor 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 selecting the first signal hold ctrl while clicking the second signal and then click the Connect button Enter a new net name select Internal and click OK Note that the signals to be connected are all internal to the design so be sure these are specified as Internal scope in the Port Signal Assignment table You can also rename the Net Names of signals by clicking in the white net name box There are no parameters for each core that must be set differently than the default value 6 Rebuild the bitstream and download it to the board Adding Software To Use The Timer And Interrupt Controller 7 Select driver interface level 1 for the Timer and Interrupt Controller software settings 8 Remove the source file lab2a c from the project and add lab2b c which should be in the code directory of your project 2 University of Toronto ECE532 Digital Hardware LAB 3 Adding IP And Device Drivers That Use Interrupts 9 Using the source file lab2b 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 10 Compile the program and download using GDB Verify the code works correctly 11 If you stop your program and run it a second time you may notice that it does not work and the message Timer counter initialization error is printed to the serial port Why do you think the initialization failed Step into the XTmrCtr Initialize function to find the answer However first you will have to recompile the drivers in debug mode In XPS select Options Compiler Options from the menus Select the Others tab and enter g O0 in the Extra Compiler Flags field to enable debug mode and turn off optimizations for the libraries When you step through the XTmrCtr Initialize function you will 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 disable interrupts for the interrupt controller at the start of your program using its level 0 driver xintc l h Otherwise an interrupt may occur before the drivers are initialized and your program will freeze while trying to service the interrupt Using A Switch To Control The Flashing Rate Of The LED 12 Add an additional bit as input to the GP IO to read the value of SW0 on the User Input DIP switch on the board In the Parameters tab of Add Edit Cores change the value of C GPIO WIDTH to 2 In the Ports tab change the range of the opb gpio 0 GPIO IO signal to 0 1 Note the bit order is LB UB as stated at the top of the window Add bit 1 of this signal to the system ucf file and connect it to the pin for USER INPUT0 Find the pin number in the Multimedia Board User Guide 13 Rebuild the bitstream and download it
View Full Document