Timeout Driver

This file recounts the basic use cases and implementation of the Timeout Driver.

Timeout Basics

The Timeout Driver Software Library is a code library that aims to provide an abstraction interface to Timer-type peripherals such as the Timer0/1/2 peripherals and their derivatives; the Signal Measurement Timer (SMT); and the Hardware Limit Timer (HLT). On top of this hardware abstraction, the application side interface allows users to create applications that need a timeout event after a specified time. The driver can register multiple timers with different callbacks that trigger different events upon their corresponding timer expiration. There are also options to run timers just once or repeatedly to provide users the flexibility of using the timer peripherals as one-off countdown timers or periodic timers. The Timeout Driver library is part of the MCC Foundations Services Library that aims to simplify further the configuration of the different peripherals for the benefit of first-time users and those with a limited MCU programming background.

In general, the Timeout driver can be used two different ways:

  • Scheduled Timer mode. This mode enables users to schedule events to happen at different times. The scheduled timer can be used as a oneshot timer which runs only once, or as a periodic timer which can run repeatedly.
  • Stopwatch/Cycle Counter mode. This mode enable users to measure time elapsed between or during events.

Timeout Implementation

The Timeout Driver Software Library uses structures and linked-list implementation to perform functionalities such as creating, adding, and deleting timers. The term "timer" that will be referred to in this discussion is represented by a structure timerStruct whose members are shown below:

typedef struct tmrStruct { timercallback_ptr_t callbackPtr;

void* payload;

struct tmrStruct* next;

ABSOLUTETIME_t absoluteTime;

} timerStruct_t;

The member callbackPtr with data type timercallback_ptr_t is a function pointer that points to a function that handles the event that would be triggered at the end of the timer period, henceforth referred to as the callback function.

The void pointer payload contains the data that the user would like to pass along to the callback function.

The pointer next is a pointer to another timer structure that is the next in line to be run after this current timer expires.

ABSOLUTETIME_t is a typedef to represent the maximum length of time the timers would run. It is defined in timeout.h generated by the MCC as an unsigned 32 bit integer. The structure member absoluteTime holds the time or more accurately, the number of ticks the timer would count before this timer expires.