VSF Documented
__type.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __COMMON_TYPE_H__
19#define __COMMON_TYPE_H__
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*============================ INCLUDES ======================================*/
26
27#ifndef ENABLED
28# define ENABLED 1
29#endif
30
31#ifndef DISABLED
32# define DISABLED 0
33#endif
34
35/* do not modify this */
36#include "vsf_usr_cfg.h"
37
38/*============================ TYPES =========================================*/
39
42typedef enum {
62 =-17,
64 =-18,
67} vsf_err_t;
69
70#ifndef __FSM_RT_TYPE__
71#define __FSM_RT_TYPE__
74typedef enum {
83 fsm_rt_user = 4
86
87#endif
88
89/*============================ INCLUDES ======================================*/
90
108#if !defined(__USE_LOCAL_LIBC__)
109# include <ctype.h>
110# include <stdlib.h>
111# include <string.h>
112# include <stddef.h>
113# include <assert.h>
114#else
115# undef __USE_LOCAL_LIBC__
116#endif
117
118/*============================ MACROS ========================================*/
119
121#ifndef VSF_ASSERT
122# if VSF_USE_TRACE == ENABLED
123// do not extern vsf_trace_assert as a normal function, maybe it's a static inline function
124//extern void vsf_trace_assert(const char *expr, const char *file, int line, const char *func);
126# define VSF_ASSERT(__EXPR) \
127 ((__EXPR) \
128 ? (void)0 \
129 : vsf_trace_assert(#__EXPR, __FILE__, __LINE__, __FUNCTION__))
130# else
131# define VSF_ASSERT assert
132# endif
133#endif
134
135#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
136# ifndef __VSF_STR
137# define __VSF_STR(__STRING) #__STRING
138# endif
139# ifndef VSF_STR
140# define VSF_STR(__STRING) __VSF_STR(__STRING)
141# endif
142#else
143# ifndef __VSF_STR
144# define __VSF_STR(...) #__VA_ARGS__
145# endif
146# ifndef VSF_STR
147# define VSF_STR(...) __VSF_STR(__VA_ARGS__)
148# endif
149#endif
150
151#define vsf_max(__a, __b) (((__a) > (__b)) ? (__a) : (__b))
152#define vsf_min(__a, __b) (((__a) < (__b)) ? (__a) : (__b))
153
154#ifndef dimof
155# define dimof(__arr) (sizeof(__arr) / sizeof((__arr)[0]))
156#endif
157
158// use offsetof from compiler if available for constexpr feature in cpp
159#if __IS_COMPILER_GCC__ || __IS_COMPILER_LLVM__
160# define vsf_offset_of(__type, __member) __builtin_offsetof(__type, __member)
161#else
162# define vsf_offset_of(__type, __member) (uintptr_t)(&(((__type *)0)->__member))
163#endif
164#define vsf_container_of(__ptr, __type, __member) \
165 ((__type *)((uintptr_t)(__ptr) - vsf_offset_of(__type, __member)))
166#define vsf_safe_container_of(__ptr, __type, __member) \
167 (__ptr ? vsf_container_of(__ptr, __type, __member) : NULL)
168
169#ifndef VSF_COMPATIBILITY
170# define VSF_COMPATIBILITY ENABLED
171#endif
172#if VSF_COMPATIBILITY == ENABLED
173# ifndef container_of
174# define container_of vsf_container_of
175# endif
176# ifndef safe_container_of
177# define safe_container_of vsf_safe_container_of
178# endif
179#endif
180
181static inline int vsf_sign(int x)
182{
183 return ((int)((int)((int)(x) > 0) - (int)((int)(x) < 0)));
184}
185
186#define vsf_abs(__num) (((__num) < 0) ? (-(__num)) : (__num))
187
188#define VSF_BIT(__N) (1UL << (__N))
189#define VSF_BITMASK(__N) (VSF_BIT(__N) - 1)
190#define VSF_UNUSED_PARAM(__VAL) (void)(__VAL)
191
192#define VSF_STATIC_ASSERT(__COND) \
193 typedef int VSF_MACRO_SAFE_NAME(STATIC_ASSERT)[(__COND) * 2 - 1]
194
195// will be removed later
196#ifdef __VSF_COMPAT__
197# define min vsf_min
198# define max vsf_max
199# define __STR __VSF_STR
200# define STR VSF_STR
201# define sign vsf_sign
202#endif
203
204/*============================ MACROFIED FUNCTIONS ===========================*/
205/*============================ TYPES =========================================*/
206
207#if __IS_COMPILER_IAR__
209# pragma diag_suppress=pe301
210#endif
211
212
213#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
219typedef uint_least32_t char32_t;
220typedef uint_least16_t char16_t;
221#endif
222
223
224#if __IS_COMPILER_IAR__
226//# pragma diag_suppress=pe301
227#endif
228
229
230#ifndef __REG_TYPE__
231#define __REG_TYPE__
232
233typedef volatile uint8_t reg8_t;
234typedef volatile uint16_t reg16_t;
235typedef volatile uint32_t reg32_t;
236
237#define __REG_CONNECT(__A, __B) __A##__B
238#define __REG_RSVD_NAME(__NAME) __REG_CONNECT(__unused_, __NAME)
239
240#define ____REG_RSVD(__NAME, __BIT) \
241 reg##__BIT##_t __NAME : __BIT;
242#define ____REG_RSVD_N(__NAME, __BIT, __N) \
243 reg##__BIT##_t __NAME[__N];
244#define __REG_RSVD(__BIT) ____REG_RSVD(REG_RSVD_NAME, __BIT)
245#define __REG_RSVD_N(__BIT, __N) ____REG_RSVD_N(REG_RSVD_NAME, __BIT, (__N))
246
247#define REG_RSVD_NAME __REG_RSVD_NAME(__LINE__)
248#define REG_RSVD(__BIT) __REG_RSVD(__BIT)
249#define REG_RSVD_N(__BIT, __N) __REG_RSVD_N(__BIT, (__N))
250
251#define REG_RSVD_U8 REG_RSVD(8)
252#define REG_RSVD_U16 REG_RSVD(16)
253#define REG_RSVD_U32 REG_RSVD(32)
254
255#define REG_RSVD_U8N(__N) REG_RSVD_N(8, (__N))
256#define REG_RSVD_U16N(__N) REG_RSVD_N(16, (__N))
257#define REG_RSVD_U32N(__N) REG_RSVD_N(32, (__N))
258
259#define REG8_RSVD_N(__N) REG_RSVD_U8N(__N)
260#define REG8_RSVD_B(__BYTE_CNT) REG8_RSVD_N(__BYTE_CNT)
261#define REG8_RSVD_8B REG8_RSVD_B(8)
262#define REG8_RSVD_16B REG8_RSVD_B(16)
263#define REG8_RSVD_32B REG8_RSVD_B(32)
264#define REG8_RSVD_64B REG8_RSVD_B(64)
265#define REG8_RSVD_128B REG8_RSVD_B(128)
266#define REG8_RSVD_256B REG8_RSVD_B(256)
267#define REG8_RSVD_512B REG8_RSVD_B(512)
268#define REG8_RSVD_1K REG8_RSVD_B(1024)
269#define REG8_RSVD_2K REG8_RSVD_B(2048)
270#define REG8_RSVD_4K REG8_RSVD_B(4096)
271#define REG8_RSVD_8K REG8_RSVD_B(8192)
272#define REG8_RSVD_16K REG8_RSVD_B(16 * 1024)
273#define REG8_RSVD_32K REG8_RSVD_B(32 * 1024)
274#define REG8_RSVD_64K REG8_RSVD_B(64 * 1024)
275#define REG8_RSVD_128K REG8_RSVD_B(128 * 1024)
276#define REG8_RSVD_256K REG8_RSVD_B(256 * 1024)
277#define REG8_RSVD_512K REG8_RSVD_B(512 * 1024)
278#define REG8_RSVD_1M REG8_RSVD_B(1024 * 1024)
279
280#define REG16_RSVD_N(__N) REG_RSVD_U16N(__N)
281// __BYTE_CNT MUST be multiple of 2
282#define REG16_RSVD_B(__BYTE_CNT) REG16_RSVD_N(__BYTE_CNT >> 1)
283#define REG16_RSVD_8B REG16_RSVD_B(8)
284#define REG16_RSVD_16B REG16_RSVD_B(16)
285#define REG16_RSVD_32B REG16_RSVD_B(32)
286#define REG16_RSVD_64B REG16_RSVD_B(64)
287#define REG16_RSVD_128B REG16_RSVD_B(128)
288#define REG16_RSVD_256B REG16_RSVD_B(256)
289#define REG16_RSVD_512B REG16_RSVD_B(512)
290#define REG16_RSVD_1K REG16_RSVD_B(1024)
291#define REG16_RSVD_2K REG16_RSVD_B(2048)
292#define REG16_RSVD_4K REG16_RSVD_B(4096)
293#define REG16_RSVD_8K REG16_RSVD_B(8192)
294#define REG16_RSVD_16K REG16_RSVD_B(16 * 1024)
295#define REG16_RSVD_32K REG16_RSVD_B(32 * 1024)
296#define REG16_RSVD_64K REG16_RSVD_B(64 * 1024)
297#define REG16_RSVD_128K REG16_RSVD_B(128 * 1024)
298#define REG16_RSVD_256K REG16_RSVD_B(256 * 1024)
299#define REG16_RSVD_512K REG16_RSVD_B(512 * 1024)
300#define REG16_RSVD_1M REG16_RSVD_B(1024 * 1024)
301
302#define REG32_RSVD_N(__N) REG_RSVD_U32N(__N)
303// __BYTE_CNT MUST be multiple of 4
304#define REG32_RSVD_B(__BYTE_CNT) REG_RSVD_U32N(__BYTE_CNT >> 2)
305#define REG32_RSVD_8B REG32_RSVD_B(8)
306#define REG32_RSVD_16B REG32_RSVD_B(16)
307#define REG32_RSVD_32B REG32_RSVD_B(32)
308#define REG32_RSVD_64B REG32_RSVD_B(64)
309#define REG32_RSVD_128B REG32_RSVD_B(128)
310#define REG32_RSVD_256B REG32_RSVD_B(256)
311#define REG32_RSVD_512B REG32_RSVD_B(512)
312#define REG32_RSVD_1K REG32_RSVD_B(1024)
313#define REG32_RSVD_2K REG32_RSVD_B(2048)
314#define REG32_RSVD_4K REG32_RSVD_B(4096)
315#define REG32_RSVD_8K REG32_RSVD_B(8192)
316#define REG32_RSVD_16K REG32_RSVD_B(16 * 1024)
317#define REG32_RSVD_32K REG32_RSVD_B(32 * 1024)
318#define REG32_RSVD_64K REG32_RSVD_B(64 * 1024)
319#define REG32_RSVD_128K REG32_RSVD_B(128 * 1024)
320#define REG32_RSVD_256K REG32_RSVD_B(256 * 1024)
321#define REG32_RSVD_512K REG32_RSVD_B(512 * 1024)
322#define REG32_RSVD_1M REG32_RSVD_B(1024 * 1024)
323
324#endif // __REG_TYPE__
325
326
327
328
329/*============================ GLOBAL VARIABLES ==============================*/
330/*============================ LOCAL VARIABLES ===============================*/
331/*============================ PROTOTYPES ====================================*/
332
333#ifdef __cplusplus
334}
335#endif
336
337
338/*============================ Multiple-Entry ================================*/
339
344#if !defined(__USE_LOCAL_STDIO__)
345//#warning including stdio.h //! uncomment this for debugging purpose only
346# include <stdio.h>
347#else
348//# warning user ignored standard stdio.h //! uncomment this for debugging purpose only
349# undef __USE_LOCAL_STDIO__
350#endif
351
352#if !defined(__USE_LOCAL_SETJMP__)
353//#warning including setjmp.h //! uncomment this for debugging purpose only
354# include <setjmp.h>
355#else
356//# warning user ignored standard setjmp.h //! uncomment this for debugging purpose only
357# undef __USE_LOCAL_SETJMP__
358#endif
359
360#if !defined(__USE_LOCAL_STDARG__)
361//#warning including stdarg.h //! uncomment this for debugging purpose only
362# include <stdarg.h>
363#else
364//# warning user ignored standard stdarg.h //! uncomment this for debugging purpose only
365# undef __USE_LOCAL_STDARG__
366#endif
367
368#endif // __COMMON_TYPE_H__
volatile uint32_t reg32_t
Definition __type.h:235
volatile uint16_t reg16_t
Definition __type.h:234
volatile uint8_t reg8_t
Definition __type.h:233
vsf_err_t
Definition __type.h:42
@ VSF_ERR_NOT_SUPPORT
function not supported
Definition __type.h:46
@ VSF_ERR_NONE
none error
Definition __type.h:44
@ VSF_ERR_NOT_ACCESSIBLE
Definition __type.h:49
@ VSF_ERR_INVALID_PTR
invalid pointer
Definition __type.h:54
@ VSF_ERR_INVALID_PARAMETER
invalid parameter
Definition __type.h:52
@ VSF_ERR_ALREADY_EXISTS
already exists
Definition __type.h:57
@ VSF_ERR_NOT_READY
service not ready yet
Definition __type.h:43
@ VSF_ERR_NOT_AVAILABLE
service not available
Definition __type.h:47
@ VSF_ERR_REQ_ALREADY_REGISTERED
request all ready exist
Definition __type.h:58
@ VSF_ERR_IO
IO error.
Definition __type.h:56
@ VSF_ERR_BUG
bug
Definition __type.h:59
@ VSF_ERR_TIMEOUT
Definition __type.h:65
@ VSF_ERR_OVERRUN
overrun
Definition __type.h:60
@ VSF_ERR_PROVIDED_RESOURCE_NOT_SUFFICIENT
the resource provided by user is not sufficient
Definition __type.h:61
@ VSF_ERR_PROVIDED_RESOURCE_NOT_ALIGNED
the provided resource is not aligned to certain size (2^N)
Definition __type.h:63
@ VSF_ERR_NOT_ACCESSABLE
target not acceesable
Definition __type.h:48
@ VSF_ERR_UNKNOWN
unknown error
Definition __type.h:45
@ VSF_ERR_INVALID_KEY
invalid key
Definition __type.h:55
@ VSF_ERR_INVALID_RANGE
invalid range
Definition __type.h:53
@ VSF_ERR_FAIL
failed
Definition __type.h:51
@ VSF_ERR_NOT_ENOUGH_RESOURCES
no enough resources
Definition __type.h:50
@ VSF_ERR_BUSY
Definition __type.h:66
fsm_rt_t
Definition __type.h:74
@ fsm_rt_wait_for_evt
Definition __type.h:80
@ fsm_rt_asyn
fsm asynchronose complete, you can check it later.
Definition __type.h:82
@ fsm_rt_err
fsm error, error code can be get from other interface
Definition __type.h:75
@ fsm_rt_wait_for_obj
fsm wait for object
Definition __type.h:79
@ fsm_rt_user
Definition __type.h:83
@ fsm_rt_cpl
fsm complete
Definition __type.h:76
@ fsm_rt_yield
Definition __type.h:78
@ fsm_rt_wfe
Definition __type.h:81
@ fsm_rt_on_going
fsm on-going
Definition __type.h:77
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned uint_least32_t
Definition stdint.h:18
unsigned char uint8_t
Definition stdint.h:5
unsigned short uint_least16_t
Definition stdint.h:16