Title: Lab5 Advanced Software Writing Lab : MicroBlaze
1Lab5Advanced Software Writing Lab MicroBlaze
2Objectives
- Utilize the OPB timer.
- Assign an interrupt handler to the OBP timer.
- Develop an interrupt handler function.
- View how the appropriate functions can affect
code size.
3Procedure
- This lab comprises several steps, including the
writing of an interrupt handler used by the
software application to access the OPB timer and
interrupt controller. Below each general
instruction for a given procedure, you will find
accompanying step-by-step directions and
illustrated figures providing more detail for
performing the general instruction. If you feel
confident about a specific instruction, feel free
to skip the step-by-step directions and move on
to the next general instruction in the procedure. - Interrupt
OPB Bus
MDM
UART
MicroBlaze
INTC
LMB BRAM Cntlr
LMB BRAM Cntlr
Timer
BRAM
GPIO
PSB
GPIO
LEDs
7Seg LED
GPIO
My IP
SWs
4Opening the Project
- Create a lab5 folder in the X\EDKLab\ directory.
If you wish to continue with your completed
design from lab4 then copy the contents of the
lab4 folder into the lab5 folder.
1.
2.
3.
4.
5Opening the Project
- Open XPS, click File ? Open Project and browse to
the project which is in the directory
X\EDKLab\lab5, then click system.xmp to open the
project.
1.
2.
6Modify the MHS File and add an Interrupt
Controller
- Double-click the system.mhs file to open it in
the XPS editor.
7Modify the MHS File and add an Interrupt
Controller
- Add the following line at the end of the Delay
instance parameters (before the END keyword). - PORT Interrupt timer1
- Save and Close the MHS file.
8Modify the MHS File and add an Interrupt
Controller
- Click Project ? Add Cores (dialog).
9Modify the MHS File and add an Interrupt
Controller
- In the Peripherals tab, add the opb_intc
peripheral.
1.
2.
3.
10Modify the MHS File and add an Interrupt
Controller
1.
- In the Bus Connections tab, connect the interrupt
controler as an s (slave) device to the OPB bus. - Change the base address of the interrupt
controller to 0x80001c00 and the high address to
0x80001dff.
3.
4.
2.
11Modify the MHS File and add an Interrupt
Controller
- Using the Ports tab, add the OPB_Clk, Intr, and
Irq ports of the opb_intc_0 as internal.
1.
2.
3.
12Modify the MHS File and add an Interrupt
Controller
- Change the net names of the OPB_Clk and Irq ports
of the opb_intc_0 instance to sys_clk_s and
interrupt, respectively.
13Modify the MHS File and add an Interrupt
Controller
1.
- Select the browse button under Net Name next for
Intr to open the Connect and Prioritize
Interrupts dialogue box. - Select timer1 from the High Priority list
(right-side) and click the Add button to add the
interrupt output of the delay instance to the
input of the interrupt controller opb_intc. - Click ltOKgt.
2.
3.
4.
14Modify the MHS File and add an Interrupt
Controller
- Add the INTERRUPT (external interrupt request)
port on the microblaze_0 to the design as an
internal interrupt, and change its net name to
interrupt. - Click the ?? button to accept the changes and
close the editor dialog.
1.
2.
3.
4.
15Configure the BSP
- Using Project ? Software Platform Settings open
the Software Platform Settings GUI.
16Configure the BSP
- Click on the Processor, Driver Parameters and
Interrupt Handlers tab. - Enter timer_int_handler in the Current Value
field as a interrupt_handler function, as shown
in following figure. - Click ?? to accept the settings.
- Click Tools ? Generate Libraries to update the
generated libraries and xparameters.h file.
17Write the Interrupt Handler and Compile the Code
- Copy the system_timer.c and 7segled.c files to
the current project X\EDKlab\Lab5\code.
18Write the Interrupt Handler and Compile the Code
- Make the TestApp project inactive. Under the
Applications Tab, right click on the TestApp
project title and select Make Project Inactive.
This is necessary because there is no interrupt
handler in this project.
1.
2.
4.
3.
19Write the Interrupt Handler and Compile the Code
- Remove system.c from the Project MyProj project
by right clicking on it under Sources and
deleting it. - Add the two new files system_timer.c and
7segled.c to the MyProj project by right clicking
on Sources and selecting Add File then navigate
to the sources and add them.
1.
2.
3.
4.
5.
20Write the Interrupt Handler and Compile the Code
- Double-click system_timer.c to open the C file in
the XPS editor. Examine the contents of the C
file. Notice that the interrupt handler has not
been completed. You will complete it.
21Write the Interrupt Handler and Compile the Code
- Create a new global variable to be used in the
interrupt handler code - Xuint32 timer_count 0
- Note The Xuint32 type is declared in include
"xbasic_types.h" xutil.h. - Save the file.
22Write the Interrupt Handler and Compile the Code
- Notice that the interrupt handler function is
called timer_int_handler. - This name must match the name specified in the
OPB Timer Peripheral Options, as shown in Page
15. If the name does not match exactly, the
interrupt handler will not be connected to the
interrupt. - Create several new local variables for the
timer_int_handler - Xuint32 baseaddr (int)baseaddr_p
- Xuint32 csr
- The first step in creating an OPB timer interrupt
handler is to verify that the OPB timer caused
the interrupt. This information can be found in
the OPB Timer Control Status Register. Open the
documentation to determine how the Control Status
Register works.
23Write the Interrupt Handler and Compile the Code
- In Windows, Click Start ? Programs ? Xilinx
Platform Studio 6.3i ? Documentation ? EDK 6.3i
Reference User Guides.
24Write the Interrupt Handler and Compile the Code
- Scroll down to the bottom of the page and click
Processor IP Reference Guide.
25Write the Interrupt Handler and Compile the Code
- In the Processor IP Reference Guide, click OPB
Timer/Counter under the peripheral cores section.
Click View this data sheet to view the complete
data sheet.
1.
3.
2.
26Write the Interrupt Handler and Compile the Code
- Go to the Register Description section in the
data sheet and study TCSR0 Register. Notice that
bit 23, T0INT, has the following description
27Write the Interrupt Handler and Compile the Code
- The level 0 driver for the OPB timer provides
functions (macros) that read and write to the
Control Status Register, which we will use to
read and write TCSR0. We can use the following
function to determine whether the interrupt has
occured - XTmrCtr_mGetControlStatusReg( )
- The following is the documentation associated
with the OPB timer - XTmrCtr_mGetControlStatusReg ( BaseAddress,
TmrCtrNumber ) - Get the Control Status Register of a timer
counter. - Parameters
- BaseAddress is the base address of the device.
- TmrCtrNumber is the specific timer counter within
the device, a zero-based number, 0 -gt
(XTC_DEVICE_TIMER_COUNT - 1). - Returns
- The value read from the register, a 32-bit value.
28Write the Interrupt Handler and Compile the Code
- Add this function call to the code with the
associated parameters. The resulting 32-bit value
should be stored in the variable csr. - csr XTmrCtr_mGetControlStatusReg(baseaddr, 0)
- Using the value returned to csr, test to see if
bit 23 is set by using the XTC_CSR_INT_OCCURED_MAS
K parameter. - if (csr XTC_CSR_INT_OCCURED_MASK)
-
- timer_count
29Write the Interrupt Handler and Compile the Code
- If the interrupt was taken, increment a counter.
The count value should then be displayed by using
the 7SegLED peripheral. A subroutine to do the
display is included in the 7SegLED.c file. The
following call will display the value in
timer_count on the display and light the decimal
point in position 1. - dispLED(timer_count, 1)
- Clear the interrupt by using the following
function call - XTmrCtr_mSetControlStatusReg(baseaddr, 0, csr)
30Write the Interrupt Handler and Compile the Code
- The interrupt handler has now been completed, and
it should look like following figure, with the
exception of the counter. You can create any type
of counter you like.
31Write the Interrupt Handler and Compile the Code
- In the Applications tab, double-click on Compiler
Options. - Click on the Directories tab and delete the
linker script file entry and click ??.
2.
1.
3.
4.
32Write the Interrupt Handler and Compile the Code
- Generate the hardware system, click Tools ?
Generate Netlist. - PlatGen will regenerate the hardware system
because you added the interrupt controller to the
MHS file. - Compile the source file.
33Write the Interrupt Handler and Compile the Code
- Why do you think the program is so big?
- The printf function uses significant amount of
code space. - Change the printf to xil_printf.
- This contains the same functionality as printf
with the exception of the floating-point
handling. - Recompile the code.
34Write the Interrupt Handler and Compile the Code
- In the Applications tab, double-click on Compiler
Options. - Click on the Directories tab.
2.
1.
3.
35Write the Interrupt Handler and Compile the Code
- Click on the browse button of the linker script
file entry, browse to the X\EDKlab\Lab5\TestApp\s
rc\ directory, and select TestAppLinkScr to add
it to the project. - Click ?? to accept the setting.
1.
2.
3.
4.
36Write the Interrupt Handler and Compile the Code
- Close the project so that the peripheral can be
seen by XPS, File ? Close Project. - Open the project by clicking File ? Recent
Projects ? \lab5\system.xmp from XPS. - alter the xil_printf function call to printf in
main. - In the TestAppLinkScr file, change the stack and
heap size to 0x200 each.
37Write the Interrupt Handler and Compile the Code
- Try to compile the code. A compilation error
will occur due to memory being full. This
occurred as now the linker script is in effect
and the total memory requirement is 44432 which
is much more than what we have (16K in lmb). - Change the printf function to xil_printf in main.
- Save the changes.
38Write the Interrupt Handler and Compile the Code
- Compile the code and you will see that it
compiles successfully. - Note The amount of memory usage is different
then the one being used without linker script as
the linker script controls the heap and stack
sizes and placement.
39Verifying in Hardware
- Download the generated bit file by clicking Tools
? Download. - After the board is programmed, you will see a
counter on the 7 Segment LEDs and a message on
the terminal window. - Note It is possible that the design will not
meet timing. If this is the case, it is still
likely to function correctly. If not, then you
can change the effort level in PAR from std to
high in the fast_runtime.opt file in the lab5\etc
directory.
40Conclusion
- This lab led you through assigning an interrupt
handler function to an interrupting device such
as an OPB timer. An interrupt controller was
added to the system. - The LibGen tool allowed you to update the
parameters on the added and modified system. - You also developed an interrupt handler function
and viewed how the appropriate function can
reduce the code size, which can have a major
impact on resource requirements.