ubinos
type.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Sung Ho Park
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef UBINOS_TYPE_H_
8 #define UBINOS_TYPE_H_
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
23 #include <ubinos_config.h>
24 
25 #if (UBINOS__BSP__CPU_ARCH == UBINOS__BSP__CPU_ARCH__ARM)
26 
27 #ifndef __ASSEMBLY__
28 
30 typedef unsigned char byte_t;
31 
33 typedef unsigned short word_t;
34 
36 typedef unsigned int dword_t;
37 
38 #endif /* __ASSEMBLY__ */
39 
40 #ifndef NULL
42 #define NULL 0
43 #endif
44 
45 #ifndef EOF
47 #define EOF (-1)
48 #endif
49 
50 #ifndef __SIZE_TYPE__
52 #define __SIZE_TYPE__ long unsigned int
53 #endif
54 
55 #ifndef __ASSEMBLY__
56 
59 
60 #endif /* __ASSEMBLY__ */
61 
63 #define SIZETOUINT(a) (a)
64 
66 #define UINTTOSIZE(a) (a)
67 
68 #ifndef INT_MIN
70 #define INT_MIN 0x80000000L // -2147483648
71 #endif
72 
73 #ifndef INT_MAX
75 #define INT_MAX 0x7FFFFFFFL // 2147483647
76 #endif
77 
78 #ifndef UINT_MAX
80 #define UINT_MAX 0xFFFFFFFFL // 4294967295
81 #endif
82 
83 #ifndef INT_SIZE
85 #define INT_SIZE 4
86 #endif
87 
88 #ifndef INT16_MIN
90 #define INT16_MIN 0x8000 // -32768
91 #endif
92 
93 #ifndef INT16_MAX
95 #define INT16_MAX 0x7FFF // 32767
96 #endif
97 
98 #ifndef UINT16_MAX
100 #define UINT16_MAX 0xFFFF // 65535
101 #endif
102 
104 #define MEM_ALIGNMENT INT_SIZE
105 
107 #define MEM_ALIGNMASK (MEM_ALIGNMENT - 1)
108 
110 #define MEM_ALIGN(a) ((((unsigned int) (a)) + MEM_ALIGNMASK) & (~MEM_ALIGNMASK))
111 
112 #define MEM_ALIGNMASK_16 (16 - 1)
113 
114 #define MEM_ALIGN_16(a) ((((unsigned int) (a)) + MEM_ALIGNMASK_16) & (~MEM_ALIGNMASK_16))
115 
116 #elif (UBINOS__BSP__CPU_ARCH == UBINOS__BSP__CPU_ARCH__LOCAL)
117 
118 #ifndef NULL
120 #define NULL 0
121 #endif
122 
124 typedef __SIZE_TYPE__ size_t;
125 
126 #else
127 
128 #error "Unsupported UBINOS__BSP__CPU_ARCH"
129 
130 #endif /* (UBINOS__BSP__CPU_ARCH == ... */
131 
132 #ifndef __ASSEMBLY__
133 
134 #include <stdint.h>
135 #include <assert.h>
136 
137 #include <ubinos/objtype.h>
138 
140 typedef enum {
141  UBI_ST_OK = 0,
170 } ubi_st_t;
171 
172 #define ubi_assert(__expr) assert(__expr)
173 
174 #define ubi_assert_ok(__ubi_st) ubi_assert(__ubi_st == UBI_ST_OK)
175 #define ubi_assert_not_null(__ptr) ubi_assert((void *) __ptr != NULL)
176 
177 #define ubi_unused(__var) do { (void) __var; } while(0)
178 
179 /* Deprecated */
180 #define UBI_ERR_INTERNAL UBI_ST_ERR
181 
182 #define ubi_err_t ubi_st_t
183 
184 #define UBI_ERR_OK UBI_ST_OK
185 #define UBI_ERR_ERROR UBI_ST_ERR
186 #define UBI_ERR_BUSY UBI_ST_BUSY
187 #define UBI_ERR_TIMEOUT UBI_ST_TIMEOUT
188 #define UBI_ERR_CANCEL UBI_ST_CANCEL
189 #define UBI_ERR_CANCEL_2 UBI_ST_CANCEL_2
190 
191 #define UBI_ERR_UNKNOWN UBI_ST_ERR_UNKNOWN
192 #define UBI_ERR_NULL UBI_ST_ERR_NULL
193 #define UBI_ERR_NO_MEM UBI_ST_ERR_NO_MEM
194 #define UBI_ERR_BUF_FULL UBI_ST_ERR_BUF_FULL
195 #define UBI_ERR_BUF_EMPTY UBI_ST_ERR_BUF_EMPTY
196 #define UBI_ERR_NOT_FOUND UBI_ST_ERR_NOT_FOUND
197 #define UBI_ERR_NOT_SUPPORTED UBI_ST_ERR_NOT_SUPPORTED
198 #define UBI_ERR_INVALID_PARAM UBI_ST_ERR_INVALID_PARAM
199 #define UBI_ERR_INVALID_DATA UBI_ST_ERR_INVALID_DATA
200 #define UBI_ERR_INVALID_LENGTH UBI_ST_ERR_INVALID_LENGTH
201 #define UBI_ERR_INVALID_ADDR UBI_ST_ERR_INVALID_ADDR
202 #define UBI_ERR_INVALID_STATE UBI_ST_ERR_INVALID_STATE
203 #define UBI_ERR_INIT UBI_ST_ERR_INIT
204 #define UBI_ERR_RESET UBI_ST_ERR_RESET
205 #define UBI_ERR_IO UBI_ST_ERR_IO
206 #define UBI_ERR_TX UBI_ST_ERR_TX
207 #define UBI_ERR_RX UBI_ST_ERR_RX
208 #define UBI_ERR_PACKET UBI_ST_ERR_PACKET
209 #define UBI_ERR_HEAP UBI_ST_ERR_HEAP
210 #define UBI_ERR_BUS UBI_ST_ERR_BUS
211 
212 #define UBI_ERR_BUS_INIT UBI_ST_ERR_INIT
213 #define UBI_ERR_BUS_RESET UBI_ST_ERR_RESET
214 #define UBI_ERR_BUS_IO UBI_ST_ERR_IO
215 #define UBI_ERR_BUS_TX UBI_ST_ERR_TX
216 #define UBI_ERR_BUS_RX UBI_ST_ERR_RX
217 
218 #endif /* __ASSEMBLY__ */
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif /* UBINOS_TYPE_H_ */
225 
ubinos object type
unsigned int dword_t
Definition: type.h:36
ubi_st_t
Definition: type.h:140
@ UBI_ST_CANCEL_2
Definition: type.h:146
@ UBI_ST_ERR_BUF_EMPTY
Definition: type.h:152
@ UBI_ST_ERR_INVALID_ADDR
Definition: type.h:158
@ UBI_ST_ERR_RESET
Definition: type.h:161
@ UBI_ST_ERR_HEAP
Definition: type.h:166
@ UBI_ST_ERR_TX
Definition: type.h:163
@ UBI_ST_ERR_INVALID_LENGTH
Definition: type.h:157
@ UBI_ST_ERR_NOT_FOUND
Definition: type.h:153
@ UBI_ST_ERR_PACKET
Definition: type.h:165
@ UBI_ST_ERR_BUF_FULL
Definition: type.h:151
@ UBI_ST_OK
Definition: type.h:141
@ UBI_ST_BUSY
Definition: type.h:143
@ UBI_ST_ERR_NOT_SUPPORTED
Definition: type.h:154
@ UBI_ST_ERR_INVALID_DATA
Definition: type.h:156
@ UBI_ST_ERR_INIT
Definition: type.h:160
@ UBI_ST_TIMEOUT
Definition: type.h:144
@ UBI_ST_ERR
Definition: type.h:142
@ UBI_ST_CANCEL
Definition: type.h:145
@ UBI_ST_ERR_IO
Definition: type.h:162
@ UBI_ST_ERR_UNDERFLOW
Definition: type.h:169
@ UBI_ST_ERR_BUS
Definition: type.h:167
@ UBI_ST_ERR_RX
Definition: type.h:164
@ UBI_ST_ERR_UNKNOWN
Definition: type.h:148
@ UBI_ST_ERR_INVALID_STATE
Definition: type.h:159
@ UBI_ST_ERR_INVALID_PARAM
Definition: type.h:155
@ UBI_ST_ERR_OVERFLOW
Definition: type.h:168
@ UBI_ST_ERR_NO_MEM
Definition: type.h:150
@ UBI_ST_ERR_NULL
Definition: type.h:149
unsigned char byte_t
Definition: type.h:30
__SIZE_TYPE__ size_t
Definition: type.h:58
#define __SIZE_TYPE__
Definition: type.h:52
unsigned short word_t
Definition: type.h:33