AM65x MCU+ SDK  09.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 
55 #if defined (OS_SAFERTOS)
56 #define ClockP_OBJECT_SIZE_MAX (120u)
57 #else
58 #define ClockP_OBJECT_SIZE_MAX (104u)
59 #endif
60 
63 typedef struct ClockP_Object_ {
64 
65  /* uintptr_t translates to uint64_t for A53 and uint32_t for R5 and M4 */
66  /* This accounts for the 64bit pointer in A53 and 32bit pointer in R5 and M4 */
67  uintptr_t rsv[ClockP_OBJECT_SIZE_MAX/sizeof(uint32_t)];
70 
71 
75 typedef struct ClockP_Config_
76 {
77  uint32_t timerBaseAddr;
78  uint32_t timerHwiIntNum;
79  uint32_t timerInputClkHz;
81  uint32_t usecPerTick;
84 
91 typedef void (*ClockP_FxnCallback)(ClockP_Object *obj, void *args);
92 
96 typedef struct ClockP_Params_ {
97 
98  uint32_t start;
99  uint32_t timeout;
100  uint32_t period;
104  void *args;
108  const char *name;
112 } ClockP_Params;
113 
114 
115 
127 void ClockP_init(void);
128 
137 
149 
156 
165 
172 
185 
192 void ClockP_setTimeout(ClockP_Object *obj, uint32_t timeout);
193 
202 
208 uint32_t ClockP_getTicks(void);
209 
217 uint32_t ClockP_usecToTicks(uint64_t usecs);
218 
226 uint64_t ClockP_ticksToUsec(uint32_t ticks);
227 
228 
232 uint64_t ClockP_getTimeUsec(void);
233 
243 void ClockP_usleep(uint32_t usec);
244 
254 void ClockP_sleep(uint32_t sec);
255 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif /* CLOCKP_H */
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:101
SystemP.h
ClockP_Params::name
const char * name
Definition: ClockP.h:108
ClockP_Object
Opaque clock object used with the clock APIs.
Definition: ClockP.h:63
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:81
ClockP_sleep
void ClockP_sleep(uint32_t sec)
Sleep for user specified seconds.
ClockP_init
void ClockP_init(void)
Initialize the clock module.
ClockP_OBJECT_SIZE_MAX
#define ClockP_OBJECT_SIZE_MAX
Max size of clock object across no-RTOS and all OS's.
Definition: ClockP.h:58
ClockP_destruct
void ClockP_destruct(ClockP_Object *obj)
Cleanup, delete, destruct a clock object.
ClockP_Params::start
uint32_t start
Definition: ClockP.h:98
ClockP_setTimeout
void ClockP_setTimeout(ClockP_Object *obj, uint32_t timeout)
Set clock timeout value, takes effect for next clock start.
ClockP_Config
ClockP module config, set as part of SysConfig, not to be set by end-users directly.
Definition: ClockP.h:76
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:96
ClockP_Config::timerBaseAddr
uint32_t timerBaseAddr
Definition: ClockP.h:77
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:104
ClockP_Config::timerInputPreScaler
uint32_t timerInputPreScaler
Definition: ClockP.h:80
ClockP_Params::period
uint32_t period
Definition: ClockP.h:100
ClockP_usleep
void ClockP_usleep(uint32_t usec)
Sleep for user specified usecs.
ClockP_Config::timerHwiIntNum
uint32_t timerHwiIntNum
Definition: ClockP.h:78
ClockP_usecToTicks
uint32_t ClockP_usecToTicks(uint64_t usecs)
Convert usecs to clock ticks.
ClockP_Params::timeout
uint32_t timeout
Definition: ClockP.h:99
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:91
ClockP_Config::timerInputClkHz
uint32_t timerInputClkHz
Definition: ClockP.h:79