MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgabino 0:c76361bd82e8 1 /* mbed Microcontroller Library
dgabino 0:c76361bd82e8 2 * Copyright (c) 2006-2013 ARM Limited
dgabino 0:c76361bd82e8 3 *
dgabino 0:c76361bd82e8 4 * Licensed under the Apache License, Version 2.0 (the "License");
dgabino 0:c76361bd82e8 5 * you may not use this file except in compliance with the License.
dgabino 0:c76361bd82e8 6 * You may obtain a copy of the License at
dgabino 0:c76361bd82e8 7 *
dgabino 0:c76361bd82e8 8 * http://www.apache.org/licenses/LICENSE-2.0
dgabino 0:c76361bd82e8 9 *
dgabino 0:c76361bd82e8 10 * Unless required by applicable law or agreed to in writing, software
dgabino 0:c76361bd82e8 11 * distributed under the License is distributed on an "AS IS" BASIS,
dgabino 0:c76361bd82e8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dgabino 0:c76361bd82e8 13 * See the License for the specific language governing permissions and
dgabino 0:c76361bd82e8 14 * limitations under the License.
dgabino 0:c76361bd82e8 15 */
dgabino 0:c76361bd82e8 16 #ifndef MBED_TOOLCHAIN_H
dgabino 0:c76361bd82e8 17 #define MBED_TOOLCHAIN_H
dgabino 0:c76361bd82e8 18
dgabino 0:c76361bd82e8 19
dgabino 0:c76361bd82e8 20 // Warning for unsupported compilers
dgabino 0:c76361bd82e8 21 #if !defined(__GNUC__) /* GCC */ \
dgabino 0:c76361bd82e8 22 && !defined(__CC_ARM) /* ARMCC */ \
dgabino 0:c76361bd82e8 23 && !defined(__clang__) /* LLVM/Clang */ \
dgabino 0:c76361bd82e8 24 && !defined(__ICCARM__) /* IAR */
dgabino 0:c76361bd82e8 25 #warning "This compiler is not yet supported."
dgabino 0:c76361bd82e8 26 #endif
dgabino 0:c76361bd82e8 27
dgabino 0:c76361bd82e8 28
dgabino 0:c76361bd82e8 29 // Attributes
dgabino 0:c76361bd82e8 30
dgabino 0:c76361bd82e8 31 /** MBED_PACKED
dgabino 0:c76361bd82e8 32 * Pack a structure, preventing any padding from being added between fields.
dgabino 0:c76361bd82e8 33 *
dgabino 0:c76361bd82e8 34 * @code
dgabino 0:c76361bd82e8 35 * #include "toolchain.h"
dgabino 0:c76361bd82e8 36 *
dgabino 0:c76361bd82e8 37 * MBED_PACKED(struct) foo {
dgabino 0:c76361bd82e8 38 * char x;
dgabino 0:c76361bd82e8 39 * int y;
dgabino 0:c76361bd82e8 40 * };
dgabino 0:c76361bd82e8 41 * @endcode
dgabino 0:c76361bd82e8 42 */
dgabino 0:c76361bd82e8 43 #ifndef MBED_PACKED
dgabino 0:c76361bd82e8 44 #if defined(__ICCARM__)
dgabino 0:c76361bd82e8 45 #define MBED_PACKED(struct) __packed struct
dgabino 0:c76361bd82e8 46 #else
dgabino 0:c76361bd82e8 47 #define MBED_PACKED(struct) struct __attribute__((packed))
dgabino 0:c76361bd82e8 48 #endif
dgabino 0:c76361bd82e8 49 #endif
dgabino 0:c76361bd82e8 50
dgabino 0:c76361bd82e8 51 /** MBED_ALIGN(N)
dgabino 0:c76361bd82e8 52 * Declare a variable to be aligned on an N-byte boundary.
dgabino 0:c76361bd82e8 53 *
dgabino 0:c76361bd82e8 54 * @note
dgabino 0:c76361bd82e8 55 * IAR does not support alignment greater than word size on the stack
dgabino 0:c76361bd82e8 56 *
dgabino 0:c76361bd82e8 57 * @code
dgabino 0:c76361bd82e8 58 * #include "toolchain.h"
dgabino 0:c76361bd82e8 59 *
dgabino 0:c76361bd82e8 60 * MBED_ALIGN(16) char a;
dgabino 0:c76361bd82e8 61 * @endcode
dgabino 0:c76361bd82e8 62 */
dgabino 0:c76361bd82e8 63 #ifndef MBED_ALIGN
dgabino 0:c76361bd82e8 64 #if defined(__ICCARM__)
dgabino 0:c76361bd82e8 65 #define _MBED_ALIGN(N) _Pragma(#N)
dgabino 0:c76361bd82e8 66 #define MBED_ALIGN(N) _MBED_ALIGN(data_alignment=N)
dgabino 0:c76361bd82e8 67 #else
dgabino 0:c76361bd82e8 68 #define MBED_ALIGN(N) __attribute__((aligned(N)))
dgabino 0:c76361bd82e8 69 #endif
dgabino 0:c76361bd82e8 70 #endif
dgabino 0:c76361bd82e8 71
dgabino 0:c76361bd82e8 72 /** MBED_UNUSED
dgabino 0:c76361bd82e8 73 * Declare a function argument to be unused, suppressing compiler warnings
dgabino 0:c76361bd82e8 74 *
dgabino 0:c76361bd82e8 75 * @code
dgabino 0:c76361bd82e8 76 * #include "toolchain.h"
dgabino 0:c76361bd82e8 77 *
dgabino 0:c76361bd82e8 78 * void foo(MBED_UNUSED int arg) {
dgabino 0:c76361bd82e8 79 *
dgabino 0:c76361bd82e8 80 * }
dgabino 0:c76361bd82e8 81 * @endcode
dgabino 0:c76361bd82e8 82 */
dgabino 0:c76361bd82e8 83 #ifndef MBED_UNUSED
dgabino 0:c76361bd82e8 84 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
dgabino 0:c76361bd82e8 85 #define MBED_UNUSED __attribute__((__unused__))
dgabino 0:c76361bd82e8 86 #else
dgabino 0:c76361bd82e8 87 #define MBED_UNUSED
dgabino 0:c76361bd82e8 88 #endif
dgabino 0:c76361bd82e8 89 #endif
dgabino 0:c76361bd82e8 90
dgabino 0:c76361bd82e8 91 /** MBED_WEAK
dgabino 0:c76361bd82e8 92 * Mark a function as being weak.
dgabino 0:c76361bd82e8 93 *
dgabino 0:c76361bd82e8 94 * @note
dgabino 0:c76361bd82e8 95 * weak functions are not friendly to making code re-usable, as they can only
dgabino 0:c76361bd82e8 96 * be overridden once (and if they are multiply overridden the linker will emit
dgabino 0:c76361bd82e8 97 * no warning). You should not normally use weak symbols as part of the API to
dgabino 0:c76361bd82e8 98 * re-usable modules.
dgabino 0:c76361bd82e8 99 *
dgabino 0:c76361bd82e8 100 * @code
dgabino 0:c76361bd82e8 101 * #include "toolchain.h"
dgabino 0:c76361bd82e8 102 *
dgabino 0:c76361bd82e8 103 * MBED_WEAK void foo() {
dgabino 0:c76361bd82e8 104 * // a weak implementation of foo that can be overriden by a definition
dgabino 0:c76361bd82e8 105 * // without __weak
dgabino 0:c76361bd82e8 106 * }
dgabino 0:c76361bd82e8 107 * @endcode
dgabino 0:c76361bd82e8 108 */
dgabino 0:c76361bd82e8 109 #ifndef MBED_WEAK
dgabino 0:c76361bd82e8 110 #if defined(__ICCARM__)
dgabino 0:c76361bd82e8 111 #define MBED_WEAK __weak
dgabino 0:c76361bd82e8 112 #else
dgabino 0:c76361bd82e8 113 #define MBED_WEAK __attribute__((weak))
dgabino 0:c76361bd82e8 114 #endif
dgabino 0:c76361bd82e8 115 #endif
dgabino 0:c76361bd82e8 116
dgabino 0:c76361bd82e8 117 /** MBED_PURE
dgabino 0:c76361bd82e8 118 * Hint to the compiler that a function depends only on parameters
dgabino 0:c76361bd82e8 119 *
dgabino 0:c76361bd82e8 120 * @code
dgabino 0:c76361bd82e8 121 * #include "toolchain.h"
dgabino 0:c76361bd82e8 122 *
dgabino 0:c76361bd82e8 123 * MBED_PURE int foo(int arg){
dgabino 0:c76361bd82e8 124 * // no access to global variables
dgabino 0:c76361bd82e8 125 * }
dgabino 0:c76361bd82e8 126 * @endcode
dgabino 0:c76361bd82e8 127 */
dgabino 0:c76361bd82e8 128 #ifndef MBED_PURE
dgabino 0:c76361bd82e8 129 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
dgabino 0:c76361bd82e8 130 #define MBED_PURE __attribute__((const))
dgabino 0:c76361bd82e8 131 #else
dgabino 0:c76361bd82e8 132 #define MBED_PURE
dgabino 0:c76361bd82e8 133 #endif
dgabino 0:c76361bd82e8 134 #endif
dgabino 0:c76361bd82e8 135
dgabino 0:c76361bd82e8 136 /** MBED_FORCEINLINE
dgabino 0:c76361bd82e8 137 * Declare a function that must always be inlined. Failure to inline
dgabino 0:c76361bd82e8 138 * such a function will result in an error.
dgabino 0:c76361bd82e8 139 *
dgabino 0:c76361bd82e8 140 * @code
dgabino 0:c76361bd82e8 141 * #include "toolchain.h"
dgabino 0:c76361bd82e8 142 *
dgabino 0:c76361bd82e8 143 * MBED_FORCEINLINE void foo() {
dgabino 0:c76361bd82e8 144 *
dgabino 0:c76361bd82e8 145 * }
dgabino 0:c76361bd82e8 146 * @endcode
dgabino 0:c76361bd82e8 147 */
dgabino 0:c76361bd82e8 148 #ifndef MBED_FORCEINLINE
dgabino 0:c76361bd82e8 149 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
dgabino 0:c76361bd82e8 150 #define MBED_FORCEINLINE static inline __attribute__((always_inline))
dgabino 0:c76361bd82e8 151 #elif defined(__ICCARM__)
dgabino 0:c76361bd82e8 152 #define MBED_FORCEINLINE _Pragma("inline=forced") static
dgabino 0:c76361bd82e8 153 #else
dgabino 0:c76361bd82e8 154 #define MBED_FORCEINLINE static inline
dgabino 0:c76361bd82e8 155 #endif
dgabino 0:c76361bd82e8 156 #endif
dgabino 0:c76361bd82e8 157
dgabino 0:c76361bd82e8 158 /** MBED_NORETURN
dgabino 0:c76361bd82e8 159 * Declare a function that will never return.
dgabino 0:c76361bd82e8 160 *
dgabino 0:c76361bd82e8 161 * @code
dgabino 0:c76361bd82e8 162 * #include "toolchain.h"
dgabino 0:c76361bd82e8 163 *
dgabino 0:c76361bd82e8 164 * MBED_NORETURN void foo() {
dgabino 0:c76361bd82e8 165 * // must never return
dgabino 0:c76361bd82e8 166 * while (1) {}
dgabino 0:c76361bd82e8 167 * }
dgabino 0:c76361bd82e8 168 * @endcode
dgabino 0:c76361bd82e8 169 */
dgabino 0:c76361bd82e8 170 #ifndef MBED_NORETURN
dgabino 0:c76361bd82e8 171 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
dgabino 0:c76361bd82e8 172 #define MBED_NORETURN __attribute__((noreturn))
dgabino 0:c76361bd82e8 173 #elif defined(__ICCARM__)
dgabino 0:c76361bd82e8 174 #define MBED_NORETURN __noreturn
dgabino 0:c76361bd82e8 175 #else
dgabino 0:c76361bd82e8 176 #define MBED_NORETURN
dgabino 0:c76361bd82e8 177 #endif
dgabino 0:c76361bd82e8 178 #endif
dgabino 0:c76361bd82e8 179
dgabino 0:c76361bd82e8 180 /** MBED_UNREACHABLE
dgabino 0:c76361bd82e8 181 * An unreachable statement. If the statement is reached,
dgabino 0:c76361bd82e8 182 * behaviour is undefined. Useful in situations where the compiler
dgabino 0:c76361bd82e8 183 * cannot deduce the unreachability of code.
dgabino 0:c76361bd82e8 184 *
dgabino 0:c76361bd82e8 185 * @code
dgabino 0:c76361bd82e8 186 * #include "toolchain.h"
dgabino 0:c76361bd82e8 187 *
dgabino 0:c76361bd82e8 188 * void foo(int arg) {
dgabino 0:c76361bd82e8 189 * switch (arg) {
dgabino 0:c76361bd82e8 190 * case 1: return 1;
dgabino 0:c76361bd82e8 191 * case 2: return 2;
dgabino 0:c76361bd82e8 192 * ...
dgabino 0:c76361bd82e8 193 * }
dgabino 0:c76361bd82e8 194 * MBED_UNREACHABLE;
dgabino 0:c76361bd82e8 195 * }
dgabino 0:c76361bd82e8 196 * @endcode
dgabino 0:c76361bd82e8 197 */
dgabino 0:c76361bd82e8 198 #ifndef MBED_UNREACHABLE
dgabino 0:c76361bd82e8 199 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM)
dgabino 0:c76361bd82e8 200 #define MBED_UNREACHABLE __builtin_unreachable()
dgabino 0:c76361bd82e8 201 #else
dgabino 0:c76361bd82e8 202 #define MBED_UNREACHABLE while (1)
dgabino 0:c76361bd82e8 203 #endif
dgabino 0:c76361bd82e8 204 #endif
dgabino 0:c76361bd82e8 205
dgabino 0:c76361bd82e8 206 /** MBED_DEPRECATED("message string")
dgabino 0:c76361bd82e8 207 * Mark a function declaration as deprecated, if it used then a warning will be
dgabino 0:c76361bd82e8 208 * issued by the compiler possibly including the provided message. Note that not
dgabino 0:c76361bd82e8 209 * all compilers are able to display the message.
dgabino 0:c76361bd82e8 210 *
dgabino 0:c76361bd82e8 211 * @code
dgabino 0:c76361bd82e8 212 * #include "toolchain.h"
dgabino 0:c76361bd82e8 213 *
dgabino 0:c76361bd82e8 214 * MBED_DEPRECATED("don't foo any more, bar instead")
dgabino 0:c76361bd82e8 215 * void foo(int arg);
dgabino 0:c76361bd82e8 216 * @endcode
dgabino 0:c76361bd82e8 217 */
dgabino 0:c76361bd82e8 218 #ifndef MBED_DEPRECATED
dgabino 0:c76361bd82e8 219 #if defined(__GNUC__) || defined(__clang__)
dgabino 0:c76361bd82e8 220 #define MBED_DEPRECATED(M) __attribute__((deprecated(M)))
dgabino 0:c76361bd82e8 221 #elif defined(__CC_ARM)
dgabino 0:c76361bd82e8 222 #define MBED_DEPRECATED(M) __attribute__((deprecated))
dgabino 0:c76361bd82e8 223 #else
dgabino 0:c76361bd82e8 224 #define MBED_DEPRECATED(M)
dgabino 0:c76361bd82e8 225 #endif
dgabino 0:c76361bd82e8 226 #endif
dgabino 0:c76361bd82e8 227
dgabino 0:c76361bd82e8 228 /** MBED_DEPRECATED_SINCE("version", "message string")
dgabino 0:c76361bd82e8 229 * Mark a function declaration as deprecated, noting that the declaration was
dgabino 0:c76361bd82e8 230 * deprecated on the specified version. If the function is used then a warning
dgabino 0:c76361bd82e8 231 * will be issued by the compiler possibly including the provided message.
dgabino 0:c76361bd82e8 232 * Note that not all compilers are able to display this message.
dgabino 0:c76361bd82e8 233 *
dgabino 0:c76361bd82e8 234 * @code
dgabino 0:c76361bd82e8 235 * #include "toolchain.h"
dgabino 0:c76361bd82e8 236 *
dgabino 0:c76361bd82e8 237 * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead")
dgabino 0:c76361bd82e8 238 * void foo(int arg);
dgabino 0:c76361bd82e8 239 * @endcode
dgabino 0:c76361bd82e8 240 */
dgabino 0:c76361bd82e8 241 #define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]")
dgabino 0:c76361bd82e8 242
dgabino 0:c76361bd82e8 243 /** MBED_CALLER_ADDR()
dgabino 0:c76361bd82e8 244 * Returns the caller of the current function.
dgabino 0:c76361bd82e8 245 *
dgabino 0:c76361bd82e8 246 * @note
dgabino 0:c76361bd82e8 247 * This macro is only implemented for GCC and ARMCC.
dgabino 0:c76361bd82e8 248 *
dgabino 0:c76361bd82e8 249 * @code
dgabino 0:c76361bd82e8 250 * #include "toolchain.h"
dgabino 0:c76361bd82e8 251 *
dgabino 0:c76361bd82e8 252 * printf("This function was called from %p", MBED_CALLER_ADDR());
dgabino 0:c76361bd82e8 253 * @endcode
dgabino 0:c76361bd82e8 254 *
dgabino 0:c76361bd82e8 255 * @return Address of the calling function
dgabino 0:c76361bd82e8 256 */
dgabino 0:c76361bd82e8 257 #ifndef MBED_CALLER_ADDR
dgabino 0:c76361bd82e8 258 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM)
dgabino 0:c76361bd82e8 259 #define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0))
dgabino 0:c76361bd82e8 260 #elif defined(__CC_ARM)
dgabino 0:c76361bd82e8 261 #define MBED_CALLER_ADDR() __builtin_return_address(0)
dgabino 0:c76361bd82e8 262 #else
dgabino 0:c76361bd82e8 263 #define MBED_CALLER_ADDR() (NULL)
dgabino 0:c76361bd82e8 264 #endif
dgabino 0:c76361bd82e8 265 #endif
dgabino 0:c76361bd82e8 266
dgabino 0:c76361bd82e8 267 // FILEHANDLE declaration
dgabino 0:c76361bd82e8 268 #if defined(TOOLCHAIN_ARM)
dgabino 0:c76361bd82e8 269 #include <rt_sys.h>
dgabino 0:c76361bd82e8 270 #endif
dgabino 0:c76361bd82e8 271
dgabino 0:c76361bd82e8 272 #ifndef FILEHANDLE
dgabino 0:c76361bd82e8 273 typedef int FILEHANDLE;
dgabino 0:c76361bd82e8 274 #endif
dgabino 0:c76361bd82e8 275
dgabino 0:c76361bd82e8 276 // Backwards compatibility
dgabino 0:c76361bd82e8 277 #ifndef WEAK
dgabino 0:c76361bd82e8 278 #define WEAK MBED_WEAK
dgabino 0:c76361bd82e8 279 #endif
dgabino 0:c76361bd82e8 280
dgabino 0:c76361bd82e8 281 #ifndef PACKED
dgabino 0:c76361bd82e8 282 #define PACKED MBED_PACKED()
dgabino 0:c76361bd82e8 283 #endif
dgabino 0:c76361bd82e8 284
dgabino 0:c76361bd82e8 285 #ifndef EXTERN
dgabino 0:c76361bd82e8 286 #define EXTERN extern
dgabino 0:c76361bd82e8 287 #endif
dgabino 0:c76361bd82e8 288
dgabino 0:c76361bd82e8 289 #endif