00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _COMPILER_H_
00031 #define _COMPILER_H_
00032
00033
00034
00035
00036 #if defined(__SAMV71Q21__)
00037 #include "include/samv71/samv71.h"
00038 #elif defined(__SAME70Q21__)
00039 #include "include/same70/same70.h"
00040 #else
00041 #error "please define correct macro for the chip first!"
00042 #endif
00043
00044
00045
00046
00047 #ifndef __ASSEMBLY__
00048
00049 #include <stddef.h>
00050 #include <stdlib.h>
00051 #include <stdbool.h>
00052 #include <stdint.h>
00053
00054
00055 #if defined (__CC_ARM)
00056 #define WEAK __attribute__ ((weak))
00057 #elif defined (__ICCARM__)
00058 #define WEAK __weak
00059 #elif defined (__GNUC__)
00060 #define WEAK __attribute__ ((weak))
00061 #endif
00062
00063
00064 #if defined (__CC_ARM)
00065 #define COMPILER_NAME "KEIL"
00066 #elif defined (__ICCARM__)
00067 #define COMPILER_NAME "IAR"
00068 #elif defined (__GNUC__)
00069 #define COMPILER_NAME "GCC"
00070 #endif
00071
00072
00073 #if defined (__CC_ARM)
00074 #define NO_INIT
00075 #elif defined (__ICCARM__)
00076 #define NO_INIT __no_init
00077 #elif defined (__GNUC__)
00078 #define NO_INIT
00079 #endif
00080
00081
00082
00083 #if defined (__CC_ARM)
00084 #define memory_sync() __dsb(15);__isb(15);
00085 #elif defined (__ICCARM__)
00086 #define memory_sync() __DSB();__ISB();
00087 #elif defined (__GNUC__)
00088 #define memory_sync() __DSB();__ISB();
00089 #endif
00090
00091
00092 #if defined (__CC_ARM)
00093 #define memory_barrier() __dmb(15);
00094 #elif defined (__ICCARM__)
00095 #define memory_barrier() __DMB();
00096 #elif defined (__GNUC__)
00097 #define memory_barrier() __DMB();
00098 #endif
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #define TPASTE2(a, b) a##b
00112 #define TPASTE3(a, b, c) a##b##c
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 #define ATPASTE2(a, b) TPASTE2(a, b)
00126 #define ATPASTE3(a, b, c) TPASTE3(a, b, c)
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #define COMPILER_PRAGMA(arg) _Pragma(#arg)
00137
00138
00139
00140
00141
00142
00143 #define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
00144
00145
00146
00147
00148
00149
00150 #define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
00151
00152
00153
00154
00155
00156 #if defined (__CC_ARM)
00157 #define COMPILER_SECTION(a) __attribute__((__section__(a)))
00158 #elif defined (__ICCARM__)
00159 #define COMPILER_SECTION(a) COMPILER_PRAGMA(location = a)
00160 #elif defined (__GNUC__)
00161 #define COMPILER_SECTION(a) __attribute__((__section__(a)))
00162 #endif
00163
00164
00165
00166
00167 #if defined (__CC_ARM)
00168 #define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
00169 #elif defined (__ICCARM__)
00170 #define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
00171 #elif defined (__GNUC__)
00172 #define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
00173 #endif
00174
00175
00176
00177
00178
00179 #if defined (__CC_ARM)
00180 #define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
00181 #elif defined (__ICCARM__)
00182 #define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
00183 #elif defined (__GNUC__)
00184 #define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
00185 #endif
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 #define Abs(a) (((a) < 0) ? -(a) : (a))
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 #define Min(a, b) (((a) < (b)) ? (a) : (b))
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 #define Max(a, b) (((a) > (b)) ? (a) : (b))
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 #define min(a, b) Min(a, b)
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 #define max(a, b) Max(a, b)
00257
00258
00259
00260 #define be32_to_cpu(x) __REV(x)
00261 #define cpu_to_be32(x) __REV(x)
00262 #define BE32_TO_CPU(x) __REV(x)
00263 #define CPU_TO_BE32(x) __REV(x)
00264
00265
00266
00267
00268
00269 #define UNUSED(v) (void)(v)
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 # define irq_initialize_vectors() \
00293 do { \
00294 } while (0)
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 # define irq_register_handler(int_num, int_prio) \
00314 NVIC_ClearPendingIRQ((IRQn_Type)int_num); \
00315 NVIC_SetPriority((IRQn_Type)int_num, int_prio); \
00316 NVIC_EnableIRQ((IRQn_Type)int_num); \
00317
00318
00319
00320
00321 # define cpu_irq_enable() \
00322 do { \
00323 \
00324 __DMB(); \
00325 __enable_irq(); \
00326 } while (0)
00327 # define cpu_irq_disable() \
00328 do { \
00329 __disable_irq(); \
00330 __DMB(); \
00331 \
00332 } while (0)
00333
00334 typedef uint32_t irqflags_t;
00335
00336 #if !defined(__DOXYGEN__)
00337 extern volatile bool g_interrupt_enabled;
00338 #endif
00339
00340 #define cpu_irq_is_enabled() (__get_PRIMASK() == 0)
00341
00342 static volatile uint32_t cpu_irq_critical_section_counter;
00343 static volatile bool cpu_irq_prev_interrupt_state;
00344
00345 static inline irqflags_t cpu_irq_save(void)
00346 {
00347 irqflags_t flags = cpu_irq_is_enabled();
00348 cpu_irq_disable();
00349 return flags;
00350 }
00351
00352 static inline bool cpu_irq_is_enabled_flags(irqflags_t flags)
00353 {
00354 return (flags);
00355 }
00356
00357 static inline void cpu_irq_restore(irqflags_t flags)
00358 {
00359 if (cpu_irq_is_enabled_flags(flags))
00360 cpu_irq_enable();
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 #define Enable_global_interrupt() cpu_irq_enable()
00372 #define Disable_global_interrupt() cpu_irq_disable()
00373 #define Is_global_interrupt_enabled() cpu_irq_is_enabled()
00374
00375
00376
00377
00378
00379
00380
00381 #define DISABLE 0
00382 #define ENABLE 1
00383 #define DISABLED 0
00384 #define ENABLED 1
00385 #define OFF 0
00386 #define ON 1
00387 #define FALSE 0
00388 #define TRUE 1
00389 #ifndef __cplusplus
00390 #if !defined(__bool_true_false_are_defined)
00391 #define false FALSE
00392 #define true TRUE
00393 #endif
00394 #endif
00395 #define KO 0
00396 #define OK 1
00397 #define PASS 0
00398 #define FAIL 1
00399 #define LOW 0
00400 #define HIGH 1
00401 #define CLR 0
00402 #define SET 1
00403
00404
00405
00406
00407
00408
00409
00410
00411 #define ctz(u) ((u) & (1ul << 0) ? 0 : \
00412 (u) & (1ul << 1) ? 1 : \
00413 (u) & (1ul << 2) ? 2 : \
00414 (u) & (1ul << 3) ? 3 : \
00415 (u) & (1ul << 4) ? 4 : \
00416 (u) & (1ul << 5) ? 5 : \
00417 (u) & (1ul << 6) ? 6 : \
00418 (u) & (1ul << 7) ? 7 : \
00419 (u) & (1ul << 8) ? 8 : \
00420 (u) & (1ul << 9) ? 9 : \
00421 (u) & (1ul << 10) ? 10 : \
00422 (u) & (1ul << 11) ? 11 : \
00423 (u) & (1ul << 12) ? 12 : \
00424 (u) & (1ul << 13) ? 13 : \
00425 (u) & (1ul << 14) ? 14 : \
00426 (u) & (1ul << 15) ? 15 : \
00427 (u) & (1ul << 16) ? 16 : \
00428 (u) & (1ul << 17) ? 17 : \
00429 (u) & (1ul << 18) ? 18 : \
00430 (u) & (1ul << 19) ? 19 : \
00431 (u) & (1ul << 20) ? 20 : \
00432 (u) & (1ul << 21) ? 21 : \
00433 (u) & (1ul << 22) ? 22 : \
00434 (u) & (1ul << 23) ? 23 : \
00435 (u) & (1ul << 24) ? 24 : \
00436 (u) & (1ul << 25) ? 25 : \
00437 (u) & (1ul << 26) ? 26 : \
00438 (u) & (1ul << 27) ? 27 : \
00439 (u) & (1ul << 28) ? 28 : \
00440 (u) & (1ul << 29) ? 29 : \
00441 (u) & (1ul << 30) ? 30 : \
00442 (u) & (1ul << 31) ? 31 : \
00443 32)
00444
00445 #endif // __ASSEMBLY__
00446
00447 #endif // _COMPILER_H_