Document License This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/us/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. Contributors to this document Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ SYS/BIOS On-Line Training Introduction to Timers / Clocks SYS/BIOS 1 SYS/BIOS Timing Services • Timer Module – Manages timer peripherals – Provides target/device abstraction • Clock Module – Manages BIOS “heartbeat” – Can schedule functions to fire in the future (one-shot or periodically) – Input can be configured to use Timer module “tick” or application “tick” • Timestamp Module – Provides simple time stamping services for benchmarking code – Allows time stamping RTA logs 2 BIOS Timer Architecture Func1() Application Software Fired as One-Shot or Periodic BIOS Software ISR BIOS Timer Module Timer Peripheral Timer Peripheral Timer Peripheral MSP430 Hardware 3 BIOS Timer/Clock Architecture Func1() Func2() Func3() Func4() Application Software Fired as One-Shot or Periodic Swi_post() Clock.doTick() BIOS Clock Module BIOS Software ISR BIOS Timer Module Timer Peripheral Timer Peripheral Timer Peripheral MSP430 Hardware 4 Controlling a Clock Function Clock created and started with startFlag or Clock_start() Func runs One-shot Clock timeout Func runs Continuous Clock timeout period Func runs period Func runs ... Time • Clock_start(), Clock_stop(): Clock Instances can be stopped/restarted – Can only be called from the context of the Clock Swi • Clock_tickStart()/Clock_tickStop(): starts/stops the timer generating the underlying timer tick • Clock_setPeriod(), Clock_setTimeout(), Clock_setfunc(): Modifies a stopped Clock instance • Clock_tickReconfig allows Clock params to be reconfigured based on a new timer frequency 5 Clock Run-Time API Clock_Params clockParams; Task_Handle myClock; Error_block eb; Clock_Params_init(&clockParams); clockParams.period = 4; /* every 4 Clock ticks */ clockParams.startFlag = TRUE; /* start immediately */ Error_init(&eb); myClock = Clock_create((Clock_FuncPtr)clockHandler, 4, &clockParams, &eb); Clock_create Clock_delete Clock_getTicks Clock_getTimeout Clock_getTimerHandle Clock_Params_init Clock_setFunc Clock_setPeriod Clock_setTimeout Clock_start Clock_stop Clock_tick Clock_tickReconfig Clock_tickStart Clock_tickStop Allocate and initialize a new instance object and return its handle Finalize and free this previously allocated instance object, setting the referenced Time in Clock ticks Get timeout of instance Get timer Handle Initialize this config-params structure with supplier-specified defaults before Overwrite Clock function and arg Set periodic interval Set the initial timeout Start instance Stop instance Function called by the timer isr when tickSource is TickSource_TIMER Reconfigure clock for new cpu frequency Start clock after reconfiguration Stop clock for reconfiguration 6 Configuring the Clock Module with XGCONF timerId: specify -1 to request any timer swiPriority: priority of the clock functions running periodically (defaults to 15) tickPeriod: specifies period between system ticks (defaults to 1000 usec) tickSource: • tickSource_TIMER: creates timer to generate system tick (periodic call to Clock_tick) • tickSource_USER: application calls Clock_tick from a user interrupt • tickSource_NULL: no APIs with a timeout value and no Clock APIs. 7 * Adding a Clock Object With XGCONF clockfxn: function to be called timeout: initial period period: sets subsequent timeout interval (in Clock ticks). One-shot => set to 0. startFlag: • true => starts immediately • false => starts on call to Clock_start() arg: argument to clockFxn 8 *
© Copyright 2026 Paperzz