1 / 40

Lab5 Advanced Software Writing Lab : MicroBlaze

Lab5 Advanced Software Writing Lab : MicroBlaze. Objectives. 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. Procedure.

floyd
Download Presentation

Lab5 Advanced Software Writing Lab : MicroBlaze

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab5Advanced Software Writing Lab : MicroBlaze

  2. Objectives • 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.

  3. Procedure • 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 GPIO BRAM PSB GPIO LEDs 7Seg LED My IP GPIO SWs

  4. Opening 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.

  5. Opening 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.

  6. Modify the MHS File and add an Interrupt Controller • Double-click the system.mhs file to open it in the XPS editor.

  7. Modify 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.

  8. Modify the MHS File and add an Interrupt Controller • Click Project  Add Cores (dialog).

  9. Modify the MHS File and add an Interrupt Controller • In the Peripherals tab, add the opb_intc peripheral. 1. 2. 3.

  10. Modify 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.

  11. Modify 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.

  12. Modify 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.

  13. Modify 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 <OK>. 2. 3. 4.

  14. Modify 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.

  15. Configure the BSP • Using Project  Software Platform Settings … open the Software Platform Settings GUI.

  16. Configure the BSP • Click on the Processor, Driver Parameters and Interrupt Handlers tab. • Enter timer_int_handler in the Current Value field as a interrupt_handlerfunction, as shown in following figure. • Click 確定to accept the settings. • Click Tools  Generate Libraries to update the generated libraries and xparameters.h file.

  17. Write the Interrupt Handler and Compile the Code • Copy the system_timer.c and 7segled.c files to the current project X:\EDKlab\Lab5\code.

  18. Write 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. Thisis necessary because there is no interrupt handler in this project. 1. 2. 4. 3.

  19. Write 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 andselecting Add File… then navigate to the sources and add them. 1. 2. 3. 4. 5.

  20. Write 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.

  21. Write 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.

  22. Write 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.

  23. Write the Interrupt Handler and Compile the Code • In Windows, Click Start  Programs  Xilinx Platform Studio 6.3i  Documentation  EDK 6.3i Reference & User Guides.

  24. Write the Interrupt Handler and Compile the Code • Scroll down to the bottom of the page and click Processor IP Reference Guide.

  25. Write 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.

  26. Write 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:

  27. Write 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 -> (XTC_DEVICE_TIMER_COUNT - 1). • Returns: • The value read from the register, a 32-bit value.

  28. Write 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_MASK parameter. • if (csr & XTC_CSR_INT_OCCURED_MASK) • { • timer_count++; • }

  29. Write 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);

  30. Write 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.

  31. Write 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.

  32. Write 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.

  33. Write 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.

  34. Write the Interrupt Handler and Compile the Code • In the Applications tab, double-click on Compiler Options. • Click on the Directories tab. 2. 1. 3.

  35. Write 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\src\ directory, and select TestAppLinkScr to add it to the project. • Click 確定to accept the setting. 1. 2. 3. 4.

  36. Write 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.

  37. Write 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.

  38. Write 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.

  39. Verifying 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.

  40. Conclusion • 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.

More Related