Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
stm32w108
hal
micro
cortexm3
compiler
gnu.h
Go to the documentation of this file.
1
/** @file hal/micro/cortexm3/compiler/gnu.h
2
* See @ref gnu for detailed documentation.
3
*
4
*/
5
6
/** @addtogroup gnu
7
* @brief Compiler and Platform specific definitions and typedefs for the
8
* GNU C ARM compiler.
9
*
10
* @note gnu.h should be included first in all source files by setting the
11
* preprocessor macro PLATFORM_HEADER to point to it. gnu.h automatically
12
* includes platform-common.h.
13
*
14
* See gnu.h and platform-common.h for source code.
15
*@{
16
*/
17
18
#ifndef __GNU_H__
19
#define __GNU_H__
20
21
#ifndef __GNUC__
22
#error Improper PLATFORM_HEADER
23
#endif
24
25
#if (__GNUC__ < 4)
26
#error Only GNU C versions later than 4.3.2 are supported
27
#elif (__GNUC__ == 4)
28
#if (__GNUC_MINOR__ < 3)
29
#error Only GNU C versions later than 4.3.2 are supported
30
#elif (__GNUC_MINOR__ == 3)
31
#if (__GNUC_PATCHLEVEL__ < 2)
32
#error Only GNU C versions later than 4.3.2 are supported
33
#endif
34
#endif
35
#endif // __GNUC__
36
37
38
#ifndef DOXYGEN_SHOULD_SKIP_THIS
39
//#include <intrinsics.h>
40
#include <stdarg.h>
41
#if defined (CORTEXM3_STM32W108)
42
#include "micro/cortexm3/stm32w108/regs.h"
43
#include "micro/cortexm3/stm32w108/stm32w108_type.h"
44
#else
45
#error Unknown CORTEXM3 micro
46
#endif
47
//Provide a default NVIC configuration file. The build process can
48
//override this if it needs to.
49
#ifndef NVIC_CONFIG
50
#define NVIC_CONFIG "hal/micro/cortexm3/nvic-config.h"
51
#endif
52
//[[
53
#ifdef EMU_TEST
54
#ifdef I_AM_AN_EMULATOR
55
// This register is defined for both the chip and the emulator with
56
// with distinct reset values. Need to undefine to avoid preprocessor
57
// collision.
58
#undef DATA_EMU_REGS_BASE
59
#undef DATA_EMU_REGS_END
60
#undef DATA_EMU_REGS_SIZE
61
#undef I_AM_AN_EMULATOR
62
#undef I_AM_AN_EMULATOR_REG
63
#undef I_AM_AN_EMULATOR_ADDR
64
#undef I_AM_AN_EMULATOR_RESET
65
#undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR
66
#undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_MASK
67
#undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BIT
68
#undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BITS
69
#endif//I_AM_AN_EMULATOR
70
#error MICRO currently not supported for emulator builds.
71
#endif//EMU_TEST
72
//]]
73
74
// suppress warnings about unknown pragmas
75
// (as they may be pragmas known to other platforms)
76
//#pragma diag_suppress = pe161
77
78
#endif // DOXYGEN_SHOULD_SKIP_THIS
79
80
// Define that the minimal hal is being used.
81
#define MINIMAL_HAL
82
83
84
/** \name Master Variable Types
85
* These are a set of typedefs to make the size of all variable declarations
86
* explicitly known.
87
*/
88
//@{
89
/**
90
* @brief A typedef to make the size of the variable explicitly known.
91
*/
92
typedef
unsigned
char
boolean
;
93
typedef
unsigned
char
int8u;
94
typedef
signed
char
int8s;
95
typedef
unsigned
short
int16u;
96
typedef
signed
short
int16s;
97
typedef
unsigned
int
int32u;
98
typedef
signed
int
int32s;
99
typedef
unsigned
int
PointerType;
100
//@} \\END MASTER VARIABLE TYPES
101
102
/**
103
* @brief Use the Master Program Memory Declarations from platform-common.h
104
*/
105
#define _HAL_USE_COMMON_PGM_
106
107
108
109
////////////////////////////////////////////////////////////////////////////////
110
/** \name Miscellaneous Macros
111
*/
112
////////////////////////////////////////////////////////////////////////////////
113
//@{
114
115
/**
116
* @brief A convenient method for code to know what endiannes processor
117
* it is running on. For the Cortex-M3, we are little endian.
118
*/
119
#define BIGENDIAN_CPU FALSE
120
121
122
/**
123
* @brief A friendlier name for the compiler's intrinsic for not
124
* stripping.
125
*/
126
#define NO_STRIPPING
/* __root ??? */
127
#define __no_init
/*__attribute__((section (".noinit")))*/
128
129
/**
130
* @brief A friendlier name for the compiler's intrinsic for eeprom
131
* reference.
132
*/
133
#define EEPROM errorerror
134
135
136
#ifndef __SOURCEFILE__
137
/**
138
* @brief The __SOURCEFILE__ macro is used by asserts to list the
139
* filename if it isn't otherwise defined, set it to the compiler intrinsic
140
* which specifies the whole filename and path of the sourcefile
141
*/
142
#define __SOURCEFILE__ __FILE__
143
#endif
144
145
146
//#include <assert.h>
147
#undef assert
148
#define assert(condition) do { if (! (condition)) {while (1); }} while(0)
149
#if 0
150
do
{
if
(! (condition)) { \
151
printf (
"Assert failed %s %d\r\n"
,
__SOURCEFILE__
, __LINE__); }}
while
(0)
152
#endif
153
154
#ifndef BOOTLOADER
155
#undef __delay_cycles
156
/**
157
* @brief __delay_cycles() is an intrinsic IAR call; however, we
158
* have explicity disallowed it since it is too specific to the system clock.
159
* \note Please use halCommonDelayMicroseconds() instead, because it correctly
160
* accounts for various system clock speeds.
161
*/
162
#define __delay_cycles(x) please_use_halCommonDelayMicroseconds_instead_of_delay_cycles
163
#endif
164
165
/**
166
* @brief Set debug level based on whether or DEBUG is defined.
167
* basic debugging support is included if DEBUG is not defined.
168
*/
169
#ifndef DEBUG_LEVEL
170
#ifdef DEBUG
171
#define DEBUG_LEVEL FULL_DEBUG
172
#else
173
#define DEBUG_LEVEL BASIC_DEBUG
174
#endif
175
#endif
176
177
/**
178
* @brief Set the application start and end address.
179
* This are useful to detect whether an image is for bootloader mode or not.
180
* This can be used also to clone image to another node via bootloader.
181
*/
182
#define APPLICATION_IMAGE_START ((u32) &__ApplicationFlashStart)
183
#define APPLICATION_IMAGE_END ((u32) &__ApplicationFlashEnd)
184
extern
char
__ApplicationFlashStart;
185
extern
char
__ApplicationFlashEnd;
186
187
/**
188
* @brief Macro to reset the watchdog timer. Note: be very very
189
* careful when using this as you can easily get into an infinite loop if you
190
* are not careful.
191
*/
192
void
halInternalResetWatchDog
(
void
);
193
#define halResetWatchdog() halInternalResetWatchDog()
194
195
196
/**
197
* @brief Define __attribute__ to nothing since it isn't handled by IAR.
198
*/
199
200
201
/**
202
* @brief Declare a variable as unused to avoid a warning. Has no effect
203
* in IAR builds
204
*/
205
#define UNUSED
206
207
/**
208
* @brief Some platforms need to cast enum values that have the high bit set.
209
*/
210
#define SIGNED_ENUM
211
212
213
/**
214
* @brief Define the magic value that is interpreted by IAR C-SPY's Stack View.
215
*/
216
#define STACK_FILL_VALUE 0xCDCDCDCD
217
218
/**
219
* @brief Define a generic RAM function identifier to a compiler specific one.
220
*/
221
#ifdef RAMEXE
222
//If the whole build is running out of RAM, as chosen by the RAMEXE build
223
//define, then define RAMFUNC to nothing since it's not needed.
224
#define RAMFUNC
225
#else //RAMEXE
226
#define RAMFUNC __ramfunc
227
#endif //RAMEXE
228
229
/**
230
* @brief Define a generic no operation identifier to a compiler specific one.
231
*/
232
#define NO_OPERATION() __no_operation()
233
234
/**
235
* @brief A convenience macro that makes it easy to change the field of a
236
* register to any value.
237
*/
238
#define SET_REG_FIELD(reg, field, value) \
239
do{ \
240
reg = ((reg & (~field##_MASK)) | (value << field##_BIT)); \
241
}while(0)
242
243
/**
244
* @brief Stub for code not running in simulation.
245
*/
246
#define simulatedTimePasses()
247
/**
248
* @brief Stub for code not running in simulation.
249
*/
250
#define simulatedTimePassesMs(x)
251
/**
252
* @brief Stub for code not running in simulation.
253
*/
254
#define simulatedSerialTimePasses()
255
256
257
/**
258
* @brief Use the Divide and Modulus Operations from platform-common.h
259
*/
260
#define _HAL_USE_COMMON_DIVMOD_
261
262
263
/**
264
* @brief Provide a portable way to specify the segment where a variable
265
* lives.
266
*/
267
#define VAR_AT_SEGMENT(__variableDeclaration, __segmentName) \
268
__variableDeclaration __attribute__ ((section (__segmentName)))
269
270
#define ALIGN_VAR(__variableDeclaration, alignment) \
271
__variableDeclaration __attribute__ ((aligned(alignment)))
272
273
////////////////////////////////////////////////////////////////////////////////
274
//@} // end of Miscellaneous Macros
275
////////////////////////////////////////////////////////////////////////////////
276
277
/** @name Portable segment names
278
*@{
279
*/
280
/**
281
* @brief Portable segment names
282
*/
283
#define __NO_INIT__ ".noinit"
284
#define __INTVEC__ ".intvec"
285
#define __CSTACK__ "CSTACK"
286
#define __DATA_INIT__ ".data_init"
287
#define __DATA__ ".data"
288
#define __BSS__ ".bss"
289
#define __CONST__ ".rodata"
290
#define __TEXT__ ".text"
291
#define __TEXTRW_INIT__ ".textrw_init"
292
#define __TEXTRW__ ".textrw"
293
#define __FAT__ "FAT" // Fixed address table
294
#define __NVM__ "NVM" //Non-Volatile Memory data storage
295
296
//=============================================================================
297
// The '#pragma segment=' declaration must be used before attempting to access
298
// the segments so the compiler properly handles the __segment_*() functions.
299
//
300
// The segment names used here are the default segment names used by IAR. Refer
301
// to the IAR Compiler Reference Guide for a proper description of these
302
// segments.
303
//=============================================================================
304
#if 0
305
#pragma segment=__NO_INIT__
306
#pragma segment=__INTVEC__
307
#pragma segment=__CSTACK__
308
#pragma segment=__DATA_INIT__
309
#pragma segment=__DATA__
310
#pragma segment=__BSS__
311
#pragma segment=__CONST__
312
#pragma segment=__TEXT__
313
#pragma segment=__TEXTRW_INIT__
314
#pragma segment=__TEXTRW__
315
#pragma segment=__FAT__
316
#pragma segment=__NVM__
317
#endif
318
/**@} */
319
320
//A utility function for inserting barrier instructions. These
321
//instructions should be used whenever the MPU is enabled or disabled so
322
//that all memory/instruction accesses can complete before the MPU changes
323
//state.
324
void
_executeBarrierInstructions(
void
);
325
326
////////////////////////////////////////////////////////////////////////////////
327
/** \name Global Interrupt Manipulation Macros
328
*
329
* \b Note: The special purpose BASEPRI register is used to enable and disable
330
* interrupts while permitting faults.
331
* When BASEPRI is set to 1 no interrupts can trigger. The configurable faults
332
* (usage, memory management, and bus faults) can trigger if enabled as well as
333
* the always-enabled exceptions (reset, NMI and hard fault).
334
* When BASEPRI is set to 0, it is disabled, so any interrupt can triggger if
335
* its priority is higher than the current priority.
336
*/
337
////////////////////////////////////////////////////////////////////////////////
338
//@{
339
340
#define ATOMIC_LITE(blah) ATOMIC(blah)
341
#define DECLARE_INTERRUPT_STATE_LITE DECLARE_INTERRUPT_STATE
342
#define DISABLE_INTERRUPTS_LITE() DISABLE_INTERRUPTS()
343
#define RESTORE_INTERRUPTS_LITE() RESTORE_INTERRUPTS()
344
345
#ifdef BOOTLOADER
346
#ifndef DOXYGEN_SHOULD_SKIP_THIS
347
// The bootloader does not use interrupts
348
#define DECLARE_INTERRUPT_STATE
349
#define DISABLE_INTERRUPTS() do { } while(0)
350
#define RESTORE_INTERRUPTS() do { } while(0)
351
#define INTERRUPTS_ON() do { } while(0)
352
#define INTERRUPTS_OFF() do { } while(0)
353
#define INTERRUPTS_ARE_OFF() (FALSE)
354
#define ATOMIC(blah) { blah }
355
#define HANDLE_PENDING_INTERRUPTS() do { } while(0)
356
#define SET_BASE_PRIORITY_LEVEL(basepri) do { } while(0)
357
#endif // DOXYGEN_SHOULD_SKIP_THIS
358
#else // BOOTLOADER
359
360
#ifndef DOXYGEN_SHOULD_SKIP_THIS
361
/**
362
* @brief This macro should be called in the local variable
363
* declarations section of any function which calls DISABLE_INTERRUPTS()
364
* or RESTORE_INTERRUPTS().
365
*/
366
#define DECLARE_INTERRUPT_STATE int8u _emIsrState
367
368
// Prototypes for the BASEPRI and PRIMASK access functions. They are very
369
// basic and instantiated in assembly code in the file spmr.s37 (since
370
// there are no C functions that cause the compiler to emit code to access
371
// the BASEPRI/PRIMASK). This will inhibit the core from taking interrupts
372
// with a priority equal to or less than the BASEPRI value.
373
// Note that the priority values used by these functions are 5 bits and
374
// right-aligned
375
extern
int8u _readBasePri(
void
);
376
extern
void
_writeBasePri(int8u priority);
377
378
// Prototypes for BASEPRI functions used to disable and enable interrupts
379
// while still allowing enabled faults to trigger.
380
extern
void
_enableBasePri(
void
);
381
extern
int8u _disableBasePri(
void
);
382
extern
boolean
_basePriIsDisabled(
void
);
383
384
// Prototypes for setting and clearing PRIMASK for global interrupt
385
// enable/disable.
386
extern
void
_setPriMask(
void
);
387
extern
void
_clearPriMask(
void
);
388
#endif // DOXYGEN_SHOULD_SKIP_THIS
389
390
//The core Global Interrupt Manipulation Macros start here.
391
392
/**
393
* @brief Disable interrupts, saving the previous state so it can be
394
* later restored with RESTORE_INTERRUPTS().
395
* \note Do not fail to call RESTORE_INTERRUPTS().
396
* \note It is safe to nest this call.
397
*/
398
#define DISABLE_INTERRUPTS() \
399
do { \
400
_emIsrState = _disableBasePri(); \
401
} while(0)
402
403
404
/**
405
* @brief Restore the global interrupt state previously saved by
406
* DISABLE_INTERRUPTS()
407
* \note Do not call without having first called DISABLE_INTERRUPTS()
408
* to have saved the state.
409
* \note It is safe to nest this call.
410
*/
411
#define RESTORE_INTERRUPTS() \
412
do { \
413
_writeBasePri(_emIsrState); \
414
} while(0)
415
416
417
/**
418
* @brief Enable global interrupts without regard to the current or
419
* previous state.
420
*/
421
#define INTERRUPTS_ON() \
422
do { \
423
_enableBasePri(); \
424
} while(0)
425
426
427
/**
428
* @brief Disable global interrupts without regard to the current or
429
* previous state.
430
*/
431
#define INTERRUPTS_OFF() \
432
do { \
433
(void)_disableBasePri(); \
434
} while(0)
435
436
437
/**
438
* @returns TRUE if global interrupts are disabled.
439
*/
440
#define INTERRUPTS_ARE_OFF() ( _basePriIsDisabled() )
441
442
/**
443
* @returns TRUE if global interrupt flag was enabled when
444
* ::DISABLE_INTERRUPTS() was called.
445
*/
446
#define INTERRUPTS_WERE_ON() (_emIsrState == 0)
447
448
/**
449
* @brief A block of code may be made atomic by wrapping it with this
450
* macro. Something which is atomic cannot be interrupted by interrupts.
451
*/
452
#define ATOMIC(blah) \
453
{ \
454
DECLARE_INTERRUPT_STATE; \
455
DISABLE_INTERRUPTS(); \
456
{ blah } \
457
RESTORE_INTERRUPTS(); \
458
}
459
460
461
/**
462
* @brief Allows any pending interrupts to be executed. Usually this
463
* would be called at a safe point while interrupts are disabled (such as
464
* within an ISR).
465
*
466
* Takes no action if interrupts are already enabled.
467
*/
468
#define HANDLE_PENDING_INTERRUPTS() \
469
do { \
470
if (INTERRUPTS_ARE_OFF()) { \
471
INTERRUPTS_ON(); \
472
INTERRUPTS_OFF(); \
473
} \
474
} while (0)
475
476
477
/**
478
* @brief Sets the base priority mask (BASEPRI) to the value passed,
479
* bit shifted up by PRIGROUP_POSITION+1. This will inhibit the core from
480
* taking all interrupts with a preemptive priority equal to or less than
481
* the BASEPRI mask. This macro is dependent on the value of
482
* PRIGROUP_POSITION in nvic-config.h. Note that the value 0 disables the
483
* the base priority mask.
484
*
485
* Refer to the "PRIGROUP" table in nvic-config.h to know the valid values
486
* for this macro depending on the value of PRIGROUP_POSITION. With respect
487
* to the table, this macro can only take the preemptive priority group
488
* numbers denoted by the parenthesis.
489
*/
490
#define SET_BASE_PRIORITY_LEVEL(basepri) \
491
do { \
492
_writeBasePri(basepri); \
493
} while(0)
494
495
#endif // BOOTLOADER
496
////////////////////////////////////////////////////////////////////////////////
497
//@} // end of Global Interrupt Manipulation Macros
498
////////////////////////////////////////////////////////////////////////////////
499
500
/**
501
* @brief Use the C Standard Library Memory Utilities from platform-common.h
502
*/
503
#define _HAL_USE_COMMON_MEMUTILS_
504
505
////////////////////////////////////////////////////////////////////////////////
506
/** \name External Declarations
507
* These are routines that are defined in certain header files that we don't
508
* want to include, e.g. stdlib.h
509
*/
510
////////////////////////////////////////////////////////////////////////////////
511
//@{
512
513
/**
514
* @brief Returns the absolute value of I (also called the magnitude of I).
515
* That is, if I is negative, the result is the opposite of I, but if I is
516
* nonnegative the result is I.
517
*
518
* @param I An integer.
519
*
520
* @return A nonnegative integer.
521
*/
522
int
abs
(
int
I);
523
524
////////////////////////////////////////////////////////////////////////////////
525
//@} // end of External Declarations
526
////////////////////////////////////////////////////////////////////////////////
527
528
529
/**
530
* @brief Include platform-common.h last to pick up defaults and common definitions.
531
*/
532
#define PLATCOMMONOKTOINCLUDE
533
#include "
hal/micro/generic/compiler/platform-common.h
"
534
#undef PLATCOMMONOKTOINCLUDE
535
536
#endif // __GNU_H__
537
538
/** @} END addtogroup */
539
Generated on Fri Aug 30 2013 12:34:09 for Contiki 2.5 by
1.8.3.1