Keil Logo

Signal Functions

Signal Functions repeat operations in the background while µVision runs the target program. They help simulating and testing serial and analog I/Os, port communications, and other repetitive external events, like signal inputs and pulses.

Signal functions are created by the developer directly in the Command window or using the function editor. Refer to Creating Functions for details.

It is mandatory to call the built-in function twatch at least once to delay execution and let µVision run the target program. An error is triggered for signal functions that never call twatch. System Variables can be used in signal functions.

Signal functions begin with the keyword SIGNAL and are defined as follows:

SIGNAL void fname (parameter_list) {
  statements
}

Where

fname Is the name of the function.
void The return type of a signal function must be void.
parameter_list Is the list of arguments passed to the function. Each argument must have a type and a name. If no arguments are passed, then use void for the parameter_list. Multiple arguments are separated by commas. A signal function can have a maximum of eight parameters.
statements Are instructions the function carries out.
{ } Are the opening and closing braces. The function definition is complete when the number of open braces is balanced with the number of the closing braces.

Example

The following signal function puts the character 'A' into the serial input buffer, delays for 1,000,000 CPU states, and repeats.

SIGNAL void StuffS0in (void) {
  while (1) {
    S0IN = 'A';
    twatch (1000000);
  }
}

Invoke the function by typing the function name into the Command window.

StuffS0in()

Restrictions

  • The return type of a signal function must be void.
  • A maximum of eight function parameters are allowed.
  • Signal functions may not be invoked from User Functions.
  • Signal functions cannot be aborted using Ctrl+C.

Managing Signal Functions

µVision maintains a queue for all active signal functions. A signal function can have the state idle or running. When a signal function invokes the twatch function, it goes into the idle state for the number of CPU states passed to twatch. After the user program has executed the specified number of CPU states, the signal function becomes running. Execution continues at the statement after twatch.

When invoked, the signal function is added to the queue and gets marked as running. Signal functions can be invoked only once. If the function is invoked twice, then a warning is displayed.

If a signal function exits because of a return statement, then it is removed automatically from the queue of active signal functions.

The command SIGNAL STATE shows the state of all active signal functions.
The command SIGNAL KILL fname removes a signal functions from the queue.

Analog Example

The following example shows a signal function that varies the analog input ain0 on a C167. The function increases and decreases the input voltage by 0.5 volts between 0V and an upper limit specified in the function argument. This signal function repeats indefinitely, delaying 200,000 CPU states for each voltage step.

signal void analog0 (float limit) {
float volts;

printf ("Analog0 (%f) entered.\n", limit);
  while (1) {           /* forever */
    volts = 0;
    while (volts <= limit) {
      ain0 = volts;     /* analog input-0 */
      twatch (200000);  /* 200000 states Time-Break */
      volts += 0.5;     /* increase voltage */
    }
    volts = limit;
    while (volts >= 0.0) {
      ain0 = volts;
      twatch (200000);  /* 200000 states Time-Break */
      volts -= 0.5;     /* decrease voltage */
    }
  }
}

Invoke the function:

>ANALOG0 (5.0)           /* Start of 'ANALOG()' */

View the state of the function:

>SIGNAL STATE
 1  idle     Signal = ANALOG0 (line 8)

The Command window lists the internal function number, the status of the signal function, the function name and the line number that is executing.

Remove the function from the queue of active signal functions.

>SIGNAL KILL ANALOG0

Related Knowledgebase Articles

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.