Contiki 2.6
|
00001 /** @file hal/micro/cortexm3/compiler/iar.h 00002 * @brief iar for detailed documentation. 00003 * 00004 * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. --> 00005 */ 00006 00007 /** @addtogroup iar 00008 * @brief Compiler and Platform specific definitions and typedefs for the 00009 * IAR ARM C compiler. 00010 * 00011 * @note iar.h should be included first in all source files by setting the 00012 * preprocessor macro PLATFORM_HEADER to point to it. iar.h automatically 00013 * includes platform-common.h. 00014 * 00015 * See iar.h and platform-common.h for source code. 00016 *@{ 00017 */ 00018 00019 #ifndef __IAR_H__ 00020 #define __IAR_H__ 00021 00022 #ifndef __ICCARM__ 00023 #error Improper PLATFORM_HEADER 00024 #endif 00025 00026 #if (__VER__ < 5040005) 00027 #error Only IAR EWARM versions later than 5.40.5 are supported 00028 #endif // __VER__ 00029 00030 00031 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00032 #include <intrinsics.h> 00033 #include <stdarg.h> 00034 #if defined (CORTEXM3_STM32W108) 00035 #include "micro/cortexm3/stm32w108/regs.h" 00036 #include "micro/cortexm3/stm32w108/stm32w108_type.h" 00037 #elif defined (CORTEXM3_STM32F103) 00038 #include "stm32f10x.h" 00039 #else 00040 #error Unknown CORTEXM3 micro 00041 #endif 00042 //Provide a default NVIC configuration file. The build process can 00043 //override this if it needs to. 00044 #ifndef NVIC_CONFIG 00045 #define NVIC_CONFIG "hal/micro/cortexm3/nvic-config.h" 00046 #endif 00047 //[[ 00048 #ifdef ST_EMU_TEST 00049 #ifdef I_AM_AN_EMULATOR 00050 // This register is defined for both the chip and the emulator with 00051 // with distinct reset values. Need to undefine to avoid preprocessor 00052 // collision. 00053 #undef DATA_EMU_REGS_BASE 00054 #undef DATA_EMU_REGS_END 00055 #undef DATA_EMU_REGS_SIZE 00056 #undef I_AM_AN_EMULATOR 00057 #undef I_AM_AN_EMULATOR_REG 00058 #undef I_AM_AN_EMULATOR_ADDR 00059 #undef I_AM_AN_EMULATOR_RESET 00060 #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR 00061 #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_MASK 00062 #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BIT 00063 #undef I_AM_AN_EMULATOR_I_AM_AN_EMULATOR_BITS 00064 #endif//I_AM_AN_EMULATOR 00065 00066 #error MICRO currently not supported for emulator builds. 00067 00068 #endif//ST_EMU_TEST 00069 //]] 00070 00071 // suppress warnings about unknown pragmas 00072 // (as they may be pragmas known to other platforms) 00073 #pragma diag_suppress = pe161 00074 00075 #endif // DOXYGEN_SHOULD_SKIP_THIS 00076 00077 // Define that the minimal hal is being used. 00078 #define MINIMAL_HAL 00079 00080 00081 /** \name Master Variable Types 00082 * These are a set of typedefs to make the size of all variable declarations 00083 * explicitly known. 00084 */ 00085 //@{ 00086 /** 00087 * @brief A typedef to make the size of the variable explicitly known. 00088 */ 00089 typedef unsigned char boolean; 00090 typedef unsigned char int8u; 00091 typedef signed char int8s; 00092 typedef unsigned short int16u; 00093 typedef signed short int16s; 00094 typedef unsigned int int32u; 00095 typedef signed int int32s; 00096 typedef unsigned int PointerType; 00097 //@} \\END MASTER VARIABLE TYPES 00098 00099 /** 00100 * @brief Use the Master Program Memory Declarations from platform-common.h 00101 */ 00102 #define _HAL_USE_COMMON_PGM_ 00103 00104 00105 00106 //////////////////////////////////////////////////////////////////////////////// 00107 /** \name Miscellaneous Macros 00108 */ 00109 //////////////////////////////////////////////////////////////////////////////// 00110 //@{ 00111 00112 /** 00113 * @brief A convenient method for code to know what endiannes processor 00114 * it is running on. For the Cortex-M3, we are little endian. 00115 */ 00116 #define BIGENDIAN_CPU FALSE 00117 00118 00119 /** 00120 * @brief A friendlier name for the compiler's intrinsic for not 00121 * stripping. 00122 */ 00123 #define NO_STRIPPING __root 00124 00125 00126 /** 00127 * @brief A friendlier name for the compiler's intrinsic for eeprom 00128 * reference. 00129 */ 00130 #define EEPROM errorerror 00131 00132 00133 #ifndef __SOURCEFILE__ 00134 /** 00135 * @brief The __SOURCEFILE__ macro is used by asserts to list the 00136 * filename if it isn't otherwise defined, set it to the compiler intrinsic 00137 * which specifies the whole filename and path of the sourcefile 00138 */ 00139 #define __SOURCEFILE__ __FILE__ 00140 #endif 00141 00142 00143 #include <assert.h> 00144 00145 00146 #ifndef BOOTLOADER 00147 #undef __delay_cycles 00148 /** 00149 * @brief __delay_cycles() is an intrinsic IAR call; however, we 00150 * have explicity disallowed it since it is too specific to the system clock. 00151 * \note Please use halCommonDelayMicroseconds() instead, because it correctly 00152 * accounts for various system clock speeds. 00153 */ 00154 #define __delay_cycles(x) please_use_halCommonDelayMicroseconds_instead_of_delay_cycles 00155 #endif 00156 00157 /** 00158 * @brief Set debug level based on whether or DEBUG is defined. 00159 * For the STM32W108xx, basic debugging support is included if DEBUG is not defined. 00160 */ 00161 #ifndef DEBUG_LEVEL 00162 #ifdef DEBUG 00163 #define DEBUG_LEVEL FULL_DEBUG 00164 #else 00165 #define DEBUG_LEVEL BASIC_DEBUG 00166 #endif 00167 #endif 00168 00169 /** 00170 * @brief Set the application start and end address. 00171 * This are useful to detect whether an image is for bootloader mode or not. 00172 * This can be used also to clone image to another node via bootloader. 00173 */ 00174 #define APPLICATION_IMAGE_START ((u32) __section_begin("FLASH_IMAGE")) 00175 #define APPLICATION_IMAGE_END ((u32) __section_end ("FLASH_IMAGE")) 00176 00177 00178 /** 00179 * @brief Macro to reset the watchdog timer. Note: be very very 00180 * careful when using this as you can easily get into an infinite loop if you 00181 * are not careful. 00182 */ 00183 void halInternalResetWatchDog(void); 00184 #define halResetWatchdog() halInternalResetWatchDog() 00185 00186 00187 /** 00188 * @brief Define __attribute__ to nothing since it isn't handled by IAR. 00189 */ 00190 #define __attribute__(nothing) 00191 00192 00193 /** 00194 * @brief Declare a variable as unused to avoid a warning. Has no effect 00195 * in IAR builds 00196 */ 00197 #define UNUSED 00198 00199 /** 00200 * @brief Some platforms need to cast enum values that have the high bit set. 00201 */ 00202 #define SIGNED_ENUM 00203 00204 00205 /** 00206 * @brief Define the magic value that is interpreted by IAR C-SPY's Stack View. 00207 */ 00208 #define STACK_FILL_VALUE 0xCDCDCDCD 00209 00210 /** 00211 * @brief Define a generic RAM function identifier to a compiler specific one. 00212 */ 00213 #ifdef RAMEXE 00214 //If the whole build is running out of RAM, as chosen by the RAMEXE build 00215 //define, then define RAMFUNC to nothing since it's not needed. 00216 #define RAMFUNC 00217 #else //RAMEXE 00218 #define RAMFUNC __ramfunc 00219 #endif //RAMEXE 00220 00221 /** 00222 * @brief Define a generic no operation identifier to a compiler specific one. 00223 */ 00224 #define NO_OPERATION() __no_operation() 00225 00226 /** 00227 * @brief A convenience macro that makes it easy to change the field of a 00228 * register to any value. 00229 */ 00230 #define SET_REG_FIELD(reg, field, value) \ 00231 do{ \ 00232 reg = ((reg & (~field##_MASK)) | (value << field##_BIT)); \ 00233 }while(0) 00234 00235 /** 00236 * @brief Stub for code not running in simulation. 00237 */ 00238 #define simulatedTimePasses() 00239 /** 00240 * @brief Stub for code not running in simulation. 00241 */ 00242 #define simulatedTimePassesMs(x) 00243 /** 00244 * @brief Stub for code not running in simulation. 00245 */ 00246 #define simulatedSerialTimePasses() 00247 00248 00249 /** 00250 * @brief Use the Divide and Modulus Operations from platform-common.h 00251 */ 00252 #define _HAL_USE_COMMON_DIVMOD_ 00253 00254 00255 /** 00256 * @brief Provide a portable way to specify the segment where a variable 00257 * lives. 00258 */ 00259 #define VAR_AT_SEGMENT(__variableDeclaration, __segmentName) \ 00260 __variableDeclaration @ __segmentName 00261 00262 #define _QUOTEME(a) #a 00263 #define QUOTEME(a) _QUOTEME(a) 00264 #define ALIGN_VAR(__variableDeclaration, alignment) _Pragma(QUOTEME(data_alignment=alignment)) \ 00265 __variableDeclaration 00266 00267 //////////////////////////////////////////////////////////////////////////////// 00268 //@} // end of Miscellaneous Macros 00269 //////////////////////////////////////////////////////////////////////////////// 00270 00271 /** @name Portable segment names 00272 *@{ 00273 */ 00274 /** 00275 * @brief Portable segment names 00276 */ 00277 #define __NO_INIT__ ".noinit" 00278 #define __INTVEC__ ".intvec" 00279 #define __CSTACK__ "CSTACK" 00280 #define __DATA_INIT__ ".data_init" 00281 #define __DATA__ ".data" 00282 #define __BSS__ ".bss" 00283 #define __CONST__ ".rodata" 00284 #define __TEXT__ ".text" 00285 #define __TEXTRW_INIT__ ".textrw_init" 00286 #define __TEXTRW__ ".textrw" 00287 #define __FAT__ "FAT" // Fixed address table 00288 #define __NVM__ "NVM" //Non-Volatile Memory data storage 00289 00290 //============================================================================= 00291 // The '#pragma segment=' declaration must be used before attempting to access 00292 // the segments so the compiler properly handles the __segment_*() functions. 00293 // 00294 // The segment names used here are the default segment names used by IAR. Refer 00295 // to the IAR Compiler Reference Guide for a proper description of these 00296 // segments. 00297 //============================================================================= 00298 #pragma segment=__NO_INIT__ 00299 #pragma segment=__INTVEC__ 00300 #pragma segment=__CSTACK__ 00301 #pragma segment=__DATA_INIT__ 00302 #pragma segment=__DATA__ 00303 #pragma segment=__BSS__ 00304 #pragma segment=__CONST__ 00305 #pragma segment=__TEXT__ 00306 #pragma segment=__TEXTRW_INIT__ 00307 #pragma segment=__TEXTRW__ 00308 #pragma segment=__FAT__ 00309 #pragma segment=__NVM__ 00310 // Special pragma to get the application image start and end address 00311 #pragma segment="FLASH_IMAGE" 00312 /**@} */ 00313 00314 //A utility function for inserting barrier instructions. These 00315 //instructions should be used whenever the MPU is enabled or disabled so 00316 //that all memory/instruction accesses can complete before the MPU changes 00317 //state. 00318 void _executeBarrierInstructions(void); 00319 // MPU is unused with this platform header variant 00320 #define _HAL_MPU_UNUSED_ 00321 00322 //////////////////////////////////////////////////////////////////////////////// 00323 /** \name Global Interrupt Manipulation Macros 00324 * 00325 * \b Note: The special purpose BASEPRI register is used to enable and disable 00326 * interrupts while permitting faults. 00327 * When BASEPRI is set to 1 no interrupts can trigger. The configurable faults 00328 * (usage, memory management, and bus faults) can trigger if enabled as well as 00329 * the always-enabled exceptions (reset, NMI and hard fault). 00330 * When BASEPRI is set to 0, it is disabled, so any interrupt can triggger if 00331 * its priority is higher than the current priority. 00332 */ 00333 //////////////////////////////////////////////////////////////////////////////// 00334 //@{ 00335 00336 #define ATOMIC_LITE(blah) ATOMIC(blah) 00337 #define DECLARE_INTERRUPT_STATE_LITE DECLARE_INTERRUPT_STATE 00338 #define DISABLE_INTERRUPTS_LITE() DISABLE_INTERRUPTS() 00339 #define RESTORE_INTERRUPTS_LITE() RESTORE_INTERRUPTS() 00340 00341 #ifdef BOOTLOADER 00342 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00343 // The bootloader does not use interrupts 00344 #define DECLARE_INTERRUPT_STATE 00345 #define DISABLE_INTERRUPTS() do { } while(0) 00346 #define RESTORE_INTERRUPTS() do { } while(0) 00347 #define INTERRUPTS_ON() do { } while(0) 00348 #define INTERRUPTS_OFF() do { } while(0) 00349 #define INTERRUPTS_ARE_OFF() (FALSE) 00350 #define ATOMIC(blah) { blah } 00351 #define HANDLE_PENDING_INTERRUPTS() do { } while(0) 00352 #define SET_BASE_PRIORITY_LEVEL(basepri) do { } while(0) 00353 #endif // DOXYGEN_SHOULD_SKIP_THIS 00354 #else // BOOTLOADER 00355 00356 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00357 /** 00358 * @brief This macro should be called in the local variable 00359 * declarations section of any function which calls DISABLE_INTERRUPTS() 00360 * or RESTORE_INTERRUPTS(). 00361 */ 00362 #define DECLARE_INTERRUPT_STATE int8u _emIsrState 00363 00364 // Prototypes for the BASEPRI and PRIMASK access functions. They are very 00365 // basic and instantiated in assembly code in the file spmr.s37 (since 00366 // there are no C functions that cause the compiler to emit code to access 00367 // the BASEPRI/PRIMASK). This will inhibit the core from taking interrupts 00368 // with a priority equal to or less than the BASEPRI value. 00369 // Note that the priority values used by these functions are 5 bits and 00370 // right-aligned 00371 extern int8u _readBasePri(void); 00372 extern void _writeBasePri(int8u priority); 00373 00374 // Prototypes for BASEPRI functions used to disable and enable interrupts 00375 // while still allowing enabled faults to trigger. 00376 extern void _enableBasePri(void); 00377 extern int8u _disableBasePri(void); 00378 extern boolean _basePriIsDisabled(void); 00379 00380 // Prototypes for setting and clearing PRIMASK for global interrupt 00381 // enable/disable. 00382 extern void _setPriMask(void); 00383 extern void _clearPriMask(void); 00384 #endif // DOXYGEN_SHOULD_SKIP_THIS 00385 00386 //The core Global Interrupt Manipulation Macros start here. 00387 00388 /** 00389 * @brief Disable interrupts, saving the previous state so it can be 00390 * later restored with RESTORE_INTERRUPTS(). 00391 * \note Do not fail to call RESTORE_INTERRUPTS(). 00392 * \note It is safe to nest this call. 00393 */ 00394 #define DISABLE_INTERRUPTS() \ 00395 do { \ 00396 _emIsrState = _disableBasePri(); \ 00397 } while(0) 00398 00399 00400 /** 00401 * @brief Restore the global interrupt state previously saved by 00402 * DISABLE_INTERRUPTS() 00403 * \note Do not call without having first called DISABLE_INTERRUPTS() 00404 * to have saved the state. 00405 * \note It is safe to nest this call. 00406 */ 00407 #define RESTORE_INTERRUPTS() \ 00408 do { \ 00409 _writeBasePri(_emIsrState); \ 00410 } while(0) 00411 00412 00413 /** 00414 * @brief Enable global interrupts without regard to the current or 00415 * previous state. 00416 */ 00417 #define INTERRUPTS_ON() \ 00418 do { \ 00419 _enableBasePri(); \ 00420 } while(0) 00421 00422 00423 /** 00424 * @brief Disable global interrupts without regard to the current or 00425 * previous state. 00426 */ 00427 #define INTERRUPTS_OFF() \ 00428 do { \ 00429 (void)_disableBasePri(); \ 00430 } while(0) 00431 00432 00433 /** 00434 * @returns TRUE if global interrupts are disabled. 00435 */ 00436 #define INTERRUPTS_ARE_OFF() ( _basePriIsDisabled() ) 00437 00438 /** 00439 * @returns TRUE if global interrupt flag was enabled when 00440 * ::DISABLE_INTERRUPTS() was called. 00441 */ 00442 #define INTERRUPTS_WERE_ON() (_emIsrState == 0) 00443 00444 /** 00445 * @brief A block of code may be made atomic by wrapping it with this 00446 * macro. Something which is atomic cannot be interrupted by interrupts. 00447 */ 00448 #define ATOMIC(blah) \ 00449 { \ 00450 DECLARE_INTERRUPT_STATE; \ 00451 DISABLE_INTERRUPTS(); \ 00452 { blah } \ 00453 RESTORE_INTERRUPTS(); \ 00454 } 00455 00456 00457 /** 00458 * @brief Allows any pending interrupts to be executed. Usually this 00459 * would be called at a safe point while interrupts are disabled (such as 00460 * within an ISR). 00461 * 00462 * Takes no action if interrupts are already enabled. 00463 */ 00464 #define HANDLE_PENDING_INTERRUPTS() \ 00465 do { \ 00466 if (INTERRUPTS_ARE_OFF()) { \ 00467 INTERRUPTS_ON(); \ 00468 INTERRUPTS_OFF(); \ 00469 } \ 00470 } while (0) 00471 00472 00473 /** 00474 * @brief Sets the base priority mask (BASEPRI) to the value passed, 00475 * bit shifted up by PRIGROUP_POSITION+1. This will inhibit the core from 00476 * taking all interrupts with a preemptive priority equal to or less than 00477 * the BASEPRI mask. This macro is dependent on the value of 00478 * PRIGROUP_POSITION in nvic-config.h. Note that the value 0 disables the 00479 * the base priority mask. 00480 * 00481 * Refer to the "PRIGROUP" table in nvic-config.h to know the valid values 00482 * for this macro depending on the value of PRIGROUP_POSITION. With respect 00483 * to the table, this macro can only take the preemptive priority group 00484 * numbers denoted by the parenthesis. 00485 */ 00486 #define SET_BASE_PRIORITY_LEVEL(basepri) \ 00487 do { \ 00488 _writeBasePri(basepri); \ 00489 } while(0) 00490 00491 #endif // BOOTLOADER 00492 //////////////////////////////////////////////////////////////////////////////// 00493 //@} // end of Global Interrupt Manipulation Macros 00494 //////////////////////////////////////////////////////////////////////////////// 00495 00496 /** 00497 * @brief Use the C Standard Library Memory Utilities from platform-common.h 00498 */ 00499 #define _HAL_USE_COMMON_MEMUTILS_ 00500 00501 //////////////////////////////////////////////////////////////////////////////// 00502 /** \name External Declarations 00503 * These are routines that are defined in certain header files that we don't 00504 * want to include, e.g. stdlib.h 00505 */ 00506 //////////////////////////////////////////////////////////////////////////////// 00507 //@{ 00508 00509 /** 00510 * @brief Returns the absolute value of I (also called the magnitude of I). 00511 * That is, if I is negative, the result is the opposite of I, but if I is 00512 * nonnegative the result is I. 00513 * 00514 * @param I An integer. 00515 * 00516 * @return A nonnegative integer. 00517 */ 00518 int abs(int I); 00519 00520 //////////////////////////////////////////////////////////////////////////////// 00521 //@} // end of External Declarations 00522 //////////////////////////////////////////////////////////////////////////////// 00523 00524 00525 /** 00526 * @brief Include platform-common.h last to pick up defaults and common definitions. 00527 */ 00528 #define PLATCOMMONOKTOINCLUDE 00529 #include "hal/micro/generic/compiler/platform-common.h" 00530 #undef PLATCOMMONOKTOINCLUDE 00531 00532 #endif // __IAR_H__ 00533 00534 /** @} END addtogroup */ 00535