Timer System Service Library Details for Harmony v2

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 in implementing the MPLAB Harmony Timer System Service Library. Refer the following table for a description of each function:

sys_tmr_call_graph.png

If you enable interrupts for the Timer Driver used by the Timer System Service, DRV_TMR_Tasks() will be called by the Interrupt Service Routin e(ISR) Timer, instead of being called by the SYS_Tasks().

Function Name Source File Description
SYS_TMR_Initialize system_init.c Specify Timer Driver index and System Tick frequency
(Driver instance specified by the Timer Driver instance to use in MPLAB Harmony Configurator (MHC) (e.g. DRV_TMR_INDEX_0) )
(System Tick frequency specified by the 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 the 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 the value of Internal Time units 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 the number of 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 the 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 ISR Timer instead of the SYS_Tasks(). The ISR Timer can be found in the C source file SYSTEM_INTERRUPT.

tmr_drv_int_checked.png
Click image to enlarge.



file: SYSTEM_INTERRUPT

// 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
}

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.