|
AM64x MCU+ SDK
10.00.00
|
|
Go to the documentation of this file.
58 #ifndef UNIBASE_MARCORS_H_
59 #define UNIBASE_MARCORS_H_
66 #define UB_SEC_NS 1000000000LL
67 #define UB_MSEC_NS 1000000
68 #define UB_USEC_NS 1000
69 #define UB_SEC_US 1000000LL
70 #define UB_MSEC_US 1000
71 #define UB_SEC_MS 1000
73 #define UB_CHARS_IN_LINE 384
75 #define UB_BIT(x) (1U<<(x))
76 #define UB_MAX(x,y) ((x)>(y)?(x):(y))
77 #define UB_MIN(x,y) ((x)<(y)?(x):(y))
79 #define UB_CONSOLE_PRINT(...) \
81 char coutstr[UB_CHARS_IN_LINE]; \
82 (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
83 ub_console_debug_select_print(true, false, coutstr); \
86 #define UB_DEBUGMEM_PRINT(...) \
88 char coutstr[UB_CHARS_IN_LINE]; \
89 (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
90 ub_console_debug_select_print(false, true, coutstr); \
93 #define UB_CONSOLE_DEBUGMEM_PRINT(...) \
95 char coutstr[UB_CHARS_IN_LINE]; \
96 (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
97 ub_console_debug_select_print(true, true, coutstr); \
100 #define UB_SELECT_PRINT(console, debugmem, ...) \
102 char coutstr[UB_CHARS_IN_LINE]; \
103 (void)snprintf(coutstr, UB_CHARS_IN_LINE, __VA_ARGS__); \
104 ub_console_debug_select_print(console, debugmem, coutstr); \
116 #define UB_LOG(level, ...) UB_LOG_##level(__VA_ARGS__)
121 #define UB_TLOG(level, ...) UB_TLOG_##level(__VA_ARGS__)
136 #define UB_VLOG(var, ...) \
137 if((var)==UBL_DEBUGV){UB_LOG(UBL_DEBUGV,__VA_ARGS__);}\
138 else if((var)==UBL_DEBUG){UB_LOG(UBL_DEBUG,__VA_ARGS__);}\
139 else if((var)==UBL_INFOV){UB_LOG(UBL_INFOV,__VA_ARGS__);}\
140 else if((var)==UBL_INFO){UB_LOG(UBL_INFO,__VA_ARGS__);}\
141 else if((var)==UBL_WARN){UB_LOG(UBL_WARN,__VA_ARGS__);}\
142 else if((var)==UBL_ERROR){UB_LOG(UBL_ERROR,__VA_ARGS__);}\
143 else if((var)==UBL_FATAL){UB_LOG(UBL_FATAL,__VA_ARGS__);}\
147 #define UB_PRIhexB8 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X"
148 #define UB_ARRAY_B8(x) (x)[0],(x)[1],(x)[2],(x)[3],(x)[4],(x)[5],(x)[6],(x)[7]
151 #define UB_PRIhexB6 "%02X:%02X:%02X:%02X:%02X:%02X"
152 #define UB_ARRAY_B6(x) (x)[0],(x)[1],(x)[2],(x)[3],(x)[4],(x)[5]
155 #define UB_NON_ZERO_B6(x) (((x)[0]|(x)[1]|(x)[2]|(x)[3]|(x)[4]|(x)[5])!=0u)
158 #define UB_NON_ZERO_B8(x) (((x)[0]|(x)[1]|(x)[2]|(x)[3]|(x)[4]|(x)[5]|(x)[6]|(x)[7])!=0u)
161 #define UB_ALLFF_B6(x) (((x)[0]&(x)[1]&(x)[2]&(x)[3]&(x)[4]&(x)[5])==0xffu)
164 #define UB_ALLFF_B8(x) (((x)[0]&(x)[1]&(x)[2]&(x)[3]&(x)[4]&(x)[5]&(x)[6]&(x)[7])==0xffu)
174 #define UB_ABIT8_FIELD(name, s, m) \
175 static inline int name##_bit_field(uint8_t x) \
176 { return (x >> (s)) & (m); } \
177 static inline int name##_set_bit_field(uint8_t x, uint8_t v) \
178 { return (x & ~((m) << (s))) | ((v & (m)) << (s)) ; }
181 #define UB_ABIT16_FIELD(name, s, m) \
182 static inline int name##_bit_field(uint16_t x) \
183 { return (htons(x) >> (s)) & (m); } \
184 static inline int name##_set_bit_field(uint16_t x, uint16_t v) \
185 {return ntohs((htons(x) & ~((m) << (s))) \
186 | ((v & (m)) << (s)));}
189 #define UB_ABIT32_FIELD(name, s, m) \
190 static inline int name##_bit_field(uint32_t x) \
191 { return (htonl(x) >> (s)) & (m); } \
192 static inline int name##_set_bit_field(uint32_t x, uint32_t v) \
193 {return ntohl((htonl(x) & ~((m) << (s))) \
194 | ((v & (m)) << (s)));}
203 #define UB_ABIT8_TOGGLE_FIELD(name, s, m) \
204 static inline int name##_toggle_bit_field(uint8_t x) \
205 {return (x ^ ((m) << (s)));}
208 #define UB_ABIT16_TOGGLE_FIELD(name, s, m) \
209 static inline int name##_toggle_bit_field(uint16_t x) \
210 {return ntohs((htons(x) ^ ((m) << (s))));}
213 #define UB_ABIT32_TOGGLE_FIELD(name, s, m) \
214 static inline int name##_toggle_bit_field(uint32_t x) \
215 {return ntohl((htonl(x) ^ ((m) << (s))));}
218 #define UB_TS2NSEC(ts) (((int64_t)(ts).tv_sec*1000000000)+(ts).tv_nsec)
221 #define UB_TS2USEC(ts) (((int64_t)(ts).tv_sec*1000000)+(ts).tv_nsec/UB_USEC_NS)
224 #define UB_TS2MSEC(ts) (((int64_t)(ts).tv_sec*UB_SEC_MS)+(ts).tv_nsec/UB_MSEC_NS)
227 #define UB_TV2NSEC(tv) (((int64_t)(tv).tv_sec*1000000000)+(int64_t)(tv).tv_usec*UB_USEC_NS)
230 #define UB_TV2USEC(tv) (((int64_t)(tv).tv_sec*1000000)+(tv).tv_usec)
233 #define UB_TV2MSEC(tv) (((int64_t)(tv).tv_sec*UB_SEC_MS)+(tv).tv_usec/UB_MSEC_US)
236 #define UB_NSEC2TS(ns, ts) {(ts).tv_sec=(ns)/1000000000;(ts).tv_nsec=(ns)%1000000000;}
239 #define UB_USEC2TS(us, ts) {(ts).tv_sec=(us)/1000000;(ts).tv_nsec=((us)%1000000)*UB_USEC_NS;}
242 #define UB_MSEC2TS(ms, ts) {(ts).tv_sec=(ms)/UB_SEC_MS;(ts).tv_nsec=((ms)%UB_SEC_MS)*UB_MSEC_NS;}
245 #define UB_NSEC2TV(ns, tv) {(tv).tv_sec=(ns)/1000000000;(tv).tv_usec=((ns)%1000000000)/UB_USEC_NS;}
248 #define UB_USEC2TV(us, tv) {(tv).tv_sec=(us)/1000000;(tv).tv_usec=(us)%1000000;}
251 #define UB_MSEC2TV(ms, tv) {(tv).tv_sec=(ms)/UB_SEC_MS;(tv).tv_usec=((ms)%UB_SEC_MS)*UB_MSEC_US;}
254 #define UB_TV_DIFF64NS(tv1,tv2) (UB_TV2NSEC(tv1)-UB_TV2NSEC(tv2))
257 #define UB_TV_ADD64NS(tv1,tv2) (UB_TV2NSEC(tv1)+UB_TV2NSEC(tv2))
260 #define UB_TS_DIFF64NS(ts1,ts2) (UB_TS2NSEC(ts1)-UB_TS2NSEC(ts2))
263 #define UB_TS_ADD64NS(ts1,ts2) (UB_TS2NSEC(ts1)+UB_TS2NSEC(ts2))
266 #define UB_TV_DIFF_TV(rtv,tv1,tv2) { \
267 int64_t ns_ub_m_=(int64_t)UB_TV_DIFF64NS(tv1,tv2); \
268 UB_NSEC2TV(ns_ub_m_,rtv); \
272 #define UB_TS_DIFF_TS(rts,ts1,ts2) { \
273 int64_t ns_ub_m_=(int64_t)UB_TS_DIFF64NS(ts1,ts2); \
274 UB_NSEC2TS(ns_ub_m_,rts); \
278 #define UB_TV_ADD_TV(rtv,tv1,tv2) { \
279 int64_t ns_ub_m_=(int64_t)UB_TV_ADD64NS(tv1,tv2); \
280 UB_NSEC2TV(ns_ub_m_,rtv); \
284 #define UB_TS_ADD_TS(rts,ts1,ts2) { \
285 int64_t ns_ub_m_=(int64_t)UB_TS_ADD64NS(ts1,ts2); \
286 UB_NSEC2TS(ns_ub_m_,rts); \
294 #define UB_HTONLL(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | \
302 #define UB_NTOHLL(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | \
310 #define UB_STATIC_ASSERT(cond, error) typedef char type[(cond) ? 1 : -1]
317 #define UB_PROTECTED_FUNC(cbfunc, rval, ...) \
318 int ub_func_private_mutex_lock(void); \
319 int ub_func_private_mutex_unlock(void); \
320 ub_func_private_mutex_lock(); \
321 rval=cbfunc(__VA_ARGS__); \
322 ub_func_private_mutex_unlock();
327 #define UB_PROTECTED_FUNC_VOID(cbfunc, ...) \
328 int ub_func_private_mutex_lock(void); \
329 int ub_func_private_mutex_unlock(void); \
330 ub_func_private_mutex_lock(); \
331 cbfunc(__VA_ARGS__); \
332 ub_func_private_mutex_unlock();