Timer System Service Library Details

Many engineers want to understand how something works before they commit to using it. Learning how to use the MPLAB® Harmony Framework is a much easier task than understanding how the underlying framework works. This page is for those engineers that feel the need for a deeper understanding of how the framework works.

The following information is provided to satisfy your curiosity. You do not need to understand this to use the MPLAB Harmony Framework.

This call graph shows the important functions implementing the MPLAB Harmony Timer System Service Library. Refer to the following table for a description of each function.


If you enable interrupts for the Timer Driver used by the Timer System Service, DRV_TMR_Tasks() will be called by the timer interrupt service routine (instead of being called by SYS_Tasks() ). See below for details:

Function Name Source File Description
SYS_TMR_Initialize system_init.c Specify timer driver index and system tick frequency
(Driver instance specified by "Timer Driver Instance to Use" in MHC (e.g. DRV_TMR_INDEX_0) )
(System tick frequency specified by "Timer Running Frequency" in MHC)
DRV_TMR_Open drv_tmr.c Create a client for a Timer Driver
_SYS_TMR_Setup sys_tmr.c Calculate the timer period register value
(Based on "Timer Running Frequency" value in MHC)
Calculate the number of units to decrement the System Timer client counters for each System Timer tick
(Decrement rate based on "Internal Time Units" value in MHC)
Initialize the System Timer Object (sSysTmrObject)
DRV_TMR_AlarmRegister drv_tmr.c Initialize Timer Driver client object returned from DRV_TMR_Open
* Callback function for System Timer (not System Timer client)
(Function name: _SYS_TMR_AlarmCallback)
* Periodic or one-shot
* Period (ms) = timer counter frequency / system tick frequency
* Alarm count = 0
_SYS_TMR_ProcessTmrAlarm sys_tmr.c Executed if System Timer tick occurred
* Gets the number of system ticks (usually just one)
* Decrements each System Timer client counter by # system ticks * client decrement rate
(Client decrement rate name: sSysTmrObject.sysTickUnitCount)
* If the client counter is <= 0, execute System Timer client callback function
(Callback function name defined by you in SYS_TMR_CallbackPeriodic)
DRV_TMR_ProcessEvents drv_tmr.c If the timer event flag is set (timer counter = timer period register):
* Clear flag
* Increment the Timer Driver client alarm count
* Execute the System Timer callback function (not System Timer client callback)
Pass new alarm count to callback function
(System Timer callback function name: _SYS_TMR_AlarmCallback)
_SYS_TMR_AlarmCallback sys_tmr.c Assign new alarm count to System Timer tick counter
(System Timer tick count name: sSysTmrObject.sysTickCount)
Execute the System Timer process timer alarm function:
* If using a System Timer interrupt, run the System Timer process alarm ISR
ISR name: _SYS_TMR_ProcessIsrClients
* If not using a System Timer interrupt, set System Timer object alarm received flag.
Setting this flag causes _SYS_TMR_ProcessTmrAlarm to be executed.
(Alarm received flag name: sSysTmrObject.alarmReceived)

If Timer Driver Interrupts are enabled…

If you enable interrupts for the Timer Driver used by the Timer System Service, DRV_TMR_Tasks() will be called by the timer interrupt service routine (instead of being called by SYS_Tasks()). The timer interrupt service routine can be found in the system_interrupt.c source file.

Click image to enlarge.

file: system_interrupt.c

// Timer1 ISR (Timer Driver instance 0)
void __ISR(_TIMER_1_VECTOR, ipl1AUTO) IntHandlerDrvTmrInstance0(void)
DRV_TMR_Tasks (sysObj.drvTmr0); // pass pointer to object defining timer driver instance 0

© 2017 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.