Guidelines for Developing a Nios II HAL Device Driver

ID 683146
Date 6/12/2015
Public
Document Table of Contents

1.12.2. Setting Watchpoints in the HAL UART Device Driver

In this section, you intercept the Nios II processor by placing a watchpoint on a UART peripheral register. A watchpoint is a special breakpoint that pauses the execution of an application whenever the value of a given expression changes. To watch for any writes to the transmit register on the UART, you can set up a write-access watchpoint on the register.

To set a watchpoint, perform the following steps:

  1. Start the debugging session for the hello_world_my_uart project.
  2. Open the Breakpoints view. If the Breakpoints view is not visible, open it through the Window menu, by pointing to Show View and clicking Breakpoints.
  3. Open the menu by clicking the drop-down arrow in the upper right corner of the view, and click Add Watchpoint (C/C++).
  4. In the Add Watchpoint dialog box, type a value in the Expression to watch field that equals the uart1 base value plus an offset of one long word. This value accesses the transmit register. In the case of the design example accompanying this application note, this value is 0x84.
  5. In the Access section, turn on Write and turn off Read.
  6. Click OK. The Add Watchpoint dialog box closes.
  7. Click the Resume button.

    The Nios II processor executes until it writes the first character, H. The processor writes this character when the my_uart_txirq() function invokes the macro IOWR_MY_UART_TXDATA(), as shown in the figure below.

    View the transmit register value in the Eclipse Memory view. Notice that the value changes when the debugging stops at the watchpoint.

    Look at the call stack in the upper left corner of the Nios II Debug perspective. The call stack records each call leading up to this point, including each function invoked to process the transmit interrupt.

    The alt_shadow_non_preemptive_interrupt() function calls my_uart_irq().

Figure 21. Setting Watchpoints in the UART's Transmit Register