AceRoutine  1.4.1
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
Static Public Member Functions | List of all members
ace_routine::ClockInterface Class Reference

A utility class (all methods are static) that provides a layer of indirection to Arduino clock functions (millis() and micros()). More...

#include <ClockInterface.h>

Static Public Member Functions

static unsigned long millis ()
 Get the current millis.
 
static unsigned long micros ()
 Get the current micros.
 
static unsigned long seconds ()
 Get the current seconds. More...
 

Detailed Description

A utility class (all methods are static) that provides a layer of indirection to Arduino clock functions (millis() and micros()).

This thin layer of indirection allows injection of a different ClockInterface for testing purposes. For normal code, the compiler will optimize away the extra function call.

Definition at line 40 of file ClockInterface.h.

Member Function Documentation

◆ seconds()

static unsigned long ace_routine::ClockInterface::seconds ( )
inlinestatic

Get the current seconds.

This is derived by dividing millis() by 1000, which works pretty well until the unsigned long rolls over at 4294967296 milliseconds. At that last second (4294967), this function returns the next second (0) a little bit too early. More precisely, it rolls over to 0 seconds 704 milliseconds too early. If the COROUTINE_DELAY_SECONDS() is large enough, this inaccuracy should not matter too much.

The other problem with this function is that on 8-bit processors without a hardware division instruction, the software long division by 1000 is very expensive in both memory and CPU. The flash memory increases by about 150 bytes on AVR processors. Therefore, the COROUTINE_DELAY_SECONDS() should be used sparingly.

Definition at line 63 of file ClockInterface.h.


The documentation for this class was generated from the following file: