Lab 5 Advanced Software Writing Lab Micro Blaze
Lab 5 Advanced Software Writing Lab : Micro. Blaze for EDK 6. 3 i
Objectives n n 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. for EDK 6. 3 i 1
Procedure n 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. n OPB Bus MDM Micro. Blaze LMB BRAM Cntlr INTC LMB BRAM Cntlr Timer BRAM 7 Seg LED UART My IP GPIO PSB GPIO LEDs GPIO SWs Interrupt for EDK 6. 3 i 2
Opening the Project n Create a lab 5 folder in the X: EDKLab directory. If you wish to continue with your completed design from lab 4 then copy the contents of the lab 4 folder into the lab 5 folder. 1. 2. for EDK 6. 3 i 3. 4. 3
Opening the Project n Open XPS, click File → Open Project and browse to the project which is in the directory: X: EDKLablab 5, then click system. xmp to open the project. 1. 2. for EDK 6. 3 i 4
Modify the MHS File and add an Interrupt Controller n Double-click the system. mhs file to open it in the XPS editor. for EDK 6. 3 i 5
Modify the MHS File and add an Interrupt Controller n Add the following line at the end of the Delay instance parameters (before the END keyword). n n PORT Interrupt = timer 1 Save and Close the MHS file. for EDK 6. 3 i 6
Modify the MHS File and add an Interrupt Controller n Click Project Add Cores (dialog). for EDK 6. 3 i 7
Modify the MHS File and add an Interrupt Controller n In the Peripherals tab, add the opb_intc peripheral. 2. 1. 3. for EDK 6. 3 i 8
Modify the MHS File and add an Interrupt Controller n n 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 0 x 80001 c 00 and the high address to 0 x 80001 dff. 1. 3. 4. for EDK 6. 3 i 2. 9
Modify the MHS File and add an Interrupt Controller n Using the Ports tab, add the OPB_Clk, Intr, and Irq ports of the opb_intc_0 as internal. 2. 1. 3. for EDK 6. 3 i 10
Modify the MHS File and add an Interrupt Controller n Change the net names of the OPB_Clk and Irq ports of the opb_intc_0 instance to sys_clk_s and interrupt, respectively. for EDK 6. 3 i 11
Modify the MHS File and add an Interrupt Controller n n n Select the browse button under Net Name next for Intr to open the Connect and Prioritize Interrupts dialogue box. 3. Select timer 1 from the High Priority list (right-side) and click the Add button to add the interrupt output of the 4. delay instance to the input of the interrupt controller opb_intc. Click <OK>. for EDK 6. 3 i 1. 2. 12
Modify the MHS File and add an Interrupt Controller n n 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. for EDK 6. 3 i 1. 2. 3. 4. 13
Configure the BSP n Using Project Software Platform Settings … open the Software Platform Settings GUI. for EDK 6. 3 i 14
Configure the BSP n n 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. for EDK 6. 3 i 15
Write the Interrupt Handler and Compile the Code n Copy the system_timer. c and 7 segled. c files to the current project X: EDKlabLab 5code. for EDK 6. 3 i 16
Write the Interrupt Handler and Compile the Code n Make the Test. App project inactive. Under the Applications Tab, right click on the Test. App project title and select Make Project Inactive. This is necessary because there is no interrupt handler in this project. 1. 2. 4. 3. for EDK 6. 3 i 17
Write the Interrupt Handler and Compile the Code n n Remove system. c from the Project: My. Proj project by right clicking on it under Sources and deleting it. Add the two new files system_timer. c and 7 segled. c to the My. Proj 3. project by right clicking on Sources and selecting Add File… then navigate to the sources and add them. 1. 2. 4. 5. for EDK 6. 3 i 18
Write the Interrupt Handler and Compile the Code n 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. for EDK 6. 3 i 19
Write the Interrupt Handler and Compile the Code n Create a new global variable to be used in the interrupt handler code: n n n Xuint 32 timer_count = 0; Note: The Xuint 32 type is declared in #include "xbasic_types. h" xutil. h. Save the file. for EDK 6. 3 i 20
Write the Interrupt Handler and Compile the Code n n n 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: n n n Xuint 32 baseaddr = (int)baseaddr_p; Xuint 32 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. for EDK 6. 3 i 21
Write the Interrupt Handler and Compile the Code n In Windows, Click Start Programs Xilinx Platform Studio 6. 3 i Documentation EDK 6. 3 i Reference & User Guides. for EDK 6. 3 i 22
Write the Interrupt Handler and Compile the Code n Scroll down to the bottom of the page and click Processor IP Reference Guide. for EDK 6. 3 i 23
Write the Interrupt Handler and Compile the Code n 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. for EDK 6. 3 i 24
Write the Interrupt Handler and Compile the Code n Go to the Register Description section in the data sheet and study TCSR 0 Register. Notice that bit 23, T 0 INT, has the following description: for EDK 6. 3 i 25
Write the Interrupt Handler and Compile the Code n 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 TCSR 0. We can use the following function to determine whether the interrupt has occured: n n The following is the documentation associated with the OPB timer: n n XTmr. Ctr_m. Get. Control. Status. Reg( ) XTmr. Ctr_m. Get. Control. Status. Reg ( Base. Address, Tmr. Ctr. Number ) Get the Control Status Register of a timer counter. n Parameters: n n n Base. Address is the base address of the device. Tmr. Ctr. Number is the specific timer counter within the device, a zerobased number, 0 -> (XTC_DEVICE_TIMER_COUNT - 1). Returns: n for EDK 6. 3 i The value read from the register, a 32 -bit value. 26
Write the Interrupt Handler and Compile the Code n Add this function call to the code with the associated parameters. The resulting 32 -bit value should be stored in the variable csr. n n csr = XTmr. Ctr_m. Get. Control. Status. Reg(baseaddr, 0); Using the value returned to csr, test to see if bit 23 is set by using the XTC_CSR_INT_OCCURED_MASK parameter. n n if (csr & XTC_CSR_INT_OCCURED_MASK) { timer_count++; } for EDK 6. 3 i 27
Write the Interrupt Handler and Compile the Code n If the interrupt was taken, increment a counter. The count value should then be displayed by using the 7 Seg. LED peripheral. A subroutine to do the display is included in the 7 Seg. LED. c file. The following call will display the value in timer_count on the display and light the decimal point in position 1. n n disp. LED(timer_count, 1); Clear the interrupt by using the following function call: n XTmr. Ctr_m. Set. Control. Status. Reg(baseaddr, 0, csr); for EDK 6. 3 i 28
Write the Interrupt Handler and Compile the Code n 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. for EDK 6. 3 i 29
Write the Interrupt Handler and Compile the Code n n 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. for EDK 6. 3 i 4. 30
Write the Interrupt Handler and Compile the Code n n n Generate the hardware system, click Tools Generate Netlist. Plat. Gen will regenerate the hardware system because you added the interrupt controller to the MHS file. Compile the source file. for EDK 6. 3 i 31
Write the Interrupt Handler and Compile the Code n Why do you think the program is so big? n n 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. for EDK 6. 3 i 32
Write the Interrupt Handler and Compile the Code n n In the Applications tab, double-click on Compiler Options. Click on the Directories tab. 2. 1. 3. for EDK 6. 3 i 33
Write the Interrupt Handler and Compile the Code n Click on the browse button of the linker script file entry, browse to the X: EDKlabLab 5Test. Appsrc directory, and select Test. App. Link. Scr to add it to the project. 1. 2. n 3. Click 確定 to accept the setting. for EDK 6. 3 i 4. 34
Write the Interrupt Handler and Compile the Code n n Close the project so that the peripheral can be seen by XPS, File Close Project. Open the project by clicking File Recent Projects …lab 5system. xmp from XPS. alter the xil_printf function call to printf in main. In the Test. App. Link. Scr file, change the stack and heap size to 0 x 200 each. for EDK 6. 3 i 35
Write the Interrupt Handler and Compile the Code n 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 (16 K in lmb). n Change the printf function to xil_printf in main. n Save the changes. for EDK 6. 3 i 36
Write the Interrupt Handler and Compile the Code n n 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. for EDK 6. 3 i 37
Verifying in Hardware n n n 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 lab 5etc directory. for EDK 6. 3 i 38
Conclusion n 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 Lib. Gen 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. for EDK 6. 3 i 39
- Slides: 40