Skip to content

Important Library Features

Ryan Summers edited this page Sep 6, 2015 · 9 revisions

Structure Declaration

When using the library, it is extremely important that structures are initialized to zero. When declaring structure variables, please use the following convention:

Timer_Config timer_configuration = {0};

This will ensure that all variables within the structure are initialized to 0. If structures are not initialized the zero, the library may work improperly. An example of this occurs if the callback function is not declared as NULL and does not point to an actual function. If this is the case, then the program will link to a function that does not exist and normal C execution will break as a result of a dangling reference.

The Callback Function

The callback function is used within almost every structure created by SUBLIBinal. The callback function is what drives interrupt driven designs. A callback function is simply a pointer to a function that will execute when an interrupt occurs. To supply a callback function, simply declare a function and hand a reference to it to the configuration structure. Please see the following example:

#include "sublibinal.h" //include the library header file

void foo() {
    //implement functionality that will run when the timer interrupt occurs
}

void main() {

    Timer_Config t_con = {0};
    //... Fill out portions of the structure 

    t_con.callback = &foo; //supply a pointer to the function foo

    initialize_Timer(t_con);

    //...Complete other initialization

    while (1) {
        //Embedded system loop, implement what you would like in here!
    }
}

The callback function provides expandable functionality to the interrupt service routines. The code provided in the callback function will be executed whenever the interrupt is triggered.

Please note: Callback functions must return void and accept no arguments.

Clone this wiki locally