RTX51 Tiny User's Guide

Multi-Tasking Programs

More sophisticated C programs may implement a pseudo-multitasking scheme where several functions (or tasks) are called in a loop. For example:

void main (void)
{
int counter = 0;

while (1)                  /* repeat forever */
  {
  check_serial_io ();      /* check for serial input */
  process_serial_cmds ();  /* process serial input */

  check_kbd_io ();         /* check for keyboard input */
  process_kbd_cmds ();     /* process keyboard input */

  adjust_ctrlr_parms ();   /* adjust the controller */

  counter++;               /* increment counter */
  }
}

In this example, each function performs a separate operation or task. The functions (or tasks) are executed in order, one after another.

Scheduling starts to become an issue as more tasks are added. For example, if the process_kbd_cmds function executes for a long time, the main loop may take too long to get back around to the check_serial_io function and serial data may be lost. Of course, the check_serial_io function may be called more often in the main loop to correct this issue, but eventually this technique will not work.