SysIo  1.9.0
Embedded Library and tools
defs.h
1 
8 #ifndef _SYSIO_DEFS_H_
9 #define _SYSIO_DEFS_H_
10 
11 #if !defined(__DOXYGEN__)
12 // -----------------------------------------------------------------------------
13 // Définitions à usage interne
14 #ifndef __BEGIN_C_DECLS
15 # if defined(__cplusplus)
16 # define __BEGIN_C_DECLS extern "C" {
17 # define __END_C_DECLS }
18 # else
19 # define __BEGIN_C_DECLS
20 # define __END_C_DECLS
21 # endif
22 #endif
23 
24 /* constants ================================================================ */
25 #ifndef TRUE
26 # define TRUE (1==1)
27 # define FALSE (1==2)
28 #endif
29 
30 // -----------------------------------------------------------------------------
31 #endif /* !defined(__DOXYGEN__) */
32 
33 #define BOARD_GENERIC_LINUX 0
34 #define BOARD_RASPBERRYPI 1
35 #define BOARD_NANOPI_NEO 2
36 #define BOARD_NANOPI_AIR 3
37 #define BOARD_NANOPI_M1 4
38 #define BOARD_NANOPI_M1PLUS 5
39 #define BOARD_NANOPI_NEO2 6
40 #define BOARD_NANOPI_NEOPLUS2 7
41 
42 #ifdef SYSIO_WITH_CONFIG_H
43 #include "config.h"
44 #endif
45 
46 #ifndef __ASSEMBLER__
47 #ifdef __cplusplus
48  extern "C" {
49 #endif
50 /* ==========================Partie Langage C============================== */
51 
52 #if !defined(__DOXYGEN__)
53 // -----------------------------------------------------------------------------
54 // Partie non documentée
55 #ifndef __need_NULL
56 # define __need_NULL
57 #endif
58 #ifndef __need_size_t
59 # define __need_size_t
60 #endif
61 #include <stddef.h>
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inttypes.h>
65 
66 #define BASENAME(f) (f)
67 
68 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
69 /* UNIX-style OS */
70 # define SYSIO_OS_UNIX
71 # include <libgen.h>
72 # undef BASENAME
73 # define BASENAME(f) basename(f)
74 
75 # if defined(_POSIX_VERSION)
76 /* POSIX compliant */
77 # define SYSIO_OS_POSIX
78 # endif
79 
80 # if defined(__linux__)
81 # define SYSIO_OS_LINUX
82 # endif
83 
84 # if defined(__APPLE__)
85 # define SYSIO_OS_APPLE
86 # endif
87 
88 #elif defined(_WIN32) || defined(WIN32)
89 # define SYSIO_OS_WIN32
90 
91 #else
92 # error Unable to detect operating system !
93 #endif
94 
95 
96 // ntohs, htons, ntohl, htonl, ntohll, htonll
97 #include <arpa/inet.h>
98 
99 #ifndef htonll
100 /* htonll not defined ------------------------------------------------------- */
101 #if defined(SYSIO_OS_LINUX)
102 #include <byteswap.h>
103 
104 #if BYTE_ORDER == LITTLE_ENDIAN
105 #define be64_to_cpu(val) bswap_64(val)
106 #elif BYTE_ORDER == BIG_ENDIAN
107 #define be64_to_cpu(val) (val)
108 #else
109 #error unknwon BYTE_ORDER
110 #endif
111 
112 #elif defined(SYSIO_OS_APPLE)
113 #warning TODO: be64_to_cpu(val) for darwin
114 
115 #elif defined(SYSIO_OS_WIN32)
116 #warning TODO: be64_to_cpu(val) for win32
117 
118 #endif /* SYSIO_OS_WIN32 defined */
119 
120 #define ntohll(x) be64_to_cpu(x)
121 #define htonll(x) ntohll(x)
122 /* htonll not defined ------------------------------------------------------- */
123 #endif
124 
125 /* public variables ========================================================= */
126 extern int iSysIoError;
127 
128 /* internal public functions ================================================ */
129 /*
130  * Modifie le message de la dernière erreur
131  */
132 int iSysIoSetStrError (const char *format, ...);
133 
134 /* macros =================================================================== */
135 #ifndef _BV
136 #define _BV(i) (1<<(i))
137 #endif
138 
139 #ifndef ABS
140 # define ABS(n) (((n) < 0) ? -(n) : (n))
141 #endif
142 
143 #ifndef MIN
144 #define MIN(a,b) ((a) < (b) ? a : b)
145 #endif
146 
147 #ifndef MAX
148 #define MAX(a,b) ((a) > (b) ? a : b)
149 #endif
150 
151 #ifndef MSB16
152 #define MSB16(x) ((uint8_t) (x >> 8) & 0xFF)
153 #endif
154 
155 #ifndef LSB
156 #define LSB(x) ((uint8_t) (x & 0xFF))
157 #endif
158 
159 #ifndef COUNTOF
160 # define COUNTOF(a) (sizeof(a) / sizeof(*(a)))
161 #endif
162 
163 #ifndef STRUCT_FIELD_OFFSET
164 # define STRUCT_FIELD_OFFSET(s,f) ((size_t)&(((s *)0)->f))
165 #endif
166 
167 #define PERROR(fmt,...) do { \
168  vLog (LOG_ERR, "%s:%d: %s(): " fmt, BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); \
169  iSysIoSetStrError ("%s:%d: %s(): Error: " fmt "\n", \
170  BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); \
171 } while (0)
172 
173 #define PWARNING(fmt,...) do { \
174  vLog (LOG_WARNING, "%s:%d: %s(): " fmt, BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); \
175  iSysIoSetStrError ("%s:%d: %s(): Warning: " fmt "\n", \
176  BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); \
177 } while (0)
178 
179 #define PNOTICE(fmt,...) vLog (LOG_NOTICE, fmt, ##__VA_ARGS__)
180 
181 
182 #ifdef DEBUG
183 #define PINFO(fmt,...) vLog (LOG_INFO, "%s:%d: %s(): " fmt, BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
184 #define PDEBUG(fmt,...) vLog (LOG_DEBUG, "%s:%d: %s(): " fmt, BASENAME(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
185 #else
186 #define PDEBUG(fmt,...) vLog (LOG_DEBUG, fmt, ##__VA_ARGS__)
187 #define PINFO(fmt,...) vLog (LOG_INFO, fmt, ##__VA_ARGS__)
188 #endif
189 
190 #include <sysio/log.h>
191 
192  /* GCC attributes */
193 #define FORMAT(type,fmt,first) __attribute__((__format__(type, fmt, first)))
194 #define NORETURN __attribute__((__noreturn__))
195 #define UNUSED_ARG(type,arg) __attribute__((__unused__)) type arg
196 #define UNUSED_VAR(type,name) __attribute__((__unused__)) type name
197 #define USED_VAR(type,name) __attribute__((__used__)) type name
198 #define INLINE static inline __attribute__((__always_inline__))
199 #define NOINLINE __attribute__((noinline))
200 #define LIKELY(x) __builtin_expect(!!(x), 1)
201 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
202 #define PURE_FUNC __attribute__((pure))
203 #define CONST_FUNC __attribute__((const))
204 #define UNUSED_FUNC __attribute__((unused))
205 #define USED_FUNC __attribute__((__used__))
206 #define RESTRICT __restrict__
207 #define MUST_CHECK __attribute__((warn_unused_result))
208 #define PACKED __attribute__((packed))
209 #define ALIGNED(x) __attribute__ ((__aligned__(x)))
210 
211 // -----------------------------------------------------------------------------
212 #endif /* !defined(__DOXYGEN__) */
213 
219 /* internal public functions ================================================ */
220 
227 const char * sSysIoVersion (void);
228 
234 int iSysIoMajor (void);
235 
241 int iSysIoMinor (void);
242 
248 int iSysIoBuild (void);
249 
255 const char * sSysIoGitCommit (void);
256 
260 const char * sSysIoStrError (void);
261 
265 bool bSysIoLogAssert (void);
266 
271 /* =========================Fin Partie Langage C============================= */
272 #ifdef __cplusplus
273  }
274 #endif
275 #endif /* __ASSEMBLER__ not defined */
276 
277 
278 #endif /* _SYSIO_DEFS_H_ defined */
const char * sSysIoGitCommit(void)
Renvoie l&#39;identifiant de commit git de la bibliothèque.
const char * sSysIoStrError(void)
Renvoie le message de la dernière erreur.
const char * sSysIoVersion(void)
Renvoie la version de la bibliothèque sous forme de string.
int iSysIoBuild(void)
Renvoie le numéro de build de la version de la bibliothèque.
int iSysIoMajor(void)
Renvoie le majeur de la version de la bibliothèque.
bool bSysIoLogAssert(void)
Renvoie true si LOG_ASSERT a été défini lors de la compilation.
int iSysIoMinor(void)
Renvoie le mineur de la version de la bibliothèque.