1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 #ifndef __PLAT_TYPES_H__ 5 #define __PLAT_TYPES_H__ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 #include "stddef.h" 12 #include "stdint.h" 13 #include "stdbool.h" 14 #ifdef FPGA 15 #define __TCMDATA __attribute__((section(".tcmdata"))) 16 #define __RAMCODE __attribute__((section(".ramcode"))) 17 #define __RAMDATA __attribute__((section(".ramdata"))) 18 #define __PSRAMCODE 19 #define __PSRAMDATA 20 #define __PSRAMBSS 21 #define __SRAM_EXT_BSS __attribute__((section(".sram_bss"))) 22 23 #ifdef RESTRICTED_RAM 24 #define __RRAMCODE __attribute__((section(".rram_text"))) 25 #define __RRAMDATA __attribute__((section(".rram_data"))) 26 #define __RRAMBSS __attribute__((section(".rram_bss"))) 27 #else 28 #define __RRAMCODE 29 #define __RRAMDATA 30 #define __RRAMBSS 31 #endif 32 #define __SRAMCODE __attribute__((section(".sram_text"))) 33 #define __SRAMDATA __attribute__((section(".sram_data"))) 34 #define __SRAMBSS __attribute__((section(".sram_bss"))) 35 #define __AUDMA __attribute__((section(".audma"))) 36 #define __FSRAMCODE __attribute__((section(".fast_text_sram"))) 37 #define __BOOTSRAMCODE __attribute__((section(".boot_text_sram"))) 38 39 #ifdef __FAR_FIELD_2000IWA__ 40 #define __RX_CODE 41 #else 42 #define __RX_CODE __SRAMCODE 43 #endif 44 45 #else /*FPGA*/ 46 47 #define __TCMDATA __attribute__((section(".tcmdata"))) 48 #define __RAMCODE __attribute__((section(".ramcode"))) 49 #define __RAMDATA __attribute__((section(".ramdata"))) 50 51 #ifdef RESTRICTED_RAM 52 #define __RRAMCODE __attribute__((section(".rram_text"))) 53 #define __RRAMDATA __attribute__((section(".rram_data"))) 54 #define __RRAMBSS __attribute__((section(".rram_bss"))) 55 #else 56 #define __RRAMCODE 57 #define __RRAMDATA 58 #define __RRAMBSS 59 #endif 60 #define __SRAMCODE __attribute__((section(".sram_text"))) 61 #define __SRAMDATA __attribute__((section(".sram_data"))) 62 #define __SRAMBSS __attribute__((section(".sram_bss"))) 63 #define __AUDMA __attribute__((section(".audma"))) 64 #define __FSRAMCODE __attribute__((section(".fast_text_sram"))) 65 #define __BOOTSRAMCODE __attribute__((section(".boot_text_sram"))) 66 67 #if defined(CHIP_HAS_PSRAM) && defined(PSRAM_ENABLE) 68 #define __PSRAMCODE __attribute__((section(".psram_text"))) 69 #define __PSRAMDATA __attribute__((section(".psram_data"))) 70 #define __PSRAMBSS __attribute__((section(".psram_bss"))) 71 #elif defined(CHIP_HAS_PSRAMUHS) && defined(PSRAMUHS_ENABLE) 72 #define __PSRAMUHSCODE __attribute__((section(".psramuhs_text"))) 73 #define __PSRAMUHSDATA __attribute__((section(".psramuhs_data"))) 74 #define __PSRAMUHSBSS __attribute__((section(".psramuhs_bss"))) 75 #define __PSRAMCODE __PSRAMUHSCODE 76 #define __PSRAMDATA __PSRAMUHSDATA 77 // #define __PSRAMBSS __PSRAMUHSBSS 78 #define __PSRAMBSS 79 #else 80 #define __PSRAMCODE 81 #define __PSRAMDATA 82 #define __PSRAMBSS 83 #endif 84 85 #define __SRAM_EXT_CODE __PSRAMCODE 86 #define __SRAM_EXT_DATA __PSRAMDATA 87 #define __SRAM_EXT_BSS __PSRAMBSS 88 89 #ifdef __FAR_FIELD_2000IWA__ 90 #define __RX_CODE 91 #else 92 #define __RX_CODE __SRAMCODE 93 #endif 94 95 #endif /*FPGA*/ 96 97 #ifndef TRUE 98 #define TRUE 1 99 #endif 100 #ifndef FALSE 101 #define FALSE 0 102 #endif 103 104 #ifndef X32_F 105 #define X32_F "x" 106 #endif 107 #ifndef X16_F 108 #define X16_F "x" 109 #endif 110 #ifndef U32_F 111 #define U32_F "d" 112 #endif 113 #ifndef S32_F 114 #define S32_F "d" 115 #endif 116 #ifndef S16_F 117 #define S16_F "d" 118 #endif 119 #ifndef U16_F 120 #define U16_F "d" 121 #endif 122 123 typedef long long __int64; 124 typedef long long __le64; 125 126 typedef unsigned short __le16; 127 typedef unsigned int __le32; 128 129 typedef unsigned short __be16; 130 typedef unsigned int __be32; 131 typedef unsigned short __u16; 132 typedef unsigned char __u8; 133 typedef short __s16; 134 typedef char __s8; 135 typedef unsigned int __u32; 136 typedef unsigned long u32; 137 typedef int __s32; 138 139 typedef float FP32; /* Single precision floating point */ 140 typedef double FP64; /* Double precision floating point */ 141 142 typedef unsigned int OS_STK; /* Each stack entry is 32-bit wide */ 143 typedef unsigned int OS_CPU_SR; /* Define size of CPU status register (PSR = 32 bits) */ 144 typedef void (*FUNCPtr)(void*); 145 146 typedef unsigned char INT8U; /* Unsigned 8 bit quantity */ 147 typedef signed char INT8S; /* Signed 8 bit quantity */ 148 149 typedef unsigned char UCHAR; 150 typedef char CHAR; 151 typedef unsigned char* PUCHAR; 152 typedef signed char* PCHAR; 153 154 typedef unsigned char UINT8; 155 typedef unsigned char uint8; 156 typedef unsigned short UINT16; 157 typedef unsigned short uint16; 158 typedef unsigned int UINT32; typedef unsigned int uint32; 159 typedef unsigned int uint32; 160 161 typedef signed char INT8; 162 typedef signed char int8; 163 typedef short INT16; 164 typedef short int16; 165 typedef int INT32; 166 typedef int int32; 167 168 typedef uint8_t u8_t; 169 typedef int8_t s8_t; 170 typedef uint16_t u16_t; 171 typedef int16_t s16_t; 172 typedef uint32_t u32_t; 173 typedef int32_t s32_t; 174 175 typedef unsigned char u8; 176 typedef unsigned short u16; 177 typedef unsigned long u32; 178 typedef unsigned long long u64; 179 180 typedef unsigned char U8; 181 typedef unsigned short U16; 182 typedef unsigned int U32; 183 typedef unsigned long long U64; 184 185 typedef char s8; 186 typedef short s16; 187 typedef long s32; 188 typedef long long s64; 189 190 //typedef char ascii; 191 typedef unsigned char byte; /* unsigned 8-bit data */ 192 typedef unsigned short word; /* unsigned 16-bit data */ 193 typedef unsigned long dword; /* unsigned 32-bit data */ 194 195 196 /* IO definitions (access restrictions to peripheral registers) */ 197 /** 198 \defgroup CMSIS_glob_defs CMSIS Global Defines 199 200 <strong>IO Type Qualifiers</strong> are used 201 \li to specify the access to peripheral variables. 202 \li for automatic generation of peripheral register debug information. 203 */ 204 #ifndef __I 205 #ifdef __cplusplus 206 #define __I volatile /*!< Defines 'read only' permissions */ 207 #else 208 #define __I volatile const /*!< Defines 'read only' permissions */ 209 #endif 210 #define __O volatile /*!< Defines 'write only' permissions */ 211 #define __IO volatile /*!< Defines 'read / write' permissions */ 212 #endif 213 214 215 #define BITFIELD_VAL(field, value) (((value) & (field ## _MASK >> field ## _SHIFT)) << field ## _SHIFT) 216 #define SET_BITFIELD(reg, field, value) (((reg) & ~field ## _MASK) | BITFIELD_VAL(field, value)) 217 #define GET_BITFIELD(reg, field) (((reg) & field ## _MASK) >> field ## _SHIFT) 218 219 220 /* Frequently used macros */ 221 222 #ifndef ALIGN 223 #define ALIGN(val,exp) (((val) + ((exp)-1)) & ~((exp)-1)) 224 #endif 225 #ifndef ARRAY_SIZE 226 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 227 #endif 228 #define LAST_ELEMENT(x) (&x[ARRAY_SIZE(x)-1]) 229 #define BOUND(x, min, max) ( (x) < (min) ? (min) : ((x) > (max) ? (max):(x)) ) 230 #define ROUND_SIZEOF(t) ((sizeof(t)+sizeof(int)-1)&~(sizeof(int)-1)) 231 232 #ifndef MAX 233 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 234 #endif 235 #ifndef MIN 236 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 237 #endif 238 #ifndef ABS 239 #define ABS(x) ((x<0)?(-(x)):(x)) 240 #endif 241 242 #define TO_STRING_A(s) # s 243 #define TO_STRING(s) TO_STRING_A(s) 244 245 #ifdef __GNUC__ 246 247 /* Remove const cast-away warnings from gcc -Wcast-qual */ 248 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 249 250 /// From http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/ 251 /// Macro to use in a if statement to tell the compiler this branch 252 /// is likely taken, and optimize accordingly. 253 #define LIKELY(x) __builtin_expect(!!(x), 1) 254 /// Macro to use in a if statement to tell the compiler this branch 255 /// is unlikely take, and optimize accordingly. 256 #define UNLIKELY(x) __builtin_expect(!!(x), 0) 257 258 /// For packing structure 259 #define PACKED __attribute__((packed)) 260 261 /// To describe alignment 262 #define ALIGNED(a) __attribute__((aligned(a))) 263 264 /// For possibly unused functions or variables (e.g., debugging stuff) 265 #define POSSIBLY_UNUSED __attribute__((unused)) 266 267 /// For functions or variables must be emitted even if not referenced 268 #define USED __attribute__((used)) 269 270 /// For inline functions 271 #define ALWAYS_INLINE __attribute__((always_inline)) 272 273 // For functions never inlined 274 #define NOINLINE __attribute__((noinline)) 275 276 // For functions not caring performance 277 #ifdef __ARMCC_VERSION 278 #define OPT_SIZE 279 #else 280 #define OPT_SIZE __attribute__((optimize("Os"))) 281 #endif 282 283 // For functions not returning 284 #define NORETURN __attribute__((noreturn)) 285 286 // For ASM functions in C 287 #ifdef __arm__ 288 #define NAKED __attribute__((naked)) 289 #else 290 #define NAKED __attribute__((error("Unsupport naked functions"))) 291 #endif 292 293 // For weak symbols 294 #define WEAK __attribute__((weak)) 295 296 // Structure offset 297 #ifndef OFFSETOF 298 #define OFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 299 #endif 300 301 /** 302 * CONTAINER_OF - cast a member of a structure out to the containing structure 303 * @ptr: the pointer to the member. 304 * @type: the type of the container struct this is embedded in. 305 * @member: the name of the member within the struct. 306 * 307 */ 308 #ifndef CONTAINER_OF 309 #define CONTAINER_OF(ptr, type, member) ({ \ 310 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 311 (type *)( (char *)__mptr - OFFSETOF(type,member) );}) 312 #endif 313 314 #else // Not GCC 315 316 #define __UNCONST(a) 317 #define LIKELY(x) 318 #define UNLIKELY(x) 319 #define PACKED 320 #define ALIGNED(a) 321 #define POSSIBLY_UNUSED 322 #define USED 323 #define ALWAYS_INLINE 324 #define NOINLINE 325 #define OPT_SIZE 326 #define NORETURN 327 #define NAKED 328 #define WEAK 329 #define OFFSETOF(TYPE, MEMBER) 330 331 #endif // Not GCC 332 333 /// C preprocessor conditional check 334 /// -------------------------------- 335 #define GCC_VERSION (__GNUC__ * 10000 \ 336 + __GNUC_MINOR__ * 100 \ 337 + __GNUC_PATCHLEVEL__) 338 339 #if defined(__GNUC__) && (GCC_VERSION >= 40600) && !defined(__cplusplus) 340 341 // GCC 4.6 or later 342 #define STATIC_ASSERT(e, m) _Static_assert(e, m) 343 344 #elif defined(__GNUC__) && (GCC_VERSION >= 40300) && defined(__cplusplus) && (__cplusplus >= 201103L) 345 346 #define STATIC_ASSERT(e, m) static_assert(e, m) 347 348 #else // No built-in static assert 349 350 /// FROM: http://www.pixelbeat.org/programming/gcc/static_assert.html 351 #define ASSERT_CONCAT_(a, b) a##b 352 #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) 353 /* These can't be used after statements in c89. */ 354 #ifdef __COUNTER__ 355 #define STATIC_ASSERT(e, m) \ 356 enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }; 357 #else 358 /* This can't be used twice on the same line so ensure if using in headers 359 * that the headers are not included twice (by wrapping in #ifndef...#endif) 360 * Note it doesn't cause an issue when used on same line of separate modules 361 * compiled with gcc -combine -fwhole-program. */ 362 #define STATIC_ASSERT(e, m) \ 363 enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }; 364 #endif 365 366 #endif // No built-in static assert 367 /// -------------------------------- 368 369 #ifdef __cplusplus 370 } 371 #endif 372 373 #endif 374 375