Archived: Determining When and How to Implement Callbacks in a Blackfin Application

Updated Nov 2, 2020

Environment

Software

  • LabVIEW

Other

  • Blackfin

This document has been archived and is no longer updated by your friends at NI.

The LabVIEW Embedded Module for ADI Blackfin Processors allows you to program the Analog Devices Blackfin Processor using LabVIEW. In many designs, the processor must monitor an external device for a signal, such as a push button press, and when that signal is received, some reaction is needed. In this document, we will discuss the two primary ways -- polling and callbacks -- you can use to respond to external signals in an embedded application.
 

Polling and callbacks are the two primary ways a processor responds to an external signal. With polling, the processor constantly monitors the signal and waits for a change. When a change is detected, the processor continues its execution and handles the change accordingly. The major benefit of using polling is that the application has the fastest possible response to the signal. However, polling requires that some of the processor's computation time be dedicated to the polling operation. Therefore, any additional operations that occur in parallel to the polling does not have full use of the processor.


With callbacks, also known as interrupts, the processor does not need to explicitly monitor the signal in the application. Instead, the application registers the signal with the embedded operating system, which for the Blackfin processor is the Visual DSP++ Kernel (VDK). When the OS detects the signal, the OS temporary halts the embedded application and executes an interrupt service routine (ISR). Once the ISR completes, the execution returns to the embedded application. The main benefit of using callbacks is that the main embedded application does not have to spend processor resources on monitoring a signal. Therefore, parallel applications are more efficient. However, callbacks do introduce a delay, or latency, between when the signal is detected and the corresponding reaction.

In general, if the application is performing a single task, or if minimizing latency is critical, polling is probably the most appropriate. If the application has many parallel operations or if latency is tolerable, callbacks are most suitable.

You can use a Case structure, the BF Is Button Pushed VI, and a While Loop to poll a push button. No additional configuration is needed.


 

Creating a callback-based application requires a bit more configuration than polling. You must associate the callback VI with a push button. Complete the following steps to associate a callback VI with a push button.

  1. Create a blank VI and save it.
  2. Place a Static VI Reference, located on the Functions»Application Control palette, on the LabVIEW block diagram.
  3. Right-click the Static VI Reference and select Browse for Path from the shortcut menu. Browse to and select the callback VI you saved in step 1.
  4. Wire the Static VI Reference to the callback VI reference input of the Enable Button Interrupt VI to associate the VI with the callback that occurs when you press a push button on the EZ-KIT.
  5. Configure the callback VI as an Interrupt Service Routine (ISR).
    1. Select Tools»Embedded Project Manager to open the Embedded Project Manager window.
    2. Create a new Embedded Project (LEP) or open an existing project.
    3. Add the callback VI to the Embedded Project.
    4. Select Target»Configure Interrupt VIs in the Embedded Project Manager window to open the Configure Interrupt VIs dialog box.
    5. Select the callback VI and place a checkmark in the Interrupt Service Routine checkbox.
    6. Click the OK button.

Firing a Timed Loop from a Callback VI
When using callbacks, or interrupts, you need to create a separate thread to free up processor resources. Use a Timed Loop to create a separate thread that sleeps until the OS detects the interrupt. In the Embedded Module for Blackfin Processors, each Timed Loop executes in its own OS thread. You can independently set the priority of each Timed Loop as well as select the timing source.

Before you can fire a Timed Loop from an ISR VI, you must create an external timing source. Use the Create External Timing Source VI to create the external timing source. Use the Fire External Timing Source VI to fire a Timed Loop from and ISR VI.

As a general rule, you want to spend as little time as possible in the interrupt. ISR VIs have limited capabilities. One of the limitations is that no memory allocation is allowed. Because placing a string constant on the block diagram of the ISR VI allocates memory, use a global variable to get the name of the external timing source.

To configure a Timed Loop to fire from an external timing source, you must configure the Timed Loop options so the external timing source appears as an input of the Timed Loop. Complete the following steps to configure the Timed Loop so the external timing source appears as an input.

  1. Right-click the Input Node of the Timed Loop and select Configure Timed Loop from the shortcut menu to open the Loop Configuration dialog box.

  2. Under Timing source, place a checkmark in the Use terminal checkbox.

  3. Click the OK button.

You can now wire a string to the Input Node of the Timed Loop.