Foundation Drivers: Timeout - Oneshot Timer

Video demonstrating how to use Timeout drivers Oneshot Timer example code snippet.

Getting Started Topics

Video: Foundation Drivers - Timeout, Oneshot timer

Timeout_example.c when configured to generate a Oneshot example code snippet.

/**
\file
\brief This file contains sample source codes to demonstrate the common use cases if the Timeout Driver

For the examples to run, the user must only need to select which timer the Timeout driver will be used and configure the selected timer.

There are three use cases in this example:
<br>1. Oneshot Timer - After adding an event to the handler such as a pulse or an LED toggle, calling this example will run the the timer and execute the event exactly once.
<br>2. Periodic Timer - After adding an event to the handler such as a pulse or an LED toggle, calling this example will run the the timer and execute the event repeatedly.
<br>3. Stopwatch/Counter - Calling this example will run the the timer and return the number of timer ticks that has elapsed while a loop is executing.

Important Notes:
<br>1. Include the timeout_example.h header file in whichever file the Timeout_example_create_<mode>() functions will be called.
<br>2. If using MCC-generated GPIO operations and macros within the callbacks, make sure to include pin_manager.h (i.e. #include "../include/pin_manager.h")
<br>3. If using interrupt-driven timers, make sure global interrupts are enabled.
**/

#include "../drivers/timeout.h"
#include "timeout_example.h"    

/**
 * This timeout callback handler returns 0, does not reschedule the timer, so will execute only once. 
@param none
*/
static uint32_t oneshot_handler(void)
{
    //Put your application here
    
    return 0; // Do not reschedule timer
}
/**
 * Call this function to run a 1000-tick timer once. The timer will not be rescheduled in the associated callback function.
@param none
*/
void Timeout_example_create_scheduler_mode(void)
{
    timerStruct_t oneshot_timer = {oneshot_handler, NULL};
    timeout_create(&oneshot_timer,1000); //Create timer with the oneshot function as the callback handler, run timer for this number of ticks
    
    while(1)
    {
       timeout_callNextCallback(); 
    }
}