AM263x MCU+ SDK  09.02.00
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 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 #ifndef CLOCK_MONOTONIC
89 #define CLOCK_MONOTONIC CLOCK_REALTIME
90 #endif
91 
92 #ifdef NO_GETOPT_LONG
93 #include <getopt.h>
94 struct option
95 {
96  char *name;
97  int has_arg;
98  int *flag;
99  int val;
100 };
101 #define no_argument 0
102 #define required_argument 1
103 #define optional_argument 2
104 static inline int getopt_long(int argc, char **argv, char *optstr,
105  struct option *lo, int *li)
106 {
107  return getopt(argc, argv, optstr);
108 }
109 #endif
110 
111 #define UB_UNIBASE_LOGCAT 0
112 /************************************************************
113  * type declarations
114  ************************************************************/
118 typedef enum {
124 
125 typedef int (*ub_console_out)(bool flush, const char *str);
126 typedef int (*ub_debug_out)(bool flush, const char *str);
127 typedef void* (*ub_mutex_init)(void);
128 typedef int (*ub_mutex_close)(void *mutex);
129 typedef int (*ub_mutex_lock)(void *mutex);
130 typedef int (*ub_mutex_unlock)(void *mutex);
131 typedef void (*ub_fatal_func)(void);
132 typedef uint64_t (*ub_gettime64)(ub_clocktype_t ctype);
133 
137 typedef struct unibase_cb_set {
147 
151 typedef struct unibase_init_para {
153  const char *ub_log_initstr;
155 
156 /************************************************************
157  * functions
158  ************************************************************/
170 
174 void unibase_close(void);
175 
183 void ub_fatal(const char *mes1, const char *mes2);
184 
188 bool ub_fatalerror(void);
189 
193 static inline bool ub_assert_fatal(bool cond, const char *mes1, const char *mes2)
194 {
195  if(cond) {return false;}
196  ub_fatal(mes1, mes2);
197  return ub_fatalerror();
198 }
199 
204 uint64_t ub_rt_gettime64(void);
205 
210 uint64_t ub_mt_gettime64(void);
211 
216 uint64_t ub_gptp_gettime64(void);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif
223 
unibase_init_para_t
initialization parameters
Definition: unibase.h:151
unibase_cb_set_t::get_static_mutex
ub_mutex_init get_static_mutex
get_static_mutex callback
Definition: unibase.h:140
ub_mutex_close
int(* ub_mutex_close)(void *mutex)
mutex de-initialization function
Definition: unibase.h:128
unibase_close
void unibase_close(void)
claose unibase
UB_CLOCK_REALTIME
@ UB_CLOCK_REALTIME
Definition: unibase.h:120
ub_fatalerror
bool ub_fatalerror(void)
return the fatal error status
ub_strutils.h
Utility functions for strings.
unibase_cb_set_t::debug_out
ub_debug_out debug_out
debug_out callback
Definition: unibase.h:139
ub_confutils.h
Provides functions for configuring from a file.
UB_CLOCK_MONOTONIC
@ UB_CLOCK_MONOTONIC
Definition: unibase.h:121
ub_fatal_func
void(* ub_fatal_func)(void)
function to process a fatal error event
Definition: unibase.h:131
ub_debug_out
int(* ub_debug_out)(bool flush, const char *str)
debug output function
Definition: unibase.h:126
unibase_init_para_t::cbset
unibase_cb_set_t cbset
a set of callback functions
Definition: unibase.h:152
ub_mutex_init
void *(* ub_mutex_init)(void)
mutex initialization function
Definition: unibase.h:127
unibase_init
int unibase_init(unibase_init_para_t *ub_init_para)
initialize unibase
unibase_cb_set_t::mutex_unlock
ub_mutex_unlock mutex_unlock
mutex_unlock callback
Definition: unibase.h:143
ub_gettime64
uint64_t(* ub_gettime64)(ub_clocktype_t ctype)
64-bit timestamp function
Definition: unibase.h:132
unibase_cb_set_t::gettime64
ub_gettime64 gettime64
gettime64 callback
Definition: unibase.h:144
ub_logging.h
Control logging by levels and categories.
ub_assert_fatal
static bool ub_assert_fatal(bool cond, const char *mes1, const char *mes2)
conditinal ub_fatal
Definition: unibase.h:193
unibase_cb_set_t::console_out
ub_console_out console_out
console_out callback
Definition: unibase.h:138
UB_CLOCK_GPTP
@ UB_CLOCK_GPTP
Definition: unibase.h:122
unibase_cb_set_t::fatal
ub_fatal_func fatal
fatal callback
Definition: unibase.h:145
ub_console_out
int(* ub_console_out)(bool flush, const char *str)
console output function
Definition: unibase.h:125
ub_mt_gettime64
uint64_t ub_mt_gettime64(void)
get 64-bit MONOTONIC clock value
unibase_init_para_t::ub_log_initstr
const char * ub_log_initstr
look at 'ub_log_init' in 'ub_logging.h'
Definition: unibase.h:153
ub_rt_gettime64
uint64_t ub_rt_gettime64(void)
get 64-bit REALTIME clock value
UB_CLOCK_DEFAULT
@ UB_CLOCK_DEFAULT
Definition: unibase.h:119
ub_llist.h
Doubly linked list.
ub_gptp_gettime64
uint64_t ub_gptp_gettime64(void)
get 64-bit PTP clock value
unibase_cb_set_t::mutex_lock
ub_mutex_lock mutex_lock
mutex_lock callback
Definition: unibase.h:142
unibase_cb_set_t
a set of callback functions to process platform specific tasks
Definition: unibase.h:137
unibase_cb_set_t::static_mutex_close
ub_mutex_close static_mutex_close
static_mutex_close callback
Definition: unibase.h:141
unibase_macros.h
Utility macros for convenience.
ub_mutex_lock
int(* ub_mutex_lock)(void *mutex)
mutex lock function
Definition: unibase.h:129
ub_fatal
void ub_fatal(const char *mes1, const char *mes2)
process a fatal error
ub_mutex_unlock
int(* ub_mutex_unlock)(void *mutex)
mutex unlock function
Definition: unibase.h:130
ub_esarray.h
Allocated memory array which is expanded or shrinked automatically.
ub_clocktype_t
ub_clocktype_t
clock type which provides timestamp
Definition: unibase.h:118