Index

Cooperating Sequential Tasks

  1. Introduction
    1. Arduino
    2. Interrupts
  2. Simple Tasks
  3. Multiple Tasks
  4. Communicating Tasks
  5. Communicating Values
  6. Synchronising Tasks
  7. Buffered Communication
  8. Multiple Senders
  9. Conditional Tasks
  10. Transput
  11. Implementation
    1. Common Data
    2. Tasks
    3. task_builder
    4. task
    5. channel
    6. virtual_machine
    7. set
    8. queue
    9. clock
    10. standard
    11. Adjusting Limits

clock



The clock component provides a millisecond resolution time source, which cycles through a 16-bit range of values from 0 to 32767.

The clock uses the Arduino's milliseconds function, which provides a 32-bit range of values, however this range is truncated to 16-bits for convenience, as all the other functions of the multitasking library are based on 16-bit integers. This imposes a 32.767 second limit on the maximum duration of pause actions.

Functions

void init_clock();


The init_clock function is called when the multitasking library is initialised by the init_tasks function. It synchronises the clock with the internal Arduino's internal clock.

int  clock_time();


This function returns then clock time as a 16-bit value between 0 and 32767. It is used to record the starting_time of a pause action.

bool time_up(int start_time, int duration);


Given a start_time and a pause duration, the time_up function returns true if the clock has reached, or passed, the endpoint of the pause. It will correctly indicate when time is up even if the 16-bit clock has “wrapped round”, i.e, exceeded 32767 and resumed from 0, since the start_time.