AM64x MCU+ SDK  11.01.00
ClockP.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2023 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef CLOCKP_H
34 #define CLOCKP_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdint.h>
41 #include <kernel/dpl/SystemP.h>
42 #include <kernel/dpl/TimerP.h>
43 
56 #if defined (OS_NORTOS)
57 typedef struct ClockP_Object_
58 {
59  void (*callback)(struct ClockP_Object_ *obj, void *args);
60  void *args;
61  uint32_t startTimeout; /* timeout passed to ClockP_construct() */
62  uint32_t timeout;
63  uint32_t period;
64  struct ClockP_Object_ *next;
65 } ClockP_Object;
66 #elif defined (OS_FREERTOS) || defined (OS_FREERTOS_SMP) || defined (OS_FREERTOS_MPU)
67 #include <FreeRTOS.h>
68 #include <timers.h>
69 typedef struct ClockP_Object_
70 {
71  StaticTimer_t timerObj;
72  TimerHandle_t timerHndl;
73  void (*callback)(struct ClockP_Object_ *obj, void *args);
74  void *args;
75 
76 } ClockP_Object;
77 #elif defined (OS_SAFERTOS)
78 #include <SafeRTOS.h>
79 #include <timers.h>
80 typedef struct ClockP_Object_
81 {
82  timerInitParametersType timerParameters;
83  timerControlBlockType timerControlBlock;
84  timerHandleType timerHndl;
85  void (*callback)(struct ClockP_Object_ *obj, void *args);
86  void *args;
87 } ClockP_Object;
88 #else
89 #error "Define OS_NORTOS, OS_FREERTOS or OS_SAFERTOS"
90 #endif
91 
95 typedef struct ClockP_Config_
96 {
97  uint32_t timerBaseAddr;
98  uint32_t timerHwiIntNum;
99  uint32_t timerInputClkHz;
101  uint32_t usecPerTick;
102  uint8_t intrPriority;
105 } ClockP_Config;
106 
113 typedef void (*ClockP_FxnCallback)(ClockP_Object *obj, void *args);
114 
118 typedef struct ClockP_Params_ {
119 
120  uint32_t start;
121  uint32_t timeout;
122  uint32_t period;
126  void *args;
130  const char *name;
134 } ClockP_Params;
135 
136 
137 
149 void ClockP_init(void);
150 
159 
170 int32_t ClockP_construct(ClockP_Object *obj, ClockP_Params *params);
171 
177 void ClockP_destruct(ClockP_Object *obj);
178 
186 void ClockP_start(ClockP_Object *obj);
187 
193 void ClockP_stop(ClockP_Object *obj);
194 
206 uint32_t ClockP_isActive(ClockP_Object *obj);
207 
214 void ClockP_setTimeout(ClockP_Object *obj, uint32_t timeout);
215 
223 uint32_t ClockP_getTimeout(ClockP_Object *obj);
224 
230 uint32_t ClockP_getTicks(void);
231 
239 uint32_t ClockP_usecToTicks(uint64_t usecs);
240 
248 uint64_t ClockP_ticksToUsec(uint32_t ticks);
249 
250 
259 uint64_t ClockP_getTimeUsec(void);
260 
270 void ClockP_usleep(uint32_t usec);
271 
281 void ClockP_sleep(uint32_t sec);
282 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif /* CLOCKP_H */
ClockP_Config::intrPriority
uint8_t intrPriority
Definition: ClockP.h:102
ClockP_getTimeUsec
uint64_t ClockP_getTimeUsec(void)
Get current time in units of usecs.
ClockP_construct
int32_t ClockP_construct(ClockP_Object *obj, ClockP_Params *params)
Create a clock object.
ClockP_Params::callback
ClockP_FxnCallback callback
Definition: ClockP.h:123
SystemP.h
ClockP_Params::name
const char * name
Definition: ClockP.h:130
ClockP_start
void ClockP_start(ClockP_Object *obj)
Start the clock, if not already started.
ClockP_stop
void ClockP_stop(ClockP_Object *obj)
Stop the clock, if not already stopped. No effect if clock is already stopped.
ClockP_Config::usecPerTick
uint32_t usecPerTick
Definition: ClockP.h:101
ClockP_sleep
void ClockP_sleep(uint32_t sec)
Sleep for user specified seconds.
ClockP_init
void ClockP_init(void)
Initialize the clock module.
ClockP_destruct
void ClockP_destruct(ClockP_Object *obj)
Cleanup, delete, destruct a clock object.
ClockP_Params::start
uint32_t start
Definition: ClockP.h:120
ClockP_setTimeout
void ClockP_setTimeout(ClockP_Object *obj, uint32_t timeout)
Set clock timeout value, takes effect for next clock start.
ClockP_Config
Opaque clock object used with the clock APIs.
Definition: ClockP.h:96
ClockP_Params_init
void ClockP_Params_init(ClockP_Params *params)
Set default values to ClockP_Params.
ClockP_getTicks
uint32_t ClockP_getTicks(void)
Get current clock ticks.
ClockP_Params
Parameters passed during ClockP_construct.
Definition: ClockP.h:118
ClockP_Config::timerBaseAddr
uint32_t timerBaseAddr
Definition: ClockP.h:97
TimerP.h
ClockP_ticksToUsec
uint64_t ClockP_ticksToUsec(uint32_t ticks)
Convert clock ticks to usecs.
ClockP_isActive
uint32_t ClockP_isActive(ClockP_Object *obj)
Check if clock is active i.e not expired.
ClockP_Params::args
void * args
Definition: ClockP.h:126
ClockP_Config::timerInputPreScaler
uint32_t timerInputPreScaler
Definition: ClockP.h:100
ClockP_Params::period
uint32_t period
Definition: ClockP.h:122
ClockP_usleep
void ClockP_usleep(uint32_t usec)
Sleep for user specified usecs.
ClockP_Config::timerHwiIntNum
uint32_t timerHwiIntNum
Definition: ClockP.h:98
ClockP_usecToTicks
uint32_t ClockP_usecToTicks(uint64_t usecs)
Convert usecs to clock ticks.
ClockP_Config::isPulseInterrupt
uint8_t isPulseInterrupt
Definition: ClockP.h:103
ClockP_Params::timeout
uint32_t timeout
Definition: ClockP.h:121
ClockP_getTimeout
uint32_t ClockP_getTimeout(ClockP_Object *obj)
Get current remaining time in units of ticks.
ClockP_FxnCallback
void(* ClockP_FxnCallback)(ClockP_Object *obj, void *args)
Callback that is called when the clock expires.
Definition: ClockP.h:113
ClockP_Config::timerInputClkHz
uint32_t timerInputClkHz
Definition: ClockP.h:99