Keil Logo

Traffic Example

The Traffic example represents a pedestrian traffic light showing the use of the RTX-RTOS. The traffic light operates during a user-defined time interval. Outside this time interval, the yellow light flashes. If a pedestrian pushes the request button, the traffic light goes immediately into walk state.

Software

The project located in the folder \ARM\RL\RTX\Examples\Traffic contains the files:

TRAFFIC.C includes the traffic light controller program, which is divided into the following tasks:

  • init: initializes the serial interface and starts all other tasks. This task deletes itself.
  • command: controls and processes the received serial commands.
  • clock: controls the time.
  • blinking: flashes the yellow light when the current time is outside the active time interval.
  • lights: controls the traffic light phases while the clock time is in the active time range (between the start and end times).
  • keyread: reads the pedestrian push button and sends a signal to the task lights.
  • get_escape: If an ESC character is found in the serial stream, the task command gets a signal to terminate the display command.

SERIAL.C implements the interrupt controlled and event driven serial I/O interface.

GETLINE.C reads and processes the commands from the serial port.

Startup.s provides the microcontroller startup configuration.

RTX_Config.c configures the RTX-RTOS and provides global functions.

Traffic Light Commands

The table below lists the traffic light commands:

Command Meaning Description
D Display Displays the clock, start, and end times.
T hh:mm:ss current Time Sets the current time in 24-hour format.
S hh:mm:ss Start time Sets the interval start time in 24-hour format. The traffic light operates between the start and end time. Outside this interval, the yellow light flashes.
E hh:mm:ss End time Sets the interval end time in 24-hour format. The traffic light operates between the Start and End time. Outside this interval, the yellow light flashes.
ESC Abort command Press the ESC-key to abort the command.

Test the Traffic Example

The project is delivered with the target Simulator. To test the example:

  1. Debug Button Start the µVision debugger.
  2. Run Button Run the TRAFFIC application. Enable ViewPeriodic Window Update to view the lights in the Watch Window during program execution.
  3. Serial Window The serial window UART #2 displays the output and allows entering the commands described in the table above.
  4. Set the clock time outside of the active time interval to flash the yellow light.

    Traffic Output

  5. Watch Window The watch variables show the ports that drive the lights.

    Watch Variables

  6. The push_key signal function simulates the pedestrian push key that switches the light system to the walk state. This function is called from the Toolbox button Push for Walk.

    Toolbox

  7. Use the menu Debug — Function Editor to open the file TRAFFIC.INC. This file is specified in Options for Target — Debug — Initialization File and defines the signal function push_key, the port initialization, and the toolbar button.

    Function Editor

  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.