sa

Fork of nRF51822 by Nordic Semiconductor

Committer:
nakamae
Date:
Thu Dec 29 07:05:48 2016 +0000
Revision:
639:fdeb2820ef26
Parent:
638:c90ae1400bf2
new;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 2 /*!
Vincent Coubard 638:c90ae1400bf2 3 @file compiler.h
Vincent Coubard 638:c90ae1400bf2 4 @author hathach (tinyusb.org)
Vincent Coubard 638:c90ae1400bf2 5
Vincent Coubard 638:c90ae1400bf2 6 @section LICENSE
Vincent Coubard 638:c90ae1400bf2 7
Vincent Coubard 638:c90ae1400bf2 8 Software License Agreement (BSD License)
Vincent Coubard 638:c90ae1400bf2 9
Vincent Coubard 638:c90ae1400bf2 10 Copyright (c) 2013, K. Townsend (microBuilder.eu)
Vincent Coubard 638:c90ae1400bf2 11 All rights reserved.
Vincent Coubard 638:c90ae1400bf2 12
Vincent Coubard 638:c90ae1400bf2 13 Redistribution and use in source and binary forms, with or without
Vincent Coubard 638:c90ae1400bf2 14 modification, are permitted provided that the following conditions are met:
Vincent Coubard 638:c90ae1400bf2 15 1. Redistributions of source code must retain the above copyright
Vincent Coubard 638:c90ae1400bf2 16 notice, this list of conditions and the following disclaimer.
Vincent Coubard 638:c90ae1400bf2 17 2. Redistributions in binary form must reproduce the above copyright
Vincent Coubard 638:c90ae1400bf2 18 notice, this list of conditions and the following disclaimer in the
Vincent Coubard 638:c90ae1400bf2 19 documentation and/or other materials provided with the distribution.
Vincent Coubard 638:c90ae1400bf2 20 3. Neither the name of the copyright holders nor the
Vincent Coubard 638:c90ae1400bf2 21 names of its contributors may be used to endorse or promote products
Vincent Coubard 638:c90ae1400bf2 22 derived from this software without specific prior written permission.
Vincent Coubard 638:c90ae1400bf2 23
Vincent Coubard 638:c90ae1400bf2 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Vincent Coubard 638:c90ae1400bf2 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 638:c90ae1400bf2 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 638:c90ae1400bf2 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Vincent Coubard 638:c90ae1400bf2 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 638:c90ae1400bf2 29 INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 638:c90ae1400bf2 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
Vincent Coubard 638:c90ae1400bf2 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 638:c90ae1400bf2 32 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 638:c90ae1400bf2 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 638:c90ae1400bf2 34 */
Vincent Coubard 638:c90ae1400bf2 35 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 36
Vincent Coubard 638:c90ae1400bf2 37 /** \file
Vincent Coubard 638:c90ae1400bf2 38 * \brief GCC Header
Vincent Coubard 638:c90ae1400bf2 39 */
Vincent Coubard 638:c90ae1400bf2 40
Vincent Coubard 638:c90ae1400bf2 41 /** \ingroup Group_Compiler
Vincent Coubard 638:c90ae1400bf2 42 * \defgroup Group_GCC GNU GCC
Vincent Coubard 638:c90ae1400bf2 43 * @{
Vincent Coubard 638:c90ae1400bf2 44 */
Vincent Coubard 638:c90ae1400bf2 45
Vincent Coubard 638:c90ae1400bf2 46 #ifndef _COMPILER_GCC_H_
Vincent Coubard 638:c90ae1400bf2 47 #define _COMPILER_GCC_H_
Vincent Coubard 638:c90ae1400bf2 48
Vincent Coubard 638:c90ae1400bf2 49 #ifdef __cplusplus
Vincent Coubard 638:c90ae1400bf2 50 extern "C" {
Vincent Coubard 638:c90ae1400bf2 51 #endif
Vincent Coubard 638:c90ae1400bf2 52
Vincent Coubard 638:c90ae1400bf2 53 #include "projectconfig.h"
Vincent Coubard 638:c90ae1400bf2 54
Vincent Coubard 638:c90ae1400bf2 55 //#ifndef __GNUC__
Vincent Coubard 638:c90ae1400bf2 56 // #define ATTR_ALWAYS_INLINE
Vincent Coubard 638:c90ae1400bf2 57 // #define ATTR_CONST
Vincent Coubard 638:c90ae1400bf2 58 //#else
Vincent Coubard 638:c90ae1400bf2 59
Vincent Coubard 638:c90ae1400bf2 60 #ifdef _TEST_
Vincent Coubard 638:c90ae1400bf2 61 #define ATTR_ALWAYS_INLINE
Vincent Coubard 638:c90ae1400bf2 62 #define STATIC_
Vincent Coubard 638:c90ae1400bf2 63 #define INLINE_
Vincent Coubard 638:c90ae1400bf2 64 #else
Vincent Coubard 638:c90ae1400bf2 65 #define STATIC_ static
Vincent Coubard 638:c90ae1400bf2 66 #define INLINE_ inline
Vincent Coubard 638:c90ae1400bf2 67
Vincent Coubard 638:c90ae1400bf2 68 #if CFG_DEBUG == 3
Vincent Coubard 638:c90ae1400bf2 69 #define ATTR_ALWAYS_INLINE // no inline for debug = 3
Vincent Coubard 638:c90ae1400bf2 70 #endif
Vincent Coubard 638:c90ae1400bf2 71 #endif
Vincent Coubard 638:c90ae1400bf2 72
Vincent Coubard 638:c90ae1400bf2 73
Vincent Coubard 638:c90ae1400bf2 74 #ifdef __GNUC__
Vincent Coubard 638:c90ae1400bf2 75
Vincent Coubard 638:c90ae1400bf2 76 #define ALIGN_OF(x) __alignof__(x)
Vincent Coubard 638:c90ae1400bf2 77
Vincent Coubard 638:c90ae1400bf2 78 /// Normally, the compiler places the objects it generates in sections like data or bss & function in text. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section
Vincent Coubard 638:c90ae1400bf2 79 #define ATTR_SECTION(section) __attribute__ ((#section))
Vincent Coubard 638:c90ae1400bf2 80
Vincent Coubard 638:c90ae1400bf2 81 /// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error that includes message is diagnosed. This is useful for compile-time checking
Vincent Coubard 638:c90ae1400bf2 82 #define ATTR_ERROR(Message) __attribute__ ((error(Message)))
Vincent Coubard 638:c90ae1400bf2 83
Vincent Coubard 638:c90ae1400bf2 84 /// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning that includes message is diagnosed. This is useful for compile-time checking
Vincent Coubard 638:c90ae1400bf2 85 #define ATTR_WARNING(Message) __attribute__ ((warning(Message)))
Vincent Coubard 638:c90ae1400bf2 86
Vincent Coubard 638:c90ae1400bf2 87 /**
Vincent Coubard 638:c90ae1400bf2 88 * \defgroup Group_VariableAttr Variable Attributes
Vincent Coubard 638:c90ae1400bf2 89 * @{
Vincent Coubard 638:c90ae1400bf2 90 */
Vincent Coubard 638:c90ae1400bf2 91
Vincent Coubard 638:c90ae1400bf2 92 /// This attribute specifies a minimum alignment for the variable or structure field, measured in bytes
Vincent Coubard 638:c90ae1400bf2 93 #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
Vincent Coubard 638:c90ae1400bf2 94
Vincent Coubard 638:c90ae1400bf2 95 /// The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute
Vincent Coubard 638:c90ae1400bf2 96 #define ATTR_PACKED __attribute__ ((packed))
Vincent Coubard 638:c90ae1400bf2 97
Vincent Coubard 638:c90ae1400bf2 98 #define ATTR_PREPACKED
Vincent Coubard 638:c90ae1400bf2 99
Vincent Coubard 638:c90ae1400bf2 100 #define ATTR_PACKED_STRUCT(x) x __attribute__ ((packed))
Vincent Coubard 638:c90ae1400bf2 101 /** @} */
Vincent Coubard 638:c90ae1400bf2 102
Vincent Coubard 638:c90ae1400bf2 103 /**
Vincent Coubard 638:c90ae1400bf2 104 * \defgroup Group_FuncAttr Function Attributes
Vincent Coubard 638:c90ae1400bf2 105 * @{
Vincent Coubard 638:c90ae1400bf2 106 */
Vincent Coubard 638:c90ae1400bf2 107
Vincent Coubard 638:c90ae1400bf2 108 #ifndef ATTR_ALWAYS_INLINE
Vincent Coubard 638:c90ae1400bf2 109 /// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified
Vincent Coubard 638:c90ae1400bf2 110 #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline))
Vincent Coubard 638:c90ae1400bf2 111 #endif
Vincent Coubard 638:c90ae1400bf2 112
Vincent Coubard 638:c90ae1400bf2 113 /// The nonnull attribute specifies that some function parameters should be non-null pointers. f the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. All pointer arguments are marked as non-null
Vincent Coubard 638:c90ae1400bf2 114 #define ATTR_NON_NULL __attribute__ ((nonull))
Vincent Coubard 638:c90ae1400bf2 115
Vincent Coubard 638:c90ae1400bf2 116 /// Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure
Vincent Coubard 638:c90ae1400bf2 117 #define ATTR_PURE __attribute__ ((pure))
Vincent Coubard 638:c90ae1400bf2 118
Vincent Coubard 638:c90ae1400bf2 119 /// Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory.
Vincent Coubard 638:c90ae1400bf2 120 /// Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void
Vincent Coubard 638:c90ae1400bf2 121 #define ATTR_CONST __attribute__ ((const))
Vincent Coubard 638:c90ae1400bf2 122
Vincent Coubard 638:c90ae1400bf2 123 /// The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses
Vincent Coubard 638:c90ae1400bf2 124 #define ATTR_DEPRECATED __attribute__ ((deprecated))
Vincent Coubard 638:c90ae1400bf2 125
Vincent Coubard 638:c90ae1400bf2 126 /// Same as the deprecated attribute with optional message in the warning
Vincent Coubard 638:c90ae1400bf2 127 #define ATTR_DEPRECATED_MESS(mess) __attribute__ ((deprecated(mess)))
Vincent Coubard 638:c90ae1400bf2 128
Vincent Coubard 638:c90ae1400bf2 129 /// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions that can be overridden in user code
Vincent Coubard 638:c90ae1400bf2 130 #define ATTR_WEAK __attribute__ ((weak))
Vincent Coubard 638:c90ae1400bf2 131
Vincent Coubard 638:c90ae1400bf2 132 /// The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified
Vincent Coubard 638:c90ae1400bf2 133 #define ATTR_ALIAS(func) __attribute__ ((alias(#func)))
Vincent Coubard 638:c90ae1400bf2 134
Vincent Coubard 638:c90ae1400bf2 135 /// The weakref attribute marks a declaration as a weak reference. It is equivalent with weak + alias attribute, but require function is static
Vincent Coubard 638:c90ae1400bf2 136 #define ATTR_WEAKREF(func) __attribute__ ((weakref(#func)))
Vincent Coubard 638:c90ae1400bf2 137
Vincent Coubard 638:c90ae1400bf2 138 /// The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug
Vincent Coubard 638:c90ae1400bf2 139 #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
Vincent Coubard 638:c90ae1400bf2 140
Vincent Coubard 638:c90ae1400bf2 141 /// This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly.
Vincent Coubard 638:c90ae1400bf2 142 #define ATTR_USED __attribute__ ((used))
Vincent Coubard 638:c90ae1400bf2 143
Vincent Coubard 638:c90ae1400bf2 144 /// This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function.
Vincent Coubard 638:c90ae1400bf2 145 #define ATTR_UNUSED __attribute__ ((unused))
Vincent Coubard 638:c90ae1400bf2 146
Vincent Coubard 638:c90ae1400bf2 147 #elif defined (__ICCARM__) //IAR
Vincent Coubard 638:c90ae1400bf2 148 #define ATTR_ALWAYS_INLINE // IAR dosn't provide such a syntax extension in function's prototypes.
Vincent Coubard 638:c90ae1400bf2 149 #define ATTR_CONST // IAR dosn't provide such a syntax extension in function's prototypes.
Vincent Coubard 638:c90ae1400bf2 150 #endif
Vincent Coubard 638:c90ae1400bf2 151
Vincent Coubard 638:c90ae1400bf2 152 /** @} */
Vincent Coubard 638:c90ae1400bf2 153
Vincent Coubard 638:c90ae1400bf2 154 #ifdef __cplusplus
Vincent Coubard 638:c90ae1400bf2 155 }
Vincent Coubard 638:c90ae1400bf2 156 #endif
Vincent Coubard 638:c90ae1400bf2 157
Vincent Coubard 638:c90ae1400bf2 158 #endif /* _COMPILER_GCC_H_ */
Vincent Coubard 638:c90ae1400bf2 159
Vincent Coubard 638:c90ae1400bf2 160 /// @}