SYS/BIOS  7.00
Clock.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated - http://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
200 /*
201  * ======== Clock.h ========
202  */
203 
204 #ifndef Clock__include
205 #define Clock__include
206 
207 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
209 #include <xdc/std.h>
212 #include <stdbool.h>
213 #include <stddef.h>
214 #include <stdint.h>
215 
216 #include <ti/sysbios/knl/Queue.h>
217 #include <ti/sysbios/knl/Swi.h>
218 
220 
221 /* @cond NODOC */
222 #define ti_sysbios_knl_Clock_long_names
223 #include "Clock_defs.h"
226 #ifdef __cplusplus
227 extern "C" {
228 #endif
229 
230 /*
231  * Error and Assert Ids
232  */
233 
237 #define Clock_A_clockDisabled "Cannot create a clock instance when BIOS.clockEnabled is false."
238 
242 #define Clock_A_badThreadType "Cannot create/delete a Clock from a Hwi or Swi thread."
243 
247 #define Clock_A_badTimeout "Bad timeout value."
248 
250 typedef struct Clock_Params Clock_Params;
251 typedef struct Clock_Struct Clock_Struct;
252 typedef struct Clock_Struct Clock_Object;
255 
283 };
285 
292 };
297 
301 typedef void (*Clock_FuncPtr)(uintptr_t arg1);
302 
303 /* Params */
304 struct Clock_Params {
325  bool startFlag;
342  uint32_t period;
348  uintptr_t arg;
349 };
350 
351 /* Module_State */
354  volatile uint32_t ticks;
355  unsigned int swiCount;
358  volatile unsigned int numTickSkip;
360  uint32_t maxSkippable;
362  volatile bool startDuringWorkFunc;
363  bool ticking;
378  Clock_TickMode tickMode;
390  uint32_t tickPeriod;
400  Clock_TickSource tickSource;
404  bool initDone;
405 };
406 
407 /* Struct */
408 struct Clock_Struct {
410  uint32_t timeout;
411  uint32_t currTimeout;
428  uint32_t period;
429  volatile bool active;
436  uintptr_t arg;
437  uint32_t timeoutTicks;
438 };
439 
444 extern const uint32_t Clock_serviceMargin;
456 extern const Clock_TickSource Clock_tickSource;
457 
471 extern const Clock_TickMode Clock_tickMode;
472 
487 extern const unsigned int Clock_timerId;
488 
499 extern const uint32_t Clock_tickPeriod;
500 
502 extern const Clock_Handle Clock_triggerClock;
503 
504 extern void Clock_init(void);
505 
506 extern void Clock_Instance_init(Clock_Object *obj, Clock_FuncPtr clockFxn, unsigned int timeout, const Clock_Params *prms);
507 
508 extern void Clock_Instance_finalize(Clock_Object *obj);
551 extern Clock_Handle Clock_create(Clock_FuncPtr clockFxn, unsigned int timeout, const Clock_Params *prms, Error_Block *eb);
552 
566 extern Clock_Handle Clock_construct(Clock_Struct *obj, Clock_FuncPtr clockFxn, unsigned int timeout, const Clock_Params *prms);
567 
576 extern void Clock_delete(Clock_Handle *clock);
577 
585 extern void Clock_destruct(Clock_Struct *obj);
586 
598 extern void Clock_Params_init(Clock_Params *prms);
599 
608 extern Clock_Handle Clock_Object_first(void);
609 
620 extern Clock_Handle Clock_Object_next(Clock_Handle clock);
621 
630 extern uint32_t Clock_getTicks(void);
631 
641 extern void * Clock_getTimerHandle(void);
650 extern void Clock_setTicks(uint32_t ticks);
668 extern void Clock_tickStop(void);
669 
715 extern bool Clock_tickReconfig(void);
716 
733 extern void Clock_tickStart(void);
734 
753 extern void Clock_tick(void);
754 
763 extern void Clock_workFunc(uintptr_t arg0, uintptr_t arg1);
774 extern void Clock_workFuncDynamic(uintptr_t arg0, uintptr_t arg1);
781 extern void Clock_logTick(void);
795 extern uint32_t Clock_getCompletedTicks(void);
808 extern uint32_t Clock_getTickPeriod(void);
820 extern uint32_t Clock_getTicksUntilInterrupt(void);
836 extern uint32_t Clock_getTicksUntilTimeout(void);
843 extern uint32_t Clock_walkQueueDynamic(bool service, uint32_t tick);
850 extern uint32_t Clock_walkQueuePeriodic(void);
857 extern void Clock_scheduleNextTick(uint32_t deltaTicks, uint32_t absTick);
866 extern void Clock_addI(Clock_Handle clock, Clock_FuncPtr clockFxn, uint32_t timeout, uintptr_t arg);
875 extern void Clock_initI(Clock_Handle clock, Clock_FuncPtr clockFxn, uint32_t timeout, uintptr_t arg);
882 extern void Clock_enqueueI(Clock_Handle clock);
890 extern void Clock_removeI(Clock_Handle clock);
904 extern void Clock_start(Clock_Handle clock);
905 
910 extern void Clock_startI(Clock_Handle clock);
918 extern void Clock_stop(Clock_Handle clock);
919 
929 extern void Clock_setPeriod(Clock_Handle clock, uint32_t period);
930 
940 extern void Clock_setTimeout(Clock_Handle clock, uint32_t timeout);
941 
955 extern void Clock_setFunc(Clock_Handle clock, Clock_FuncPtr fxn, uintptr_t arg);
956 
966 extern uint32_t Clock_getPeriod(Clock_Handle clock);
967 
978 extern uint32_t Clock_getTimeout(Clock_Handle clock);
979 
989 extern bool Clock_isActive(Clock_Handle clock);
990 
991 /* @cond NODOC */
997 extern void Clock_doTick(uintptr_t arg);
998 
999 extern void Clock_triggerFunc(uintptr_t arg);
1000 
1001 extern Clock_Module_State Clock_Module_state;
1002 
1003 #define Clock_module ((Clock_Module_State *) &(Clock_Module_state))
1004 
1005 static inline Clock_Handle Clock_handle(Clock_Struct *str)
1006 {
1007  return ((Clock_Handle)str);
1008 }
1009 
1010 static inline Clock_Struct * Clock_struct(Clock_Handle h)
1011 {
1012  return ((Clock_Struct *)h);
1013 }
1014 
1015 /* CC32XX DPL calls this internal function, map it for now */
1016 #define ti_sysbios_knl_Clock_doTick(a) Clock_tick()
1017 /* @endcond */
1018 
1019 #ifdef __cplusplus
1020 }
1021 #endif
1022 #endif /* Clock__include */
1023 
1024 /* @cond NODOC */
1025 #undef ti_sysbios_knl_Clock_long_names
1026 #include "Clock_defs.h"
volatile bool startDuringWorkFunc
Definition: Clock.h:362
void Clock_stop(Clock_Handle clock)
Stop instance.
uint32_t nextScheduledTick
Definition: Clock.h:359
struct Swi_Struct Swi_Struct
Definition: Swi.h:310
uint32_t currTimeout
Definition: Clock.h:411
uint32_t period
Period of this instance (in clock ticks)
Definition: Clock.h:342
void Clock_tickStop(void)
Stop clock for reconfiguration.
void Clock_setPeriod(Clock_Handle clock, uint32_t period)
Set periodic interval.
Clock_Object * Clock_Instance
Definition: Clock.h:254
uint32_t Clock_getPeriod(Clock_Handle clock)
Get period of instance.
Clock_TickMode tickMode
Timer tick mode.
Definition: Clock.h:378
Definition: Clock.h:408
void Clock_delete(Clock_Handle *clock)
Delete a Clock.
uint32_t timeout
Definition: Clock.h:410
uint32_t tickPeriod
Tick period specified in microseconds.
Definition: Clock.h:390
Clock_TickMode
Clock Tick Mode.
Definition: Clock.h:289
Definition: Clock.h:290
void Clock_Params_init(Clock_Params *prms)
Initialize the Clock_Params structure with default values.
Opaque queue element.
Definition: Queue.h:204
Swi_Struct * Swi_Handle
Definition: Swi.h:312
Clock_Handle Clock_construct(Clock_Struct *obj, Clock_FuncPtr clockFxn, unsigned int timeout, const Clock_Params *prms)
Construct a Clock.
uintptr_t arg
Uninterpreted argument passed to instance function.
Definition: Clock.h:348
volatile bool active
Definition: Clock.h:429
Runtime error manager.
void Clock_tick(void)
Advance Clock time by one tick.
void Clock_destruct(Clock_Struct *obj)
Destruct a Clock.
Definition: Clock.h:291
uint32_t maxSkippable
Definition: Clock.h:360
Definition: Clock.h:352
Queue Manager.
Swi_Struct swiStruct
Definition: Clock.h:356
Clock_TickSource
Clock tick source.
Definition: Clock.h:264
uintptr_t arg
Uninterpreted argument passed to instance function.
Definition: Clock.h:436
const unsigned int Clock_timerId
Timer Id used to create a Timer instance.
Error block.
Definition: Error.h:152
Clock_FuncPtr fxn
Definition: Clock.h:430
bool startFlag
Start immediately after instance is created.
Definition: Clock.h:325
uint32_t Clock_getTimeout(Clock_Handle clock)
Get timeout of instance.
The Clock module is disabled. In this case, it is an error for the application to ever call Clock_tic...
Definition: Clock.h:282
const Clock_TickSource Clock_tickSource
Source of clock ticks.
bool ticking
Definition: Clock.h:363
bool initDone
Used to insure idem potency during startup.
Definition: Clock.h:404
uint32_t timeoutTicks
Definition: Clock.h:437
bool inWorkFunc
Definition: Clock.h:361
The Clock module automatically configures a a Timer instance to drive the Clock tick. The specific timer and its period can be controlled via Clock_timerId and Clock_tickPeriod.
Definition: Clock.h:271
void Clock_setTimeout(Clock_Handle clock, uint32_t timeout)
Set the initial timeout.
void Clock_tickStart(void)
Start clock after reconfiguration.
void Clock_start(Clock_Handle clock)
Start instance.
Clock_Object * Clock_Handle
Definition: Clock.h:253
void Clock_setFunc(Clock_Handle clock, Clock_FuncPtr fxn, uintptr_t arg)
Overwrite Clock function and arg.
volatile unsigned int numTickSkip
Definition: Clock.h:358
uint32_t Clock_getTicks(void)
Time in Clock ticks.
bool Clock_tickReconfig(void)
Reconfigure clock for new cpu frequency.
const uint32_t Clock_tickPeriod
Tick period specified in microseconds.
uint32_t period
Period of this instance (in clock ticks)
Definition: Clock.h:428
Swi_Handle swi
Definition: Clock.h:357
volatile uint32_t ticks
Definition: Clock.h:354
The Application is responsible for calling Clock_tick periodically. Make sure Clock_tickPeriod is set...
Definition: Clock.h:277
unsigned int swiCount
Definition: Clock.h:355
Clock_Handle Clock_Object_first(void)
return handle of the first Clock on Clock list
Clock_Handle Clock_Object_next(Clock_Handle clock)
return handle of the next Clock on Clock list
bool Clock_isActive(Clock_Handle clock)
Determine if Clock object is currently active (ie running)
Clock_TickSource tickSource
Source of clock ticks.
Definition: Clock.h:400
Queue_Object clockQ
Definition: Clock.h:353
Queue_Elem objElem
Definition: Clock.h:409
Software Interrupt Manager.
Definition: Clock.h:304
const Clock_TickMode Clock_tickMode
Timer tick mode.
Clock_Handle Clock_create(Clock_FuncPtr clockFxn, unsigned int timeout, const Clock_Params *prms, Error_Block *eb)
Creates a Clock Instance.
void(* Clock_FuncPtr)(uintptr_t arg1)
Instance function prototype.
Definition: Clock.h:301
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale