Contiki 3.x
iar.h
Go to the documentation of this file.
1 /** @file hal/micro/cortexm3/compiler/iar.h
2  * @brief iar for detailed documentation.
3  *
4  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
5  */
6 
7 /**
8  * @addtogroup stm32w-cpu
9  * @{ */
10 
11 /** @defgroup iar
12  * @brief Compiler and Platform specific definitions and typedefs for the
13  * IAR ARM C compiler.
14  *
15  * @note iar.h should be included first in all source files by setting the
16  * preprocessor macro PLATFORM_HEADER to point to it. iar.h automatically
17  * includes platform-common.h.
18  *
19  * See iar.h and platform-common.h for source code.
20  *@{
21  */
22 
23 #ifndef IAR_H_
24 #define IAR_H_
25 
26 #ifndef __ICCARM__
27  #error Improper PLATFORM_HEADER
28 #endif
29 
30 #if (__VER__ < 5040005)
31  #error Only IAR EWARM versions later than 5.40.5 are supported
32 #endif // __VER__
33 
34 
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36  #include <intrinsics.h>
37  #include <stdarg.h>
38  #if defined (CORTEXM3_STM32W108)
39  #include "micro/cortexm3/stm32w108/regs.h"
40  #include "micro/cortexm3/stm32w108/stm32w108-type.h"
41  #elif defined (CORTEXM3_STM32F103)
42  #include "stm32f10x.h"
43  #else
44  #error Unknown CORTEXM3 micro
45  #endif
46  //Provide a default NVIC configuration file. The build process can
47  //override this if it needs to.
48  #ifndef NVIC_CONFIG
49  #define NVIC_CONFIG "hal/micro/cortexm3/nvic-config.h"
50  #endif
51 //[[
52 #ifdef ST_EMU_TEST
53  #ifdef I_AM_AN_EMULATOR
54  // This register is defined for both the chip and the emulator with
55  // with distinct reset values. Need to undefine to avoid preprocessor
56  // collision.
57  #undef DATA_EMU_REGS_BASE
58  #undef DATA_EMU_REGS_END
59  #undef DATA_EMU_REGS_SIZE
60  #undef I_AM_AN_EMULATOR
61  #undef I_AM_AN_EMULATOR_REG
62  #undef I_AM_AN_EMULATOR_ADDR
63  #undef I_AM_AN_EMULATOR_RESET
64  #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR
65  #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_MASK
66  #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BIT
67  #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BITS
68  #endif//I_AM_AN_EMULATOR
69 
70  #error MICRO currently not supported for emulator builds.
71 
72 #endif//ST_EMU_TEST
73 //]]
74 
75 // suppress warnings about unknown pragmas
76 // (as they may be pragmas known to other platforms)
77 #pragma diag_suppress = pe161
78 
79 #endif // DOXYGEN_SHOULD_SKIP_THIS
80 
81 // Define that the minimal hal is being used.
82 #define MINIMAL_HAL
83 
84 
85 /** \name Master Variable Types
86  * These are a set of typedefs to make the size of all variable declarations
87  * explicitly known.
88  */
89 //@{
90 /**
91  * @brief A typedef to make the size of the variable explicitly known.
92  */
93 typedef unsigned char boolean;
94 typedef unsigned char uint8_t;
95 typedef signed char int8_t;
96 typedef unsigned short uint16_t;
97 typedef signed short int16_t;
98 typedef unsigned int uint32_t;
99 typedef signed int int32_t;
100 typedef unsigned int PointerType;
101 //@} \\END MASTER VARIABLE TYPES
102 
103 /**
104  * @brief Use the Master Program Memory Declarations from platform-common.h
105  */
106 #define _HAL_USE_COMMON_PGM_
107 
108 
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /** \name Miscellaneous Macros
112  */
113 ////////////////////////////////////////////////////////////////////////////////
114 //@{
115 
116 /**
117  * @brief A convenient method for code to know what endiannes processor
118  * it is running on. For the Cortex-M3, we are little endian.
119  */
120 #define BIGENDIAN_CPU FALSE
121 
122 
123 /**
124  * @brief A friendlier name for the compiler's intrinsic for not
125  * stripping.
126  */
127 #define NO_STRIPPING __root
128 
129 
130 /**
131  * @brief A friendlier name for the compiler's intrinsic for eeprom
132  * reference.
133  */
134 #define EEPROM errorerror
135 
136 
137 #ifndef __SOURCEFILE__
138  /**
139  * @brief The __SOURCEFILE__ macro is used by asserts to list the
140  * filename if it isn't otherwise defined, set it to the compiler intrinsic
141  * which specifies the whole filename and path of the sourcefile
142  */
143  #define __SOURCEFILE__ __FILE__
144 #endif
145 
146 
147 #include <assert.h>
148 
149 
150 #ifndef BOOTLOADER
151  #undef __delay_cycles
152  /**
153  * @brief __delay_cycles() is an intrinsic IAR call; however, we
154  * have explicity disallowed it since it is too specific to the system clock.
155  * \note Please use halCommonDelayMicroseconds() instead, because it correctly
156  * accounts for various system clock speeds.
157  */
158  #define __delay_cycles(x) please_use_halCommonDelayMicroseconds_instead_of_delay_cycles
159 #endif
160 
161 /**
162  * @brief Set debug level based on whether or DEBUG is defined.
163  * For the STM32W108xx, basic debugging support is included if DEBUG is not defined.
164  */
165 #ifndef DEBUG_LEVEL
166  #ifdef DEBUG
167  #define DEBUG_LEVEL FULL_DEBUG
168  #else
169  #define DEBUG_LEVEL BASIC_DEBUG
170  #endif
171 #endif
172 
173 /**
174  * @brief Set the application start and end address.
175  * This are useful to detect whether an image is for bootloader mode or not.
176  * This can be used also to clone image to another node via bootloader.
177  */
178 #define APPLICATION_IMAGE_START ((u32) __section_begin("FLASH_IMAGE"))
179 #define APPLICATION_IMAGE_END ((u32) __section_end ("FLASH_IMAGE"))
180 
181 
182 /**
183  * @brief Macro to reset the watchdog timer. Note: be very very
184  * careful when using this as you can easily get into an infinite loop if you
185  * are not careful.
186  */
187 void halInternalResetWatchDog(void);
188 #define halResetWatchdog() halInternalResetWatchDog()
189 
190 
191 /**
192  * @brief Define __attribute__ to nothing since it isn't handled by IAR.
193  */
194 #define __attribute__(nothing)
195 
196 
197 /**
198  * @brief Declare a variable as unused to avoid a warning. Has no effect
199  * in IAR builds
200  */
201 #define UNUSED
202 
203 /**
204  * @brief Some platforms need to cast enum values that have the high bit set.
205  */
206 #define SIGNED_ENUM
207 
208 
209 /**
210  * @brief Define the magic value that is interpreted by IAR C-SPY's Stack View.
211  */
212 #define STACK_FILL_VALUE 0xCDCDCDCD
213 
214 /**
215  * @brief Define a generic RAM function identifier to a compiler specific one.
216  */
217 #ifdef RAMEXE
218  //If the whole build is running out of RAM, as chosen by the RAMEXE build
219  //define, then define RAMFUNC to nothing since it's not needed.
220  #define RAMFUNC
221 #else //RAMEXE
222  #define RAMFUNC __ramfunc
223 #endif //RAMEXE
224 
225 /**
226  * @brief Define a generic no operation identifier to a compiler specific one.
227  */
228 #define NO_OPERATION() __no_operation()
229 
230 /**
231  * @brief A convenience macro that makes it easy to change the field of a
232  * register to any value.
233  */
234 #define SET_REG_FIELD(reg, field, value) \
235  do{ \
236  reg = ((reg & (~field##_MASK)) | (value << field##_BIT)); \
237  }while(0)
238 
239 /**
240  * @brief Stub for code not running in simulation.
241  */
242 #define simulatedTimePasses()
243 /**
244  * @brief Stub for code not running in simulation.
245  */
246 #define simulatedTimePassesMs(x)
247 /**
248  * @brief Stub for code not running in simulation.
249  */
250 #define simulatedSerialTimePasses()
251 
252 
253 /**
254  * @brief Use the Divide and Modulus Operations from platform-common.h
255  */
256 #define _HAL_USE_COMMON_DIVMOD_
257 
258 
259 /**
260  * @brief Provide a portable way to specify the segment where a variable
261  * lives.
262  */
263 #define VAR_AT_SEGMENT(__variableDeclaration, __segmentName) \
264  __variableDeclaration @ __segmentName
265 
266 #define _QUOTEME(a) #a
267 #define QUOTEME(a) _QUOTEME(a)
268 #define ALIGN_VAR(__variableDeclaration, alignment) _Pragma(QUOTEME(data_alignment=alignment)) \
269  __variableDeclaration
270 
271 ////////////////////////////////////////////////////////////////////////////////
272 //@} // end of Miscellaneous Macros
273 ////////////////////////////////////////////////////////////////////////////////
274 
275 /** @name Portable segment names
276  *@{
277  */
278 /**
279  * @brief Portable segment names
280  */
281 #define __NO_INIT__ ".noinit"
282 #define __INTVEC__ ".intvec"
283 #define __CSTACK__ "CSTACK"
284 #define __DATA_INIT__ ".data_init"
285 #define __DATA__ ".data"
286 #define __BSS__ ".bss"
287 #define __CONST__ ".rodata"
288 #define __TEXT__ ".text"
289 #define __TEXTRW_INIT__ ".textrw_init"
290 #define __TEXTRW__ ".textrw"
291 #define __FAT__ "FAT" // Fixed address table
292 #define __NVM__ "NVM" //Non-Volatile Memory data storage
293 
294 //=============================================================================
295 // The '#pragma segment=' declaration must be used before attempting to access
296 // the segments so the compiler properly handles the __segment_*() functions.
297 //
298 // The segment names used here are the default segment names used by IAR. Refer
299 // to the IAR Compiler Reference Guide for a proper description of these
300 // segments.
301 //=============================================================================
302 #pragma segment=__NO_INIT__
303 #pragma segment=__INTVEC__
304 #pragma segment=__CSTACK__
305 #pragma segment=__DATA_INIT__
306 #pragma segment=__DATA__
307 #pragma segment=__BSS__
308 #pragma segment=__CONST__
309 #pragma segment=__TEXT__
310 #pragma segment=__TEXTRW_INIT__
311 #pragma segment=__TEXTRW__
312 #pragma segment=__FAT__
313 #pragma segment=__NVM__
314 // Special pragma to get the application image start and end address
315 #pragma segment="FLASH_IMAGE"
316 /**@} */
317 
318 //A utility function for inserting barrier instructions. These
319 //instructions should be used whenever the MPU is enabled or disabled so
320 //that all memory/instruction accesses can complete before the MPU changes
321 //state.
322 void _executeBarrierInstructions(void);
323 // MPU is unused with this platform header variant
324 #define _HAL_MPU_UNUSED_
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 uint8_t _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 uint8_t _readBasePri(void);
376  extern void _writeBasePri(uint8_t 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 uint8_t _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
534 #undef PLATCOMMONOKTOINCLUDE
535 
536 #endif // IAR_H_
537 
538 /** @} END addtogroup */
539 /** @} */
540 
int abs(int I)
Returns the absolute value of I (also called the magnitude of I).
See platform_common for detailed documentation.
void halInternalResetWatchDog(void)
Resets the watchdog timer.
Definition: micro-common.c:25