Laboratory 5
In laboratory 5 you will be creating a simple, interrupt-based system-on-chipi design. You will be instantiating three GPIOi devices in your system-on-chipi design and will write software which will respond to interrupts generated by those GPIOi devices. The software that you write for this laboratory will be a mixture of high-level C code and low-level assembly. Additionally, you will make use of some Xilinxi provided low-level interrupt routines. Reading and understanding the interrupt handling tutorial will help you complete this project.
Project Description
This purpose of this project is two fold. First, students should learn how to use functions written in assembly in C programs and how to use functions written in C in assembly programs. Second, students should learn how hardware interrupts are handled at the processor level, the assembly level, and the C level. Additionally, the software developed in this laboratory project should demonstrate how a running program can be interrupted by the processor so that another function can be executed. Because interrupts represent asynchronous, non-standard control flow in software programs the description of this project is complex, however, the developed software should be relatively simple.
The software for this project should consist of at least six functions. You are required to have these six functions in your demonstrated project. First, you should have a main function which enables interrupts in the system and then calls the main_loop function. The main_loop function should infinitely loop. Each loop should prompt the user for two numbers using the serial port, add the two numbers together, and then print out all of the prime numbers less than the result. This represents the main processing of the application.
You will also have four functions which perform auxiliary processing when interrupts occur. The first function should be intr_handler. This function, which should be written in assembly, will need to query the programmable interrupt controller to determine what interrupt occurs. If the interrupt was from the DIPSW GPIOi then the function handle_dipsw should be called and if the interrupt was from the push button GPIOi then the function handle_pb should be called. These two functions should be written in C and should perform the processing described below. The last function you will write is the write_leds functions, which should be written in assembly. This function will be used by the handle_dipsw and handle_pb functions and it used to illuminate certain LEDs.
Project Directions
- Create a system-on-chipi design using the BSB wizard
Your system-on-chipi design needs to include a MicroBlazei soft-processori and RS-232 Serial port as is standard for the designs in this class. Additionally, for this project you should include the LEDi, DIPSW, and Push Button GPIOs. When enabling these devices make sure to select the "Use Interrupt" option. Otherwise your system will not include the necessary programmable interrupt controller (PIC). - Write your high-level C functions
Your high-level C function will comprise most of the software for this project. Any functionality you need for this project, except the functionality explicitly mentioned in the low-level assembly functions, can be code in C. You will most likely need to read the GPIOi and interrupt controller reference manuals to figure out exactly how to enable interrupts on the system. These manuals can be found in the reference materials. At a minimum you will need to do the following:- Write your main function
- Write the handle_dipsw function
- Write the handle_pb function
- If the up or right button is pressed then shift the LEDs to the right
- If the down or left button is pressed then shift the LEDs to the left
- If the middle button is pressed then restore the LEDs to the state of the DIPSWs
- Write the main_loop function
- Prompt the user to enter two numbers using the serial port
- Add the two number together
- Print out all of the prime numbers less than the addition result
- Write your low-level assembly functions
For this project you will be writing two assembly level functions. The first function will be your low-level interrupt handler. This function should be called intr_handler and it should be a function with no parameters and no return value. The function itself will need to examine the programmable interrupt controller and determine which interrupt occurred. If the interrupt was from the DIPSW peripheral then you will need to call the C function handle_dipsw. If the interrupt was from the push button peripheral then you will need to call the C function handle_pb. If the interrupt was from neither of these two sources then your system has not been properly configured as you should be masking out any unimportant interrupts.The second function that you will write in assembly will be a function called write_leds. This function should be a function of two parameters. The first parameter should be the base address of the LEDi GPIOi and the second parameter should be an unsigned integer value which indicates which light on the LEDi to illuminate. This function must be called by your handle_dipsw and handle_pb C functions.
- Synthesize your system-on-chipi design, compile your software, and combine them into a bitstream.
- Download your bitstream onto the XUPi development board, execute it, and demonstrate your working design to your TA.
Project Questions
- How do you call a C function from assembly language?
- How do you call an assembly function from C?
- How do you register an interrupt handler using the Xilinxi libraries?
- What does the programmable interrupt controller (PIC) do? What registers are exposed to the software?
- When a hardware device generated an interrupt what happens in the rest of the system? Describe what happens in the PIC, what happens in the CPU, and what the software does.
