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