2.2 Foundation Drivers: Timeout - Periodic Timer
Video demonstrating how to use Timeout drivers Periodic Timer example code snippet.
Video: Foundation Drivers - Timeout, Periodic Timer
Timeout_example.c when configured to generate a Periodict 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 continuously reschedules a periodic timer to timeout with the number of ticks it returns. @param none */ static uint32_t periodic_handler(void) { //Put your application here return 1000; // Reschedule the timer after this many ticks } /** * Call this function to run a 1000-tick timer continuously. The callback function reschedules the timer continuously. @param none */ void Timeout_example_create_scheduler_mode(void) { timerStruct_t periodic_timer = {periodic_handler,NULL}; timeout_create(&periodic_timer,1000); //Create timer with the periodic function as the callback handler, run timer for this number of ticks. //The callback function determines for how many ticks the timer will be rescheduled. while(1) { timeout_callNextCallback(); } }