AM64x MCU+ SDK  08.02.00
ClockP.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2021 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 #define ClockP_OBJECT_SIZE_MAX (104u)
56 
59 typedef struct ClockP_Object_ {
60 
61  /* uintptr_t translates to uint64_t for A53 and uint32_t for R5 and M4 */
62  /* This accounts for the 64bit pointer in A53 and 32bit pointer in R5 and M4 */
63  uintptr_t rsv[ClockP_OBJECT_SIZE_MAX/sizeof(uint32_t)];
66 
67 
71 typedef struct ClockP_Config_
72 {
73  uint32_t timerBaseAddr;
74  uint32_t timerHwiIntNum;
75  uint32_t timerInputClkHz;
77  uint32_t usecPerTick;
80 
87 typedef void (*ClockP_FxnCallback)(ClockP_Object *obj, void *args);
88 
92 typedef struct ClockP_Params_ {
93 
94  uint32_t start;
95  uint32_t timeout;
96  uint32_t period;
100  void *args;
102  char *name;
104 } ClockP_Params;
105 
106 
107 
119 void ClockP_init();
120 
129 
141 
148 
157 
164 
177 
184 void ClockP_setTimeout(ClockP_Object *obj, uint32_t timeout);
185 
194 
200 uint32_t ClockP_getTicks();
201 
209 uint32_t ClockP_usecToTicks(uint64_t usecs);
210 
218 uint64_t ClockP_ticksToUsec(uint32_t ticks);
219 
220 
225 
235 void ClockP_usleep(uint32_t usec);
236 
246 void ClockP_sleep(uint32_t sec);
247 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* CLOCKP_H */
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:97
SystemP.h
ClockP_Object
Opaque clock object used with the clock APIs.
Definition: ClockP.h:59
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:77
ClockP_sleep
void ClockP_sleep(uint32_t sec)
Sleep for user specified seconds.
ClockP_getTimeUsec
uint64_t ClockP_getTimeUsec()
Get current time in units of usecs.
ClockP_OBJECT_SIZE_MAX
#define ClockP_OBJECT_SIZE_MAX
Max size of clock object across no-RTOS and all OS's.
Definition: ClockP.h:55
ClockP_destruct
void ClockP_destruct(ClockP_Object *obj)
Cleanup, delete, destruct a clock object.
ClockP_Params::start
uint32_t start
Definition: ClockP.h:94
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:72
ClockP_Params_init
void ClockP_Params_init(ClockP_Params *params)
Set default values to ClockP_Params.
ClockP_Params
Parameters passed during ClockP_construct.
Definition: ClockP.h:92
ClockP_Config::timerBaseAddr
uint32_t timerBaseAddr
Definition: ClockP.h:73
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:100
ClockP_init
void ClockP_init()
Initialize the clock module.
ClockP_Config::timerInputPreScaler
uint32_t timerInputPreScaler
Definition: ClockP.h:76
ClockP_Params::period
uint32_t period
Definition: ClockP.h:96
ClockP_usleep
void ClockP_usleep(uint32_t usec)
Sleep for user specified usecs.
ClockP_Config::timerHwiIntNum
uint32_t timerHwiIntNum
Definition: ClockP.h:74
ClockP_Params::name
char * name
Definition: ClockP.h:102
ClockP_usecToTicks
uint32_t ClockP_usecToTicks(uint64_t usecs)
Convert usecs to clock ticks.
ClockP_Params::timeout
uint32_t timeout
Definition: ClockP.h:95
ClockP_getTicks
uint32_t ClockP_getTicks()
Get current clock ticks.
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:87
ClockP_Config::timerInputClkHz
uint32_t timerInputClkHz
Definition: ClockP.h:75