SUBLIBinal Use - PalouseRobosub/SUBLIBinal GitHub Wiki

SUBLIBinal Library Use

This wiki page describes how SUBLIBinal is intended to be used on a basic level. Please refer to the table of contents to be redirected to the appropriate documentation

Library Use


Basic Implementation

SUBLIBinal has been developed in a way that is intuitive and easy to use. The basic implementation of the library is to declare a structure for configuration, fill in the structure, and then call an initialization function. It is crucial that you initialize structures to 0 by initializing them = {0}. That way, if you don't use a parameter, the value will be declared as 0. Please refer to our structures documentation for more information. Configuration structures are typically named XXX_Config and initialization functions are typically named initialize_XXX(), where XXX refers to the module that you are implementing. Please refer to the main page for a list of available features within SUBLIBinal. A typical example of a timer implementation is shown below.

//....
int main() 
{
    Timer_Config configuration = {0};
    //....fill out structure
    initialize_Timer(configuration);

    while (1)
    {

    }
}
//....

top


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 will never return any values. Callback function input parameters are typically void. The exception to this is if the peripheral library utilizes a background process. If it does, it will require specific parameters. Please refer to the peripheral library specification to determine which input parameters to use.

top


The Background Process

The background process is used throughout SUBLIBinal for implementation of more complex designs. The background process is a process that is placed within the embedded system loop to ensure that interrupt driven programs are not routinely interrupted by time-intensive data management tasks. The background processes force all data processing to occur in a non-interrupt environment. This is useful when utilizing time-critical interrupts. The background process functions in removing nodes of data from buffers of information. The background process then takes a callback function from the node and calls the function with some provided parameter from the packet. When a function is called from the background process, it will universally need to accept parameters. Please refer to peripheral library specifications to determine what respective callback function parameters should be.

top


Interrupts

SUBLIBinal is an interrupt driven library. This means that events are triggered in an asynchronous fashion and do not follow normal program operation. SUBLIBinal treats all interrupts identical and will service the first interrupt that is triggered with the corresponding ISR if interrupts are enabled.

top