PDK API Guide for J721E
unibase.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Texas Instruments Incorporated
3  * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4  *
5  * All rights reserved not granted herein.
6  * Limited License.
7  *
8  * Texas Instruments Incorporated grants a world-wide, royalty-free,
9  * non-exclusive license under copyrights and patents it now or hereafter
10  * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11  * this software subject to the terms herein. With respect to the foregoing patent
12  * license, such license is granted solely to the extent that any such patent is necessary
13  * to Utilize the software alone. The patent license shall not apply to any combinations which
14  * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15  * No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce this license (including the
18  * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19  * in the documentation and/or other materials provided with the distribution
20  *
21  * Redistribution and use in binary form, without modification, are permitted provided that the following
22  * conditions are met:
23  *
24  * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25  * software provided in binary form.
26  * * any redistribution and use are licensed by TI for use only with TI Devices.
27  * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28  *
29  * If software source code is provided to you, modification and redistribution of the source code are permitted
30  * provided that the following conditions are met:
31  *
32  * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33  * TI for use only with TI Devices.
34  * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35  * works, are licensed by TI for use only with TI Devices.
36  *
37  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38  * promote products derived from this software without specific prior written permission.
39  *
40  * DISCLAIMER.
41  *
42  * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49 */
65 #ifndef UNIBASE_H_
66 #define UNIBASE_H_
67 
68 #ifdef UB_OVERRIDE_H
69 #include UB_OVERRIDE_H
70 #endif
71 
72 #include <inttypes.h>
73 #include <stdbool.h>
74 
75 #include "unibase_macros.h"
76 #include "ub_logging.h"
77 #include "ub_esarray.h"
78 #include "ub_strutils.h"
79 #include "ub_llist.h"
80 #include "ub_confutils.h"
81 #include "ub_fileio.h"
82 #include "ub_getmem.h"
83 
84 #ifndef CLOCK_MONOTONIC
85 #define CLOCK_MONOTONIC CLOCK_REALTIME
86 #endif
87 
88 #ifdef NO_GETOPT_LONG
89 #include <getopt.h>
90 struct option
91 {
92  char *name;
93  int has_arg;
94  int *flag;
95  int val;
96 };
97 #define no_argument 0
98 #define required_argument 1
99 #define optional_argument 2
100 static inline int getopt_long(int argc, char **argv, char *optstr,
101  struct option *lo, int *li)
102 {
103  return getopt(argc, argv, optstr);
104 }
105 #endif
106 
107 #define UB_UNIBASE_LOGCAT 0
108 /************************************************************
109  * type declarations
110  ************************************************************/
114 typedef enum {
120 
121 typedef int (*ub_console_out)(bool flush, const char *str);
122 typedef int (*ub_debug_out)(bool flush, const char *str);
123 typedef void* (*ub_mutex_init)(void);
124 typedef int (*ub_mutex_close)(void *mutex);
125 typedef int (*ub_mutex_lock)(void *mutex);
126 typedef int (*ub_mutex_unlock)(void *mutex);
127 typedef void (*ub_fatal_func)(void);
128 typedef uint64_t (*ub_gettime64)(ub_clocktype_t ctype);
129 
133 typedef struct unibase_cb_set {
143 
147 typedef struct unibase_init_para {
149  const char *ub_log_initstr;
151 
152 /************************************************************
153  * functions
154  ************************************************************/
165 int unibase_init(unibase_init_para_t *ub_init_para);
166 
170 void unibase_close(void);
171 
179 void ub_fatal(const char *mes1, const char *mes2);
180 
184 bool ub_fatalerror(void);
185 
189 static inline bool ub_assert_fatal(bool cond, const char *mes1, const char *mes2)
190 {
191  if(cond) {return false;}
192  ub_fatal(mes1, mes2);
193  return ub_fatalerror();
194 }
195 
200 uint64_t ub_rt_gettime64(void);
201 
206 uint64_t ub_mt_gettime64(void);
207 
212 uint64_t ub_gptp_gettime64(void);
213 
221 typedef int (*ub_protected_callback)(void*);
222 int ub_protected_func(ub_protected_callback cbfunc, void *cbdata);
223 
224 #endif
225 
Definition: unibase.h:118
ub_fatal_func fatal
fatal callback
Definition: unibase.h:141
Utility macros for convenience.
ub_console_out console_out
console_out callback
Definition: unibase.h:134
Configure from a configuration file. ub_set_item_cb_t callback function can be generated by 'ub_genco...
a set of callback functions to process platform specific tasks
Definition: unibase.h:133
void *(* ub_mutex_init)(void)
mutex initialization function
Definition: unibase.h:123
Definition: unibase.h:116
ub_mutex_close mutex_close
mutex_close callback
Definition: unibase.h:137
ub_mutex_lock mutex_lock
mutex_lock callback
Definition: unibase.h:138
ub_mutex_init mutex_init
mutex_init callback
Definition: unibase.h:136
int(* ub_debug_out)(bool flush, const char *str)
debug output function
Definition: unibase.h:122
void unibase_close(void)
claose unibase
Control logging by levels and categories.
uint64_t(* ub_gettime64)(ub_clocktype_t ctype)
64-bit timestamp function
Definition: unibase.h:128
unibase_cb_set_t cbset
a set of callback functions
Definition: unibase.h:148
void(* ub_fatal_func)(void)
function to process a fatal error event
Definition: unibase.h:127
bool ub_fatalerror(void)
return the fatal error status
initialization parameters
Definition: unibase.h:147
int unibase_init(unibase_init_para_t *ub_init_para)
initialize unibase
int(* ub_console_out)(bool flush, const char *str)
console output function
Definition: unibase.h:121
static bool ub_assert_fatal(bool cond, const char *mes1, const char *mes2)
conditinal ub_fatal
Definition: unibase.h:189
uint64_t ub_mt_gettime64(void)
get 64-bit MONOTONIC clock value
ub_gettime64 gettime64
gettime64 callback
Definition: unibase.h:140
ub_debug_out debug_out
debug_out callback
Definition: unibase.h:135
uint64_t ub_gptp_gettime64(void)
get 64-bit PTP clock value
uint64_t ub_rt_gettime64(void)
get 64-bit REALTIME clock value
Definition: unibase.h:117
int ub_protected_func(ub_protected_callback cbfunc, void *cbdata)
int(* ub_mutex_unlock)(void *mutex)
mutex unlock function
Definition: unibase.h:126
Doubly linked list.
int(* ub_mutex_lock)(void *mutex)
mutex lock function
Definition: unibase.h:125
ub_mutex_unlock mutex_unlock
mutex_unlock callback
Definition: unibase.h:139
Allocated memory array which is expanded or shrinked automatically.
const char * ub_log_initstr
look at 'ub_log_init' in 'ub_logging.h'
Definition: unibase.h:149
void ub_fatal(const char *mes1, const char *mes2)
process a fatal error
char str[32]
Definition: tisci_core.h:442
ub_clocktype_t
clock type which provides timestamp
Definition: unibase.h:114
Utility functions for strings.
Definition: unibase.h:115
int(* ub_mutex_close)(void *mutex)
mutex de-initialization function
Definition: unibase.h:124
int(* ub_protected_callback)(void *)
call cbfunc with an internal mutex:'gmutex' protection
Definition: unibase.h:221