Keil Logo

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.

  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.