Foundation Drivers: Timeout - Periodic mode with Payload

Video demonstrating how to use Timeout driver's payload example code snippet.

Getting Started Topics

Video: Foundation Drivers - Timeout, Periodic mode with Payload

Timeout_example.c when configured to generate a Periodic mode with payload 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 handler executes a repeating, periodic timer that uses a payload argument.
@param payload - any value that needs to be passed onto the handler.
*/
static uint32_t periodic_handler_payload(void *payload)
{
    uint8_t *p = (uint8_t *)payload;
	*p         = *p + 1;
	if (*p < 11) // Run timer 10 times
	{
            //Put your application here
                
            return 1000; // Reschedule the timer after this many ticks
	}
	return 0; // Stop the timer
   
}
/**
 * Call this function to run a 1000-tick timer 10 times, with the counter sent as a payload.
@param none
*/
void Timeout_example_create_sched_periodic_with_payload(void)
{
    uint8_t timeout_count = 0;
    timerStruct_t periodic_timer_payload = {periodic_handler_payload, (void *)&timeout_count}; //Initialize the timer with the callback handler and a pointer to the payload 
    timeout_create(&periodic_timer_payload,1000); //Schedule the specified timer task, number ticks to initial timeout
                                                  //The callback function determines for how many ticks the timer will be rescheduled. 

    while(1)
    {
       timeout_callNextCallback(); 
    }
}