Lab05 PDF
Lab05 PDF
Lab05 PDF
SDK Lab
Introduction
This lab guides you through the process of adding timer and interrupt controller to an embedded system
and writing a software application that utilizes these timer and interrupt controller. The SDK will be used
to create and debug the software application.
Objectives
After completing this lab, you will be able to:
Design Description
The purpose of this lab exercise is to extend the hardware design created in lab 5 to include an XPS
interrupt controller and XPS Timer (see Figure 5-1). You will develop an interrupt handler to count the
interrupts generated from the timer.
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises 5 primary steps: You will add a timer and interrupt controller, create an SDK software
project, write an interrupt handler, add linker script and, finally, verify operation in hardware.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this
module from the Xilinx University Program site at http://www.xilinx.com/university
1-1. Create a lab5 folder and copy the contents of the lab4 folder into the lab5
folder, or copy the content of the labsolution\ lab4 folder into the lab5
folder. Launch Xilinx Platform Studio (XPS) and open the project file.
1-1-1. Create a lab5 folder in the C:\ xup\ embedded\ labs directory and copy the contents from lab4 to
lab5, or copy the content of the labsolution\ lab4 folder into the lab5 folder.
1-1-2. Open XPS by selecting Start All Programs Xilinx ISE Design Suite 13.2 EDK
Xilinx Platform Studio.
1-1-3. Browse to the lab5 directory and open the project system.xmp.
1-2. Add the XPS timer and XPS Interrupt Controller peripherals to the design
from the IP Catalog, and connect them to the system according to the
following table.
xps_intc_0 instance
Intr timer1
Irq Microblaze_0_INTERRU
PT
delay instance
CaptureTrig0 net_gnd
Interrupt timer1
microblaze_0 instance
INTERRUPT Microblaze_0_INTERRU
PT
1-2-1. Add the XPS Timer/Counter peripheral from the DMA and Timer section of the IP Catalog,
check Only One Timer is present option, and change its instance name to delay.
1-2-2. Add the XPS Interrupt Controller peripheral from the Clock, Reset, and Interrupt section of the
IP Catalog with default settings.
1-2-3. Connect the timer and interrupt controller device to the PLB bus (see Figure 2).
Figure 2. Add and Connect the Interrupt Controller and Timer Peripherals
1-2-5. The generated addresses should look similar to that indicated in the figure below:
1-2-6. In the Ports section, type in timer1 as the Interrupt port connection of the delay instance, and
hit Enter key.
1-2-7. Make a new net connection (see Figure 4) for the INTERRUPT (external interrupt request) port
on the microblaze_0 instance by selecting New Connection from the drop-down box. This will
create a net called microblaze_0_INTERRUPT.
Figure 4. Make a new net connection to connect the MicroBlaze Interrupt port
1-2-8. Connect the interrupt controller and timer as follows (refer to Figure 5).
Connect interrupt output port Irq of the xps_intc_0 instance to the MicroBlaze interrupt input
port using the microblaze_0_INTERRUPT net.
Click in intr field of xps_intc_0 field to open the Interrupt Connection Dialog. Click on
timer1 on left side, and click on sign to add to the Connected Interrupts field (right),
and then click OK.
2-1. Launch SDK and create a new software application project for the lab5 XPS
project. Import the lab5.c source file.
Skip steps starting from 2-1-3 to 2-1-7 and remove lab4.c, if you were
continuing with lab4.
2-1-2. Click on Export & Launch SDK button with default setting and browse to
C:\xup\embedded\labs\lab5\SDK\SDK_Export.
This will implement the design if necessary and generate system.bit and system_bd.bmm
Skip steps starting from 2-1-3 to 2-1-7 and remove lab4.c, if you were continuing with lab4.
2-1-3. Click on File in the Xilinx SDK window and select New Xilinx C Project.
2-1-4. Enter lab5 in the Project Name field and choose Empty Application in Project type window.
2-1-7. Select lab5 in the project view, right-click, and select Import.
2-1-8. Extend the General folder and double-click on File System and browse to
c:\ xup\ embedded\ lab\source. Select lab5.c and click Finish.
2-1-9. Note that both the Problems and Console tabs on the bottom report several compilation errors
Note also that the project outline on the right side is updated to reflect the libraries and routines
used in the source file.
2-2-1. In the Problems tab, double-click on the first red x for the parse error. This will open the source
file bring you around to the error place.
2-2-2. Add the missing global variable declaration as unsigned int, initialize it to the value of 1, and
save the file. The first error message should disappear.
2-2-3. Click the next error message to highlight the problem in the source code.
2-2-4. Add the missing global variable declaration as int, inititalize it to the value of 0, and save the file.
The additional error messages should disappear.
3-1-1. Go to where the interrupt handler function has already been stubbed out in the source file (a fast
way to do this is to click on the function in the outline view).
3-2. The first step in creating an XPS timer interrupt handler is to verify that the
XPS timer caused the interrupt. This can be determined by looking at the
XPS Timer Control Status Register. Open the API documentation to
determine how the Control Status Register works.
3-2-1. In the XPS System Assembly View window, right-click the delay instance and select View PDF
Datasheet to open the data sheet.
3-2-2. Go to the Register Description section in the data sheet and study the TCSR0 Register. Notice
that bit 23 has the following description:
Timer0 Interrupt
Indicates that the condition for an interrupt on this timer has occurred. If the timer mode is capture
and the timer is enabled, this bit indicates a capture has occurred. If the mode is generate, this bit
indicates the counter has rolled over. Must be cleared by writing a 1
Read:
0 - No interrupt has occurred
The level 0 driver for the XPS timer provides two functions that read and write to the Control
Status Register. View the timer API doc by right-clicking on the delay instance in the System
Assembly View and selecting Driver:tmrctr_v2_00_a View API Documentation. In the API
document, click on the File List link at the top of the document, then click on the link labeled
xtmrctr_l.h in the file list. This brings up the document on identifiers and the low-level driver
functions declared in this header file. Scroll down in the document and click on the link for the
XTmrCtr_GetControlStatusReg( ) function to read more about this function. Use this function to
determine whether an interrupt has occurred. The following is the pertinent information found in
the XPS timer documentation:
o Parameters:
BaseAddress is the base address of the device.
TmrCtrNumber is the specific timer counter within the device, a zero-based number, 0
(XTC_DEVICE_TIMER_COUNT - 1)
o Returns:
The value read from the register, a 32-bit value
3-2-3. Add the XTmrCtr_GetControlStatusReg function call to the code with the associated
parameters. The resulting 32-bit return value should be stored in the variable csr.
csr=XTmrCtr_GetControlStatusReg(XPAR_DELAY_BASEADDR,0);
Note: Substitute XPAR_DELAY_BASEADDR with the base address for the delay peripheral.
Refer to xparameters.h
3-2-4. Complete the Interrupt handler (see Figure 11) according to the steps below:
Test to see if bit 23 is set by ANDing csr with the XTC_CSR_INT_OCCURED_MASK parameter.
Display the count value by using the LEDs_8Bit peripheral and print the value using xil_printf
(same functionality as printf with the exception of floating-point handling)
XTmrCtr_SetControlStatusReg(baseaddr, 0, csr);
The completed handler should look like as shown in the next figure
3-2-5. Save the file, this should compile the source successfully.
4-1. Generate the linker script by assigning code section to ilmb and data
section to xps_bram. Set heap and stack to 0x400 each.
4-1-1. Right-click Testapp in project view and select Generate Linker Script.
4-1-2. Set the heap and stack size to 0x400 (1024) each.
4-1-3. Assign Code section to ilmb_cntlr_dlmb_cntlr and Data, Stack and Heap sections to
xps_bram_if_cntlr(this is necessary as each of the memory is too small to hold everything).
4-1-4. Click Generate to generate the linker script, add to the project and recompile the program.
5-1-3. Browse and select system.bit and system_bd.bmm files from the lab5\ implementation (this
step is required for 12.2 version. For other version, you may skip this step and try with the default
paths to see if it works).
This will execute Data2Mem program to combine the bootloop executable with hardware
bitstream, generate the download.bit file, and configure the FPGA.
5-1-5. Select Terminal tab (near console area), and click on New Terminal Connection
( ).
5-1-6. Select serial as connection type and correct COM port and 115200 baud rate, and click OK.
5-2-1. Select Testapp, from the SDK Menu, select Run Run configurations ...
5-2-3. Right click on it then select New to add a new Launch configuration.
5-2-4. Click on the Run button. The application will run. You should see messages in the Console and
the LEDs should be flickering.
5-2-6. Click YES to stop the current execution. Click YES to launch the Debug perspective.
5-2-7. Right click in the Variables tab and select Add Global Variables... All global variables will be
displayed. Select count variable and click OK.
5-3-1. Double-click to set a breakpoint on the line in lab5.c where count is written to LED.
5-3-2. Click on Resume button to continue executing the program up until the breakpoint.
5-3-3. Click on the memory tab. If you do not see it, go to Window Show View Memory.
5-3-5. Enter the address for the count variable as follows, and click OK.
Notice that the count variables increment every time you click resume.
5-3-8. Close the SDK application and close the XPS project.
Conclusion
This lab led you through adding an XPS timer and interrupt controller, and assigning an interrupt handler
function to the interrupting device via the software platform settings. You developed an interrupt handler
function and tested it in hardware. Additionally, you used the SDK debugger to view the content of
variables and memory.
Answer
1. What is the size of the compiled program?
# ##############################################################################
# Created by Base System Builder Wizard for Xilinx EDK 13.2 Build EDK_O.61xd
# Tue Jul 12 06:55:41 2011
# Target Board: Xilinx Spartan-3E Starter Board Rev D
# Family: spartan3e
# Device: XC3S500e
# Package: FG320
# Speed Grade: -4
# Processor number: 1
# Processor 1: microblaze_0
# System clock frequency: 50.0
# Debug Interface: On-Chip HW Debug Module
# ##############################################################################
PARAMETER VERSION = 2.1.0
BEGIN microblaze
PARAMETER INSTANCE = microblaze_0
PARAMETER C_AREA_OPTIMIZED = 1
PARAMETER C_USE_BARREL = 1
PARAMETER C_DEBUG_ENABLED = 1
PARAMETER HW_VER = 8.20.a
BUS_INTERFACE DLMB = dlmb
BUS_INTERFACE ILMB = ilmb
BUS_INTERFACE DPLB = mb_plb
BEGIN plb_v46
PARAMETER INSTANCE = mb_plb
PARAMETER HW_VER = 1.05.a
PORT PLB_Clk = clk_50_0000MHz
PORT SYS_Rst = sys_bus_reset
END
BEGIN lmb_v10
PARAMETER INSTANCE = ilmb
PARAMETER HW_VER = 2.00.b
PORT LMB_Clk = clk_50_0000MHz
PORT SYS_Rst = sys_bus_reset
END
BEGIN lmb_v10
PARAMETER INSTANCE = dlmb
PARAMETER HW_VER = 2.00.b
PORT LMB_Clk = clk_50_0000MHz
PORT SYS_Rst = sys_bus_reset
END
BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = dlmb_cntlr
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x00001fff
BUS_INTERFACE SLMB = dlmb
BUS_INTERFACE BRAM_PORT = dlmb_port
END
BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = ilmb_cntlr
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x00001fff
BUS_INTERFACE SLMB = ilmb
BUS_INTERFACE BRAM_PORT = ilmb_port
END
BEGIN bram_block
PARAMETER INSTANCE = lmb_bram
PARAMETER HW_VER = 1.00.a
BUS_INTERFACE PORTA = ilmb_port
BUS_INTERFACE PORTB = dlmb_port
END
BEGIN xps_uartlite
PARAMETER INSTANCE = RS232_DCE
PARAMETER C_BAUDRATE = 115200
PARAMETER C_DATA_BITS = 8
PARAMETER C_USE_PARITY = 0
PARAMETER C_ODD_PARITY = 0
BEGIN xps_gpio
PARAMETER INSTANCE = LEDs_8Bit
PARAMETER C_ALL_INPUTS = 0
PARAMETER C_GPIO_WIDTH = 8
PARAMETER C_INTERRUPT_PRESENT = 0
PARAMETER C_IS_DUAL = 0
PARAMETER HW_VER = 2.00.a
PARAMETER C_BASEADDR = 0x81440000
PARAMETER C_HIGHADDR = 0x8144ffff
BUS_INTERFACE SPLB = mb_plb
PORT GPIO_IO_O = fpga_0_LEDs_8Bit_GPIO_IO_O_pin
END
BEGIN mpmc
PARAMETER INSTANCE = DDR_SDRAM
PARAMETER C_NUM_PORTS = 1
PARAMETER C_SPECIAL_BOARD = S3E_STKIT
PARAMETER C_MEM_TYPE = DDR
PARAMETER C_MEM_PARTNO = MT46V32M16-6
PARAMETER C_MEM_DATA_WIDTH = 16
PARAMETER C_PIM0_BASETYPE = 2
PARAMETER HW_VER = 6.04.a
PARAMETER C_MPMC_BASEADDR = 0x8c000000
PARAMETER C_MPMC_HIGHADDR = 0x8fffffff
BUS_INTERFACE SPLB0 = mb_plb
PORT MPMC_Clk0 = clk_100_0000MHzDCM0
PORT MPMC_Clk90 = clk_100_0000MHz90DCM0
PORT MPMC_Rst = sys_periph_reset
PORT DDR_Clk = fpga_0_DDR_SDRAM_DDR_Clk_pin
PORT DDR_Clk_n = fpga_0_DDR_SDRAM_DDR_Clk_n_pin
PORT DDR_CE = fpga_0_DDR_SDRAM_DDR_CE_pin
PORT DDR_CS_n = fpga_0_DDR_SDRAM_DDR_CS_n_pin
PORT DDR_RAS_n = fpga_0_DDR_SDRAM_DDR_RAS_n_pin
PORT DDR_CAS_n = fpga_0_DDR_SDRAM_DDR_CAS_n_pin
PORT DDR_WE_n = fpga_0_DDR_SDRAM_DDR_WE_n_pin
PORT DDR_BankAddr = fpga_0_DDR_SDRAM_DDR_BankAddr_pin
PORT DDR_Addr = fpga_0_DDR_SDRAM_DDR_Addr_pin
PORT DDR_DQ = fpga_0_DDR_SDRAM_DDR_DQ_pin
PORT DDR_DM = fpga_0_DDR_SDRAM_DDR_DM_pin
PORT DDR_DQS = fpga_0_DDR_SDRAM_DDR_DQS_pin
PORT DDR_DQS_Div_O = fpga_0_DDR_SDRAM_ddr_dqs_div_io_pin
PORT DDR_DQS_Div_I = fpga_0_DDR_SDRAM_ddr_dqs_div_io_pin
END
BEGIN clock_generator
PARAMETER INSTANCE = clock_generator_0
PARAMETER C_CLKIN_FREQ = 50000000
PARAMETER C_CLKOUT0_FREQ = 100000000
PARAMETER C_CLKOUT0_PHASE = 90
PARAMETER C_CLKOUT0_GROUP = DCM0
BEGIN mdm
PARAMETER INSTANCE = mdm_0
PARAMETER C_MB_DBG_PORTS = 1
PARAMETER C_USE_UART = 1
PARAMETER HW_VER = 2.00.b
PARAMETER C_BASEADDR = 0x84400000
PARAMETER C_HIGHADDR = 0x8440ffff
BUS_INTERFACE SPLB = mb_plb
BUS_INTERFACE MBDEBUG_0 = microblaze_0_mdm_bus
PORT Debug_SYS_Rst = Debug_SYS_Rst
END
BEGIN proc_sys_reset
PARAMETER INSTANCE = proc_sys_reset_0
PARAMETER C_EXT_RESET_HIGH = 1
PARAMETER HW_VER = 3.00.a
PORT Slowest_sync_clk = clk_50_0000MHz
PORT Ext_Reset_In = sys_rst_s
PORT MB_Debug_Sys_Rst = Debug_SYS_Rst
PORT Dcm_locked = Dcm_all_locked
PORT MB_Reset = mb_reset
PORT Bus_Struct_Reset = sys_bus_reset
PORT Peripheral_Reset = sys_periph_reset
END
BEGIN xps_gpio
PARAMETER INSTANCE = dip
PARAMETER HW_VER = 2.00.a
PARAMETER C_GPIO_WIDTH = 4
PARAMETER C_ALL_INPUTS = 1
PARAMETER C_BASEADDR = 0x81420000
PARAMETER C_HIGHADDR = 0x8142ffff
BUS_INTERFACE SPLB = mb_plb
PORT GPIO_IO_I = dip_GPIO_IO_I
END
BEGIN xps_gpio
PARAMETER INSTANCE = push
PARAMETER HW_VER = 2.00.a
PARAMETER C_GPIO_WIDTH = 4
PARAMETER C_ALL_INPUTS = 1
PARAMETER C_BASEADDR = 0x81400000
PARAMETER C_HIGHADDR = 0x8140ffff
BUS_INTERFACE SPLB = mb_plb
PORT GPIO_IO_I = push_GPIO_IO_I
END
BEGIN lcd_ip
PARAMETER INSTANCE = lcd_ip_0
PARAMETER HW_VER = 1.00.a
PARAMETER C_BASEADDR = 0xcf400000
PARAMETER C_HIGHADDR = 0xcf40ffff
BUS_INTERFACE SPLB = mb_plb
PORT lcd = lcd_ip_0_lcd
END
BEGIN bram_block
PARAMETER INSTANCE = bram_block_0
PARAMETER HW_VER = 1.00.a
BUS_INTERFACE PORTA = xps_bram_if_cntlr_0_PORTA
END
BEGIN xps_bram_if_cntlr
PARAMETER INSTANCE = xps_bram_if_cntlr_0
PARAMETER HW_VER = 1.00.b
PARAMETER C_SPLB_NATIVE_DWIDTH = 32
PARAMETER C_BASEADDR = 0x88208000
PARAMETER C_HIGHADDR = 0x88209fff
BUS_INTERFACE SPLB = mb_plb
BUS_INTERFACE PORTA = xps_bram_if_cntlr_0_PORTA
END
BEGIN xps_timer
PARAMETER INSTANCE = delay
PARAMETER HW_VER = 1.02.a
PARAMETER C_ONE_TIMER_ONLY = 1
PARAMETER C_BASEADDR = 0x83c00000
PARAMETER C_HIGHADDR = 0x83c0ffff
BUS_INTERFACE SPLB = mb_plb
PORT Interrupt = timer1
PORT CaptureTrig0 = net_gnd
END
BEGIN xps_intc
PARAMETER INSTANCE = xps_intc_0
PARAMETER HW_VER = 2.01.a
PARAMETER C_BASEADDR = 0x81800000
PARAMETER C_HIGHADDR = 0x8180ffff
BUS_INTERFACE SPLB = mb_plb
PORT Irq = microblaze_0_INTERRUPT
PORT Intr = timer1
END