mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Child:
592:a274ee790e56
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 /**
mbed_official 579:53297373a894 2 * \file
mbed_official 579:53297373a894 3 *
mbed_official 579:53297373a894 4 * \brief Commonly used includes, types and macros.
mbed_official 579:53297373a894 5 *
mbed_official 579:53297373a894 6 * Copyright (C) 2012-2014 Atmel Corporation. All rights reserved.
mbed_official 579:53297373a894 7 *
mbed_official 579:53297373a894 8 * \asf_license_start
mbed_official 579:53297373a894 9 *
mbed_official 579:53297373a894 10 * Redistribution and use in source and binary forms, with or without
mbed_official 579:53297373a894 11 * modification, are permitted provided that the following conditions are met:
mbed_official 579:53297373a894 12 *
mbed_official 579:53297373a894 13 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 579:53297373a894 14 * this list of conditions and the following disclaimer.
mbed_official 579:53297373a894 15 *
mbed_official 579:53297373a894 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 579:53297373a894 17 * this list of conditions and the following disclaimer in the documentation
mbed_official 579:53297373a894 18 * and/or other materials provided with the distribution.
mbed_official 579:53297373a894 19 *
mbed_official 579:53297373a894 20 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 579:53297373a894 21 * from this software without specific prior written permission.
mbed_official 579:53297373a894 22 *
mbed_official 579:53297373a894 23 * 4. This software may only be redistributed and used in connection with an
mbed_official 579:53297373a894 24 * Atmel microcontroller product.
mbed_official 579:53297373a894 25 *
mbed_official 579:53297373a894 26 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 579:53297373a894 27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 579:53297373a894 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 579:53297373a894 29 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 579:53297373a894 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 579:53297373a894 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 579:53297373a894 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 579:53297373a894 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 579:53297373a894 34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 579:53297373a894 35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 579:53297373a894 36 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 579:53297373a894 37 *
mbed_official 579:53297373a894 38 * \asf_license_stop
mbed_official 579:53297373a894 39 *
mbed_official 579:53297373a894 40 */
mbed_official 579:53297373a894 41 /**
mbed_official 579:53297373a894 42 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 579:53297373a894 43 */
mbed_official 579:53297373a894 44
mbed_official 579:53297373a894 45 #ifndef UTILS_COMPILER_H_INCLUDED
mbed_official 579:53297373a894 46 #define UTILS_COMPILER_H_INCLUDED
mbed_official 579:53297373a894 47
mbed_official 579:53297373a894 48 /**
mbed_official 579:53297373a894 49 * \defgroup group_sam0_utils Compiler abstraction layer and code utilities
mbed_official 579:53297373a894 50 *
mbed_official 579:53297373a894 51 * Compiler abstraction layer and code utilities for Cortex-M0+ based Atmel SAM devices.
mbed_official 579:53297373a894 52 * This module provides various abstraction layers and utilities to make code compatible between different compilers.
mbed_official 579:53297373a894 53 *
mbed_official 579:53297373a894 54 * @{
mbed_official 579:53297373a894 55 */
mbed_official 579:53297373a894 56
mbed_official 579:53297373a894 57 #if (defined __ICCARM__)
mbed_official 579:53297373a894 58 # include <intrinsics.h>
mbed_official 579:53297373a894 59 #endif
mbed_official 579:53297373a894 60
mbed_official 579:53297373a894 61 #include <stddef.h>
mbed_official 579:53297373a894 62 #include <parts.h>
mbed_official 579:53297373a894 63 #include <status_codes.h>
mbed_official 579:53297373a894 64 #include <preprocessor.h>
mbed_official 579:53297373a894 65 #include <io.h>
mbed_official 579:53297373a894 66
mbed_official 579:53297373a894 67 #ifndef __ASSEMBLY__
mbed_official 579:53297373a894 68
mbed_official 579:53297373a894 69 #include <stdio.h>
mbed_official 579:53297373a894 70 #include <stdbool.h>
mbed_official 579:53297373a894 71 #include <stdint.h>
mbed_official 579:53297373a894 72 #include <stdlib.h>
mbed_official 579:53297373a894 73
mbed_official 579:53297373a894 74 /**
mbed_official 579:53297373a894 75 * \def UNUSED
mbed_official 579:53297373a894 76 * \brief Marking \a v as a unused parameter or value.
mbed_official 579:53297373a894 77 */
mbed_official 579:53297373a894 78 #define UNUSED(v) (void)(v)
mbed_official 579:53297373a894 79
mbed_official 579:53297373a894 80 /**
mbed_official 579:53297373a894 81 * \def barrier
mbed_official 579:53297373a894 82 * \brief Memory barrier
mbed_official 579:53297373a894 83 */
mbed_official 579:53297373a894 84 #ifdef __GNUC__
mbed_official 579:53297373a894 85 # define barrier() asm volatile("" ::: "memory")
mbed_official 579:53297373a894 86 #else
mbed_official 579:53297373a894 87 # define barrier() asm ("")
mbed_official 579:53297373a894 88 #endif
mbed_official 579:53297373a894 89
mbed_official 579:53297373a894 90 /**
mbed_official 579:53297373a894 91 * \brief Emit the compiler pragma \a arg.
mbed_official 579:53297373a894 92 *
mbed_official 579:53297373a894 93 * \param[in] arg The pragma directive as it would appear after \e \#pragma
mbed_official 579:53297373a894 94 * (i.e. not stringified).
mbed_official 579:53297373a894 95 */
mbed_official 579:53297373a894 96 #define COMPILER_PRAGMA(arg) _Pragma(#arg)
mbed_official 579:53297373a894 97
mbed_official 579:53297373a894 98 /**
mbed_official 579:53297373a894 99 * \def COMPILER_PACK_SET(alignment)
mbed_official 579:53297373a894 100 * \brief Set maximum alignment for subsequent struct and union definitions to \a alignment.
mbed_official 579:53297373a894 101 */
mbed_official 579:53297373a894 102 #define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
mbed_official 579:53297373a894 103
mbed_official 579:53297373a894 104 /**
mbed_official 579:53297373a894 105 * \def COMPILER_PACK_RESET()
mbed_official 579:53297373a894 106 * \brief Set default alignment for subsequent struct and union definitions.
mbed_official 579:53297373a894 107 */
mbed_official 579:53297373a894 108 #define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
mbed_official 579:53297373a894 109
mbed_official 579:53297373a894 110
mbed_official 579:53297373a894 111 /**
mbed_official 579:53297373a894 112 * \brief Set aligned boundary.
mbed_official 579:53297373a894 113 */
mbed_official 579:53297373a894 114 #if (defined __GNUC__) || (defined __CC_ARM)
mbed_official 579:53297373a894 115 # define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
mbed_official 579:53297373a894 116 #elif (defined __ICCARM__)
mbed_official 579:53297373a894 117 # define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
mbed_official 579:53297373a894 118 #endif
mbed_official 579:53297373a894 119
mbed_official 579:53297373a894 120 /**
mbed_official 579:53297373a894 121 * \brief Set word-aligned boundary.
mbed_official 579:53297373a894 122 */
mbed_official 579:53297373a894 123 #if (defined __GNUC__) || defined(__CC_ARM)
mbed_official 579:53297373a894 124 #define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
mbed_official 579:53297373a894 125 #elif (defined __ICCARM__)
mbed_official 579:53297373a894 126 #define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
mbed_official 579:53297373a894 127 #endif
mbed_official 579:53297373a894 128
mbed_official 579:53297373a894 129 /**
mbed_official 579:53297373a894 130 * \def __always_inline
mbed_official 579:53297373a894 131 * \brief The function should always be inlined.
mbed_official 579:53297373a894 132 *
mbed_official 579:53297373a894 133 * This annotation instructs the compiler to ignore its inlining
mbed_official 579:53297373a894 134 * heuristics and inline the function no matter how big it thinks it
mbed_official 579:53297373a894 135 * becomes.
mbed_official 579:53297373a894 136 */
mbed_official 579:53297373a894 137 #if defined(__CC_ARM)
mbed_official 579:53297373a894 138 # define __always_inline __forceinline
mbed_official 579:53297373a894 139 #elif (defined __GNUC__)
mbed_official 579:53297373a894 140 # define __always_inline __attribute__((__always_inline__))
mbed_official 579:53297373a894 141 #elif (defined __ICCARM__)
mbed_official 579:53297373a894 142 # define __always_inline _Pragma("inline=forced")
mbed_official 579:53297373a894 143 #endif
mbed_official 579:53297373a894 144
mbed_official 579:53297373a894 145 /**
mbed_official 579:53297373a894 146 * \def __no_inline
mbed_official 579:53297373a894 147 * \brief The function should never be inlined
mbed_official 579:53297373a894 148 *
mbed_official 579:53297373a894 149 * This annotation instructs the compiler to ignore its inlining
mbed_official 579:53297373a894 150 * heuristics and not inline the function no matter how small it thinks it
mbed_official 579:53297373a894 151 * becomes.
mbed_official 579:53297373a894 152 */
mbed_official 579:53297373a894 153 #if defined(__CC_ARM)
mbed_official 579:53297373a894 154 # define __no_inline __attribute__((noinline))
mbed_official 579:53297373a894 155 #elif (defined __GNUC__)
mbed_official 579:53297373a894 156 # define __no_inline __attribute__((noinline))
mbed_official 579:53297373a894 157 #elif (defined __ICCARM__)
mbed_official 579:53297373a894 158 # define __no_inline _Pragma("inline=never")
mbed_official 579:53297373a894 159 #endif
mbed_official 579:53297373a894 160
mbed_official 579:53297373a894 161
mbed_official 579:53297373a894 162 /** \brief This macro is used to test fatal errors.
mbed_official 579:53297373a894 163 *
mbed_official 579:53297373a894 164 * The macro tests if the expression is false. If it is, a fatal error is
mbed_official 579:53297373a894 165 * detected and the application hangs up. If \c TEST_SUITE_DEFINE_ASSERT_MACRO
mbed_official 579:53297373a894 166 * is defined, a unit test version of the macro is used, to allow execution
mbed_official 579:53297373a894 167 * of further tests after a false expression.
mbed_official 579:53297373a894 168 *
mbed_official 579:53297373a894 169 * \param[in] expr Expression to evaluate and supposed to be nonzero.
mbed_official 579:53297373a894 170 */
mbed_official 579:53297373a894 171 #if defined(_ASSERT_ENABLE_)
mbed_official 579:53297373a894 172 # if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
mbed_official 579:53297373a894 173 # include "unit_test/suite.h"
mbed_official 579:53297373a894 174 # else
mbed_official 579:53297373a894 175 # undef TEST_SUITE_DEFINE_ASSERT_MACRO
mbed_official 579:53297373a894 176 # define Assert(expr) \
mbed_official 579:53297373a894 177 {\
mbed_official 579:53297373a894 178 if (!(expr)) asm("BKPT #0");\
mbed_official 579:53297373a894 179 }
mbed_official 579:53297373a894 180 # endif
mbed_official 579:53297373a894 181 #else
mbed_official 579:53297373a894 182 # define Assert(expr) ((void) 0)
mbed_official 579:53297373a894 183 #endif
mbed_official 579:53297373a894 184
mbed_official 579:53297373a894 185 /* Define WEAK attribute */
mbed_official 579:53297373a894 186 #if defined ( __CC_ARM )
mbed_official 579:53297373a894 187 # define WEAK __attribute__ ((weak))
mbed_official 579:53297373a894 188 #elif defined ( __ICCARM__ )
mbed_official 579:53297373a894 189 # define WEAK __weak
mbed_official 579:53297373a894 190 #elif defined ( __GNUC__ )
mbed_official 579:53297373a894 191 # define WEAK __attribute__ ((weak))
mbed_official 579:53297373a894 192 #endif
mbed_official 579:53297373a894 193
mbed_official 579:53297373a894 194 /* Define NO_INIT attribute */
mbed_official 579:53297373a894 195 #if defined ( __CC_ARM )
mbed_official 579:53297373a894 196 # define NO_INIT __attribute__((zero_init))
mbed_official 579:53297373a894 197 #elif defined ( __ICCARM__ )
mbed_official 579:53297373a894 198 # define NO_INIT __no_init
mbed_official 579:53297373a894 199 #elif defined ( __GNUC__ )
mbed_official 579:53297373a894 200 # define NO_INIT __attribute__((section(".no_init")))
mbed_official 579:53297373a894 201 #endif
mbed_official 579:53297373a894 202
mbed_official 579:53297373a894 203 #include "interrupt.h"
mbed_official 579:53297373a894 204
mbed_official 579:53297373a894 205 /** \name Usual Types
mbed_official 579:53297373a894 206 * @{ */
mbed_official 579:53297373a894 207 #ifndef __cplusplus
mbed_official 579:53297373a894 208 # if !defined(__bool_true_false_are_defined)
mbed_official 579:53297373a894 209 typedef unsigned char bool;
mbed_official 579:53297373a894 210 # endif
mbed_official 579:53297373a894 211 #endif
mbed_official 579:53297373a894 212 typedef uint16_t le16_t;
mbed_official 579:53297373a894 213 typedef uint16_t be16_t;
mbed_official 579:53297373a894 214 typedef uint32_t le32_t;
mbed_official 579:53297373a894 215 typedef uint32_t be32_t;
mbed_official 579:53297373a894 216 typedef uint32_t iram_size_t;
mbed_official 579:53297373a894 217 /** @} */
mbed_official 579:53297373a894 218
mbed_official 579:53297373a894 219 /** \name Aliasing Aggregate Types
mbed_official 579:53297373a894 220 * @{ */
mbed_official 579:53297373a894 221
mbed_official 579:53297373a894 222 /** 16-bit union. */
mbed_official 579:53297373a894 223 typedef union {
mbed_official 579:53297373a894 224 int16_t s16;
mbed_official 579:53297373a894 225 uint16_t u16;
mbed_official 579:53297373a894 226 int8_t s8[2];
mbed_official 579:53297373a894 227 uint8_t u8[2];
mbed_official 579:53297373a894 228 } Union16;
mbed_official 579:53297373a894 229
mbed_official 579:53297373a894 230 /** 32-bit union. */
mbed_official 579:53297373a894 231 typedef union {
mbed_official 579:53297373a894 232 int32_t s32;
mbed_official 579:53297373a894 233 uint32_t u32;
mbed_official 579:53297373a894 234 int16_t s16[2];
mbed_official 579:53297373a894 235 uint16_t u16[2];
mbed_official 579:53297373a894 236 int8_t s8[4];
mbed_official 579:53297373a894 237 uint8_t u8[4];
mbed_official 579:53297373a894 238 } Union32;
mbed_official 579:53297373a894 239
mbed_official 579:53297373a894 240 /** 64-bit union. */
mbed_official 579:53297373a894 241 typedef union {
mbed_official 579:53297373a894 242 int64_t s64;
mbed_official 579:53297373a894 243 uint64_t u64;
mbed_official 579:53297373a894 244 int32_t s32[2];
mbed_official 579:53297373a894 245 uint32_t u32[2];
mbed_official 579:53297373a894 246 int16_t s16[4];
mbed_official 579:53297373a894 247 uint16_t u16[4];
mbed_official 579:53297373a894 248 int8_t s8[8];
mbed_official 579:53297373a894 249 uint8_t u8[8];
mbed_official 579:53297373a894 250 } Union64;
mbed_official 579:53297373a894 251
mbed_official 579:53297373a894 252 /** Union of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 253 typedef union {
mbed_official 579:53297373a894 254 int64_t *s64ptr;
mbed_official 579:53297373a894 255 uint64_t *u64ptr;
mbed_official 579:53297373a894 256 int32_t *s32ptr;
mbed_official 579:53297373a894 257 uint32_t *u32ptr;
mbed_official 579:53297373a894 258 int16_t *s16ptr;
mbed_official 579:53297373a894 259 uint16_t *u16ptr;
mbed_official 579:53297373a894 260 int8_t *s8ptr;
mbed_official 579:53297373a894 261 uint8_t *u8ptr;
mbed_official 579:53297373a894 262 } UnionPtr;
mbed_official 579:53297373a894 263
mbed_official 579:53297373a894 264 /** Union of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 265 typedef union {
mbed_official 579:53297373a894 266 volatile int64_t *s64ptr;
mbed_official 579:53297373a894 267 volatile uint64_t *u64ptr;
mbed_official 579:53297373a894 268 volatile int32_t *s32ptr;
mbed_official 579:53297373a894 269 volatile uint32_t *u32ptr;
mbed_official 579:53297373a894 270 volatile int16_t *s16ptr;
mbed_official 579:53297373a894 271 volatile uint16_t *u16ptr;
mbed_official 579:53297373a894 272 volatile int8_t *s8ptr;
mbed_official 579:53297373a894 273 volatile uint8_t *u8ptr;
mbed_official 579:53297373a894 274 } UnionVPtr;
mbed_official 579:53297373a894 275
mbed_official 579:53297373a894 276 /** Union of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 277 typedef union {
mbed_official 579:53297373a894 278 const int64_t *s64ptr;
mbed_official 579:53297373a894 279 const uint64_t *u64ptr;
mbed_official 579:53297373a894 280 const int32_t *s32ptr;
mbed_official 579:53297373a894 281 const uint32_t *u32ptr;
mbed_official 579:53297373a894 282 const int16_t *s16ptr;
mbed_official 579:53297373a894 283 const uint16_t *u16ptr;
mbed_official 579:53297373a894 284 const int8_t *s8ptr;
mbed_official 579:53297373a894 285 const uint8_t *u8ptr;
mbed_official 579:53297373a894 286 } UnionCPtr;
mbed_official 579:53297373a894 287
mbed_official 579:53297373a894 288 /** Union of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 289 typedef union {
mbed_official 579:53297373a894 290 const volatile int64_t *s64ptr;
mbed_official 579:53297373a894 291 const volatile uint64_t *u64ptr;
mbed_official 579:53297373a894 292 const volatile int32_t *s32ptr;
mbed_official 579:53297373a894 293 const volatile uint32_t *u32ptr;
mbed_official 579:53297373a894 294 const volatile int16_t *s16ptr;
mbed_official 579:53297373a894 295 const volatile uint16_t *u16ptr;
mbed_official 579:53297373a894 296 const volatile int8_t *s8ptr;
mbed_official 579:53297373a894 297 const volatile uint8_t *u8ptr;
mbed_official 579:53297373a894 298 } UnionCVPtr;
mbed_official 579:53297373a894 299
mbed_official 579:53297373a894 300 /** Structure of pointers to 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 301 typedef struct {
mbed_official 579:53297373a894 302 int64_t *s64ptr;
mbed_official 579:53297373a894 303 uint64_t *u64ptr;
mbed_official 579:53297373a894 304 int32_t *s32ptr;
mbed_official 579:53297373a894 305 uint32_t *u32ptr;
mbed_official 579:53297373a894 306 int16_t *s16ptr;
mbed_official 579:53297373a894 307 uint16_t *u16ptr;
mbed_official 579:53297373a894 308 int8_t *s8ptr;
mbed_official 579:53297373a894 309 uint8_t *u8ptr;
mbed_official 579:53297373a894 310 } StructPtr;
mbed_official 579:53297373a894 311
mbed_official 579:53297373a894 312 /** Structure of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 313 typedef struct {
mbed_official 579:53297373a894 314 volatile int64_t *s64ptr;
mbed_official 579:53297373a894 315 volatile uint64_t *u64ptr;
mbed_official 579:53297373a894 316 volatile int32_t *s32ptr;
mbed_official 579:53297373a894 317 volatile uint32_t *u32ptr;
mbed_official 579:53297373a894 318 volatile int16_t *s16ptr;
mbed_official 579:53297373a894 319 volatile uint16_t *u16ptr;
mbed_official 579:53297373a894 320 volatile int8_t *s8ptr;
mbed_official 579:53297373a894 321 volatile uint8_t *u8ptr;
mbed_official 579:53297373a894 322 } StructVPtr;
mbed_official 579:53297373a894 323
mbed_official 579:53297373a894 324 /** Structure of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 325 typedef struct {
mbed_official 579:53297373a894 326 const int64_t *s64ptr;
mbed_official 579:53297373a894 327 const uint64_t *u64ptr;
mbed_official 579:53297373a894 328 const int32_t *s32ptr;
mbed_official 579:53297373a894 329 const uint32_t *u32ptr;
mbed_official 579:53297373a894 330 const int16_t *s16ptr;
mbed_official 579:53297373a894 331 const uint16_t *u16ptr;
mbed_official 579:53297373a894 332 const int8_t *s8ptr;
mbed_official 579:53297373a894 333 const uint8_t *u8ptr;
mbed_official 579:53297373a894 334 } StructCPtr;
mbed_official 579:53297373a894 335
mbed_official 579:53297373a894 336 /** Structure of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. */
mbed_official 579:53297373a894 337 typedef struct {
mbed_official 579:53297373a894 338 const volatile int64_t *s64ptr;
mbed_official 579:53297373a894 339 const volatile uint64_t *u64ptr;
mbed_official 579:53297373a894 340 const volatile int32_t *s32ptr;
mbed_official 579:53297373a894 341 const volatile uint32_t *u32ptr;
mbed_official 579:53297373a894 342 const volatile int16_t *s16ptr;
mbed_official 579:53297373a894 343 const volatile uint16_t *u16ptr;
mbed_official 579:53297373a894 344 const volatile int8_t *s8ptr;
mbed_official 579:53297373a894 345 const volatile uint8_t *u8ptr;
mbed_official 579:53297373a894 346 } StructCVPtr;
mbed_official 579:53297373a894 347
mbed_official 579:53297373a894 348 /** @} */
mbed_official 579:53297373a894 349
mbed_official 579:53297373a894 350 #endif /* #ifndef __ASSEMBLY__ */
mbed_official 579:53297373a894 351
mbed_official 579:53297373a894 352 /** \name Usual Constants
mbed_official 579:53297373a894 353 * @{ */
mbed_official 579:53297373a894 354 #define DISABLE 0
mbed_official 579:53297373a894 355 #define ENABLE 1
mbed_official 579:53297373a894 356
mbed_official 579:53297373a894 357 #ifndef __cplusplus
mbed_official 579:53297373a894 358 # if !defined(__bool_true_false_are_defined)
mbed_official 579:53297373a894 359 # define false 0
mbed_official 579:53297373a894 360 # define true 1
mbed_official 579:53297373a894 361 # endif
mbed_official 579:53297373a894 362 #endif
mbed_official 579:53297373a894 363 /** @} */
mbed_official 579:53297373a894 364
mbed_official 579:53297373a894 365 #ifndef __ASSEMBLY__
mbed_official 579:53297373a894 366
mbed_official 579:53297373a894 367 /** \name Optimization Control
mbed_official 579:53297373a894 368 * @{ */
mbed_official 579:53297373a894 369
mbed_official 579:53297373a894 370 /**
mbed_official 579:53297373a894 371 * \def likely(exp)
mbed_official 579:53297373a894 372 * \brief The expression \a exp is likely to be true
mbed_official 579:53297373a894 373 */
mbed_official 579:53297373a894 374 #if !defined(likely) || defined(__DOXYGEN__)
mbed_official 579:53297373a894 375 # define likely(exp) (exp)
mbed_official 579:53297373a894 376 #endif
mbed_official 579:53297373a894 377
mbed_official 579:53297373a894 378 /**
mbed_official 579:53297373a894 379 * \def unlikely(exp)
mbed_official 579:53297373a894 380 * \brief The expression \a exp is unlikely to be true
mbed_official 579:53297373a894 381 */
mbed_official 579:53297373a894 382 #if !defined(unlikely) || defined(__DOXYGEN__)
mbed_official 579:53297373a894 383 # define unlikely(exp) (exp)
mbed_official 579:53297373a894 384 #endif
mbed_official 579:53297373a894 385
mbed_official 579:53297373a894 386 /**
mbed_official 579:53297373a894 387 * \def is_constant(exp)
mbed_official 579:53297373a894 388 * \brief Determine if an expression evaluates to a constant value.
mbed_official 579:53297373a894 389 *
mbed_official 579:53297373a894 390 * \param[in] exp Any expression
mbed_official 579:53297373a894 391 *
mbed_official 579:53297373a894 392 * \return true if \a exp is constant, false otherwise.
mbed_official 579:53297373a894 393 */
mbed_official 579:53297373a894 394 #if (defined __GNUC__) || (defined __CC_ARM)
mbed_official 579:53297373a894 395 # define is_constant(exp) __builtin_constant_p(exp)
mbed_official 579:53297373a894 396 #else
mbed_official 579:53297373a894 397 # define is_constant(exp) (0)
mbed_official 579:53297373a894 398 #endif
mbed_official 579:53297373a894 399
mbed_official 579:53297373a894 400 /** @} */
mbed_official 579:53297373a894 401
mbed_official 579:53297373a894 402 /** \name Bit-Field Handling
mbed_official 579:53297373a894 403 * @{ */
mbed_official 579:53297373a894 404
mbed_official 579:53297373a894 405 /** \brief Reads the bits of a value specified by a given bit-mask.
mbed_official 579:53297373a894 406 *
mbed_official 579:53297373a894 407 * \param[in] value Value to read bits from.
mbed_official 579:53297373a894 408 * \param[in] mask Bit-mask indicating bits to read.
mbed_official 579:53297373a894 409 *
mbed_official 579:53297373a894 410 * \return Read bits.
mbed_official 579:53297373a894 411 */
mbed_official 579:53297373a894 412 #define Rd_bits( value, mask) ((value) & (mask))
mbed_official 579:53297373a894 413
mbed_official 579:53297373a894 414 /** \brief Writes the bits of a C lvalue specified by a given bit-mask.
mbed_official 579:53297373a894 415 *
mbed_official 579:53297373a894 416 * \param[in] lvalue C lvalue to write bits to.
mbed_official 579:53297373a894 417 * \param[in] mask Bit-mask indicating bits to write.
mbed_official 579:53297373a894 418 * \param[in] bits Bits to write.
mbed_official 579:53297373a894 419 *
mbed_official 579:53297373a894 420 * \return Resulting value with written bits.
mbed_official 579:53297373a894 421 */
mbed_official 579:53297373a894 422 #define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) |\
mbed_official 579:53297373a894 423 ((bits ) & (mask)))
mbed_official 579:53297373a894 424
mbed_official 579:53297373a894 425 /** \brief Tests the bits of a value specified by a given bit-mask.
mbed_official 579:53297373a894 426 *
mbed_official 579:53297373a894 427 * \param[in] value Value of which to test bits.
mbed_official 579:53297373a894 428 * \param[in] mask Bit-mask indicating bits to test.
mbed_official 579:53297373a894 429 *
mbed_official 579:53297373a894 430 * \return \c 1 if at least one of the tested bits is set, else \c 0.
mbed_official 579:53297373a894 431 */
mbed_official 579:53297373a894 432 #define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
mbed_official 579:53297373a894 433
mbed_official 579:53297373a894 434 /** \brief Clears the bits of a C lvalue specified by a given bit-mask.
mbed_official 579:53297373a894 435 *
mbed_official 579:53297373a894 436 * \param[in] lvalue C lvalue of which to clear bits.
mbed_official 579:53297373a894 437 * \param[in] mask Bit-mask indicating bits to clear.
mbed_official 579:53297373a894 438 *
mbed_official 579:53297373a894 439 * \return Resulting value with cleared bits.
mbed_official 579:53297373a894 440 */
mbed_official 579:53297373a894 441 #define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
mbed_official 579:53297373a894 442
mbed_official 579:53297373a894 443 /** \brief Sets the bits of a C lvalue specified by a given bit-mask.
mbed_official 579:53297373a894 444 *
mbed_official 579:53297373a894 445 * \param[in] lvalue C lvalue of which to set bits.
mbed_official 579:53297373a894 446 * \param[in] mask Bit-mask indicating bits to set.
mbed_official 579:53297373a894 447 *
mbed_official 579:53297373a894 448 * \return Resulting value with set bits.
mbed_official 579:53297373a894 449 */
mbed_official 579:53297373a894 450 #define Set_bits(lvalue, mask) ((lvalue) |= (mask))
mbed_official 579:53297373a894 451
mbed_official 579:53297373a894 452 /** \brief Toggles the bits of a C lvalue specified by a given bit-mask.
mbed_official 579:53297373a894 453 *
mbed_official 579:53297373a894 454 * \param[in] lvalue C lvalue of which to toggle bits.
mbed_official 579:53297373a894 455 * \param[in] mask Bit-mask indicating bits to toggle.
mbed_official 579:53297373a894 456 *
mbed_official 579:53297373a894 457 * \return Resulting value with toggled bits.
mbed_official 579:53297373a894 458 */
mbed_official 579:53297373a894 459 #define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
mbed_official 579:53297373a894 460
mbed_official 579:53297373a894 461 /** \brief Reads the bit-field of a value specified by a given bit-mask.
mbed_official 579:53297373a894 462 *
mbed_official 579:53297373a894 463 * \param[in] value Value to read a bit-field from.
mbed_official 579:53297373a894 464 * \param[in] mask Bit-mask indicating the bit-field to read.
mbed_official 579:53297373a894 465 *
mbed_official 579:53297373a894 466 * \return Read bit-field.
mbed_official 579:53297373a894 467 */
mbed_official 579:53297373a894 468 #define Rd_bitfield( value, mask) (Rd_bits( value, mask) >> ctz(mask))
mbed_official 579:53297373a894 469
mbed_official 579:53297373a894 470 /** \brief Writes the bit-field of a C lvalue specified by a given bit-mask.
mbed_official 579:53297373a894 471 *
mbed_official 579:53297373a894 472 * \param[in] lvalue C lvalue to write a bit-field to.
mbed_official 579:53297373a894 473 * \param[in] mask Bit-mask indicating the bit-field to write.
mbed_official 579:53297373a894 474 * \param[in] bitfield Bit-field to write.
mbed_official 579:53297373a894 475 *
mbed_official 579:53297373a894 476 * \return Resulting value with written bit-field.
mbed_official 579:53297373a894 477 */
mbed_official 579:53297373a894 478 #define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (uint32_t)(bitfield) << ctz(mask)))
mbed_official 579:53297373a894 479
mbed_official 579:53297373a894 480 /** @} */
mbed_official 579:53297373a894 481
mbed_official 579:53297373a894 482
mbed_official 579:53297373a894 483 /** \name Zero-Bit Counting
mbed_official 579:53297373a894 484 *
mbed_official 579:53297373a894 485 * Under GCC, __builtin_clz and __builtin_ctz behave like macros when
mbed_official 579:53297373a894 486 * applied to constant expressions (values known at compile time), so they are
mbed_official 579:53297373a894 487 * more optimized than the use of the corresponding assembly instructions and
mbed_official 579:53297373a894 488 * they can be used as constant expressions e.g. to initialize objects having
mbed_official 579:53297373a894 489 * static storage duration, and like the corresponding assembly instructions
mbed_official 579:53297373a894 490 * when applied to non-constant expressions (values unknown at compile time), so
mbed_official 579:53297373a894 491 * they are more optimized than an assembly periphrasis. Hence, clz and ctz
mbed_official 579:53297373a894 492 * ensure a possible and optimized behavior for both constant and non-constant
mbed_official 579:53297373a894 493 * expressions.
mbed_official 579:53297373a894 494 *
mbed_official 579:53297373a894 495 * @{ */
mbed_official 579:53297373a894 496
mbed_official 579:53297373a894 497 /** \brief Counts the leading zero bits of the given value considered as a 32-bit integer.
mbed_official 579:53297373a894 498 *
mbed_official 579:53297373a894 499 * \param[in] u Value of which to count the leading zero bits.
mbed_official 579:53297373a894 500 *
mbed_official 579:53297373a894 501 * \return The count of leading zero bits in \a u.
mbed_official 579:53297373a894 502 */
mbed_official 579:53297373a894 503 #if (defined __GNUC__) || (defined __CC_ARM)
mbed_official 579:53297373a894 504 # define clz(u) __builtin_clz(u)
mbed_official 579:53297373a894 505 #else
mbed_official 579:53297373a894 506 # define clz(u) (((u) == 0) ? 32 : \
mbed_official 579:53297373a894 507 ((u) & (1ul << 31)) ? 0 : \
mbed_official 579:53297373a894 508 ((u) & (1ul << 30)) ? 1 : \
mbed_official 579:53297373a894 509 ((u) & (1ul << 29)) ? 2 : \
mbed_official 579:53297373a894 510 ((u) & (1ul << 28)) ? 3 : \
mbed_official 579:53297373a894 511 ((u) & (1ul << 27)) ? 4 : \
mbed_official 579:53297373a894 512 ((u) & (1ul << 26)) ? 5 : \
mbed_official 579:53297373a894 513 ((u) & (1ul << 25)) ? 6 : \
mbed_official 579:53297373a894 514 ((u) & (1ul << 24)) ? 7 : \
mbed_official 579:53297373a894 515 ((u) & (1ul << 23)) ? 8 : \
mbed_official 579:53297373a894 516 ((u) & (1ul << 22)) ? 9 : \
mbed_official 579:53297373a894 517 ((u) & (1ul << 21)) ? 10 : \
mbed_official 579:53297373a894 518 ((u) & (1ul << 20)) ? 11 : \
mbed_official 579:53297373a894 519 ((u) & (1ul << 19)) ? 12 : \
mbed_official 579:53297373a894 520 ((u) & (1ul << 18)) ? 13 : \
mbed_official 579:53297373a894 521 ((u) & (1ul << 17)) ? 14 : \
mbed_official 579:53297373a894 522 ((u) & (1ul << 16)) ? 15 : \
mbed_official 579:53297373a894 523 ((u) & (1ul << 15)) ? 16 : \
mbed_official 579:53297373a894 524 ((u) & (1ul << 14)) ? 17 : \
mbed_official 579:53297373a894 525 ((u) & (1ul << 13)) ? 18 : \
mbed_official 579:53297373a894 526 ((u) & (1ul << 12)) ? 19 : \
mbed_official 579:53297373a894 527 ((u) & (1ul << 11)) ? 20 : \
mbed_official 579:53297373a894 528 ((u) & (1ul << 10)) ? 21 : \
mbed_official 579:53297373a894 529 ((u) & (1ul << 9)) ? 22 : \
mbed_official 579:53297373a894 530 ((u) & (1ul << 8)) ? 23 : \
mbed_official 579:53297373a894 531 ((u) & (1ul << 7)) ? 24 : \
mbed_official 579:53297373a894 532 ((u) & (1ul << 6)) ? 25 : \
mbed_official 579:53297373a894 533 ((u) & (1ul << 5)) ? 26 : \
mbed_official 579:53297373a894 534 ((u) & (1ul << 4)) ? 27 : \
mbed_official 579:53297373a894 535 ((u) & (1ul << 3)) ? 28 : \
mbed_official 579:53297373a894 536 ((u) & (1ul << 2)) ? 29 : \
mbed_official 579:53297373a894 537 ((u) & (1ul << 1)) ? 30 : \
mbed_official 579:53297373a894 538 31)
mbed_official 579:53297373a894 539 #endif
mbed_official 579:53297373a894 540
mbed_official 579:53297373a894 541 /** \brief Counts the trailing zero bits of the given value considered as a 32-bit integer.
mbed_official 579:53297373a894 542 *
mbed_official 579:53297373a894 543 * \param[in] u Value of which to count the trailing zero bits.
mbed_official 579:53297373a894 544 *
mbed_official 579:53297373a894 545 * \return The count of trailing zero bits in \a u.
mbed_official 579:53297373a894 546 */
mbed_official 579:53297373a894 547 #if (defined __GNUC__) || (defined __CC_ARM)
mbed_official 579:53297373a894 548 # define ctz(u) __builtin_ctz(u)
mbed_official 579:53297373a894 549 #else
mbed_official 579:53297373a894 550 # define ctz(u) ((u) & (1ul << 0) ? 0 : \
mbed_official 579:53297373a894 551 (u) & (1ul << 1) ? 1 : \
mbed_official 579:53297373a894 552 (u) & (1ul << 2) ? 2 : \
mbed_official 579:53297373a894 553 (u) & (1ul << 3) ? 3 : \
mbed_official 579:53297373a894 554 (u) & (1ul << 4) ? 4 : \
mbed_official 579:53297373a894 555 (u) & (1ul << 5) ? 5 : \
mbed_official 579:53297373a894 556 (u) & (1ul << 6) ? 6 : \
mbed_official 579:53297373a894 557 (u) & (1ul << 7) ? 7 : \
mbed_official 579:53297373a894 558 (u) & (1ul << 8) ? 8 : \
mbed_official 579:53297373a894 559 (u) & (1ul << 9) ? 9 : \
mbed_official 579:53297373a894 560 (u) & (1ul << 10) ? 10 : \
mbed_official 579:53297373a894 561 (u) & (1ul << 11) ? 11 : \
mbed_official 579:53297373a894 562 (u) & (1ul << 12) ? 12 : \
mbed_official 579:53297373a894 563 (u) & (1ul << 13) ? 13 : \
mbed_official 579:53297373a894 564 (u) & (1ul << 14) ? 14 : \
mbed_official 579:53297373a894 565 (u) & (1ul << 15) ? 15 : \
mbed_official 579:53297373a894 566 (u) & (1ul << 16) ? 16 : \
mbed_official 579:53297373a894 567 (u) & (1ul << 17) ? 17 : \
mbed_official 579:53297373a894 568 (u) & (1ul << 18) ? 18 : \
mbed_official 579:53297373a894 569 (u) & (1ul << 19) ? 19 : \
mbed_official 579:53297373a894 570 (u) & (1ul << 20) ? 20 : \
mbed_official 579:53297373a894 571 (u) & (1ul << 21) ? 21 : \
mbed_official 579:53297373a894 572 (u) & (1ul << 22) ? 22 : \
mbed_official 579:53297373a894 573 (u) & (1ul << 23) ? 23 : \
mbed_official 579:53297373a894 574 (u) & (1ul << 24) ? 24 : \
mbed_official 579:53297373a894 575 (u) & (1ul << 25) ? 25 : \
mbed_official 579:53297373a894 576 (u) & (1ul << 26) ? 26 : \
mbed_official 579:53297373a894 577 (u) & (1ul << 27) ? 27 : \
mbed_official 579:53297373a894 578 (u) & (1ul << 28) ? 28 : \
mbed_official 579:53297373a894 579 (u) & (1ul << 29) ? 29 : \
mbed_official 579:53297373a894 580 (u) & (1ul << 30) ? 30 : \
mbed_official 579:53297373a894 581 (u) & (1ul << 31) ? 31 : \
mbed_official 579:53297373a894 582 32)
mbed_official 579:53297373a894 583 #endif
mbed_official 579:53297373a894 584
mbed_official 579:53297373a894 585 /** @} */
mbed_official 579:53297373a894 586
mbed_official 579:53297373a894 587
mbed_official 579:53297373a894 588 /** \name Bit Reversing
mbed_official 579:53297373a894 589 * @{ */
mbed_official 579:53297373a894 590
mbed_official 579:53297373a894 591 /** \brief Reverses the bits of \a u8.
mbed_official 579:53297373a894 592 *
mbed_official 579:53297373a894 593 * \param[in] u8 U8 of which to reverse the bits.
mbed_official 579:53297373a894 594 *
mbed_official 579:53297373a894 595 * \return Value resulting from \a u8 with reversed bits.
mbed_official 579:53297373a894 596 */
mbed_official 579:53297373a894 597 #define bit_reverse8(u8) ((U8)(bit_reverse32((U8)(u8)) >> 24))
mbed_official 579:53297373a894 598
mbed_official 579:53297373a894 599 /** \brief Reverses the bits of \a u16.
mbed_official 579:53297373a894 600 *
mbed_official 579:53297373a894 601 * \param[in] u16 U16 of which to reverse the bits.
mbed_official 579:53297373a894 602 *
mbed_official 579:53297373a894 603 * \return Value resulting from \a u16 with reversed bits.
mbed_official 579:53297373a894 604 */
mbed_official 579:53297373a894 605 #define bit_reverse16(u16) ((uint16_t)(bit_reverse32((uint16_t)(u16)) >> 16))
mbed_official 579:53297373a894 606
mbed_official 579:53297373a894 607 /** \brief Reverses the bits of \a u32.
mbed_official 579:53297373a894 608 *
mbed_official 579:53297373a894 609 * \param[in] u32 U32 of which to reverse the bits.
mbed_official 579:53297373a894 610 *
mbed_official 579:53297373a894 611 * \return Value resulting from \a u32 with reversed bits.
mbed_official 579:53297373a894 612 */
mbed_official 579:53297373a894 613 #define bit_reverse32(u32) __RBIT(u32)
mbed_official 579:53297373a894 614
mbed_official 579:53297373a894 615 /** \brief Reverses the bits of \a u64.
mbed_official 579:53297373a894 616 *
mbed_official 579:53297373a894 617 * \param[in] u64 U64 of which to reverse the bits.
mbed_official 579:53297373a894 618 *
mbed_official 579:53297373a894 619 * \return Value resulting from \a u64 with reversed bits.
mbed_official 579:53297373a894 620 */
mbed_official 579:53297373a894 621 #define bit_reverse64(u64) ((uint64_t)(((uint64_t)bit_reverse32((uint64_t)(u64) >> 32)) |\
mbed_official 579:53297373a894 622 ((uint64_t)bit_reverse32((uint64_t)(u64)) << 32)))
mbed_official 579:53297373a894 623
mbed_official 579:53297373a894 624 /** @} */
mbed_official 579:53297373a894 625
mbed_official 579:53297373a894 626
mbed_official 579:53297373a894 627 /** \name Alignment
mbed_official 579:53297373a894 628 * @{ */
mbed_official 579:53297373a894 629
mbed_official 579:53297373a894 630 /** \brief Tests alignment of the number \a val with the \a n boundary.
mbed_official 579:53297373a894 631 *
mbed_official 579:53297373a894 632 * \param[in] val Input value.
mbed_official 579:53297373a894 633 * \param[in] n Boundary.
mbed_official 579:53297373a894 634 *
mbed_official 579:53297373a894 635 * \return \c 1 if the number \a val is aligned with the \a n boundary, else \c 0.
mbed_official 579:53297373a894 636 */
mbed_official 579:53297373a894 637 #define Test_align(val, n) (!Tst_bits( val, (n) - 1 ) )
mbed_official 579:53297373a894 638
mbed_official 579:53297373a894 639 /** \brief Gets alignment of the number \a val with respect to the \a n boundary.
mbed_official 579:53297373a894 640 *
mbed_official 579:53297373a894 641 * \param[in] val Input value.
mbed_official 579:53297373a894 642 * \param[in] n Boundary.
mbed_official 579:53297373a894 643 *
mbed_official 579:53297373a894 644 * \return Alignment of the number \a val with respect to the \a n boundary.
mbed_official 579:53297373a894 645 */
mbed_official 579:53297373a894 646 #define Get_align(val, n) ( Rd_bits( val, (n) - 1 ) )
mbed_official 579:53297373a894 647
mbed_official 579:53297373a894 648 /** \brief Sets alignment of the lvalue number \a lval to \a alg with respect to the \a n boundary.
mbed_official 579:53297373a894 649 *
mbed_official 579:53297373a894 650 * \param[in] lval Input/output lvalue.
mbed_official 579:53297373a894 651 * \param[in] n Boundary.
mbed_official 579:53297373a894 652 * \param[in] alg Alignment.
mbed_official 579:53297373a894 653 *
mbed_official 579:53297373a894 654 * \return New value of \a lval resulting from its alignment set to \a alg with respect to the \a n boundary.
mbed_official 579:53297373a894 655 */
mbed_official 579:53297373a894 656 #define Set_align(lval, n, alg) ( Wr_bits(lval, (n) - 1, alg) )
mbed_official 579:53297373a894 657
mbed_official 579:53297373a894 658 /** \brief Aligns the number \a val with the upper \a n boundary.
mbed_official 579:53297373a894 659 *
mbed_official 579:53297373a894 660 * \param[in] val Input value.
mbed_official 579:53297373a894 661 * \param[in] n Boundary.
mbed_official 579:53297373a894 662 *
mbed_official 579:53297373a894 663 * \return Value resulting from the number \a val aligned with the upper \a n boundary.
mbed_official 579:53297373a894 664 */
mbed_official 579:53297373a894 665 #define Align_up( val, n) (((val) + ((n) - 1)) & ~((n) - 1))
mbed_official 579:53297373a894 666
mbed_official 579:53297373a894 667 /** \brief Aligns the number \a val with the lower \a n boundary.
mbed_official 579:53297373a894 668 *
mbed_official 579:53297373a894 669 * \param[in] val Input value.
mbed_official 579:53297373a894 670 * \param[in] n Boundary.
mbed_official 579:53297373a894 671 *
mbed_official 579:53297373a894 672 * \return Value resulting from the number \a val aligned with the lower \a n boundary.
mbed_official 579:53297373a894 673 */
mbed_official 579:53297373a894 674 #define Align_down(val, n) ( (val) & ~((n) - 1))
mbed_official 579:53297373a894 675
mbed_official 579:53297373a894 676 /** @} */
mbed_official 579:53297373a894 677
mbed_official 579:53297373a894 678
mbed_official 579:53297373a894 679 /** \name Mathematics
mbed_official 579:53297373a894 680 *
mbed_official 579:53297373a894 681 * The same considerations as for clz and ctz apply here but GCC does not
mbed_official 579:53297373a894 682 * provide built-in functions to access the assembly instructions abs, min and
mbed_official 579:53297373a894 683 * max and it does not produce them by itself in most cases, so two sets of
mbed_official 579:53297373a894 684 * macros are defined here:
mbed_official 579:53297373a894 685 * - Abs, Min and Max to apply to constant expressions (values known at
mbed_official 579:53297373a894 686 * compile time);
mbed_official 579:53297373a894 687 * - abs, min and max to apply to non-constant expressions (values unknown at
mbed_official 579:53297373a894 688 * compile time), abs is found in stdlib.h.
mbed_official 579:53297373a894 689 *
mbed_official 579:53297373a894 690 * @{ */
mbed_official 579:53297373a894 691
mbed_official 579:53297373a894 692 /** \brief Takes the absolute value of \a a.
mbed_official 579:53297373a894 693 *
mbed_official 579:53297373a894 694 * \param[in] a Input value.
mbed_official 579:53297373a894 695 *
mbed_official 579:53297373a894 696 * \return Absolute value of \a a.
mbed_official 579:53297373a894 697 *
mbed_official 579:53297373a894 698 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 699 */
mbed_official 579:53297373a894 700 #define Abs(a) (((a) < 0 ) ? -(a) : (a))
mbed_official 579:53297373a894 701
mbed_official 579:53297373a894 702 /** \brief Takes the minimal value of \a a and \a b.
mbed_official 579:53297373a894 703 *
mbed_official 579:53297373a894 704 * \param[in] a Input value.
mbed_official 579:53297373a894 705 * \param[in] b Input value.
mbed_official 579:53297373a894 706 *
mbed_official 579:53297373a894 707 * \return Minimal value of \a a and \a b.
mbed_official 579:53297373a894 708 *
mbed_official 579:53297373a894 709 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 710 */
mbed_official 579:53297373a894 711 #define Min(a, b) (((a) < (b)) ? (a) : (b))
mbed_official 579:53297373a894 712
mbed_official 579:53297373a894 713 /** \brief Takes the maximal value of \a a and \a b.
mbed_official 579:53297373a894 714 *
mbed_official 579:53297373a894 715 * \param[in] a Input value.
mbed_official 579:53297373a894 716 * \param[in] b Input value.
mbed_official 579:53297373a894 717 *
mbed_official 579:53297373a894 718 * \return Maximal value of \a a and \a b.
mbed_official 579:53297373a894 719 *
mbed_official 579:53297373a894 720 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 721 */
mbed_official 579:53297373a894 722 #define Max(a, b) (((a) > (b)) ? (a) : (b))
mbed_official 579:53297373a894 723
mbed_official 579:53297373a894 724 /** \brief Takes the minimal value of \a a and \a b.
mbed_official 579:53297373a894 725 *
mbed_official 579:53297373a894 726 * \param[in] a Input value.
mbed_official 579:53297373a894 727 * \param[in] b Input value.
mbed_official 579:53297373a894 728 *
mbed_official 579:53297373a894 729 * \return Minimal value of \a a and \a b.
mbed_official 579:53297373a894 730 *
mbed_official 579:53297373a894 731 * \note More optimized if only used with values unknown at compile time.
mbed_official 579:53297373a894 732 */
mbed_official 579:53297373a894 733 #define min(a, b) Min(a, b)
mbed_official 579:53297373a894 734
mbed_official 579:53297373a894 735 /** \brief Takes the maximal value of \a a and \a b.
mbed_official 579:53297373a894 736 *
mbed_official 579:53297373a894 737 * \param[in] a Input value.
mbed_official 579:53297373a894 738 * \param[in] b Input value.
mbed_official 579:53297373a894 739 *
mbed_official 579:53297373a894 740 * \return Maximal value of \a a and \a b.
mbed_official 579:53297373a894 741 *
mbed_official 579:53297373a894 742 * \note More optimized if only used with values unknown at compile time.
mbed_official 579:53297373a894 743 */
mbed_official 579:53297373a894 744 #define max(a, b) Max(a, b)
mbed_official 579:53297373a894 745
mbed_official 579:53297373a894 746 /** @} */
mbed_official 579:53297373a894 747
mbed_official 579:53297373a894 748
mbed_official 579:53297373a894 749 /** \brief Calls the routine at address \a addr.
mbed_official 579:53297373a894 750 *
mbed_official 579:53297373a894 751 * It generates a long call opcode.
mbed_official 579:53297373a894 752 *
mbed_official 579:53297373a894 753 * For example, `Long_call(0x80000000)' generates a software reset on a UC3 if
mbed_official 579:53297373a894 754 * it is invoked from the CPU supervisor mode.
mbed_official 579:53297373a894 755 *
mbed_official 579:53297373a894 756 * \param[in] addr Address of the routine to call.
mbed_official 579:53297373a894 757 *
mbed_official 579:53297373a894 758 * \note It may be used as a long jump opcode in some special cases.
mbed_official 579:53297373a894 759 */
mbed_official 579:53297373a894 760 #define Long_call(addr) ((*(void (*)(void))(addr))())
mbed_official 579:53297373a894 761
mbed_official 579:53297373a894 762
mbed_official 579:53297373a894 763 /** \name MCU Endianism Handling
mbed_official 579:53297373a894 764 * ARM is MCU little endian.
mbed_official 579:53297373a894 765 *
mbed_official 579:53297373a894 766 * @{ */
mbed_official 579:53297373a894 767 #define BE16(x) Swap16(x)
mbed_official 579:53297373a894 768 #define LE16(x) (x)
mbed_official 579:53297373a894 769
mbed_official 579:53297373a894 770 #define le16_to_cpu(x) (x)
mbed_official 579:53297373a894 771 #define cpu_to_le16(x) (x)
mbed_official 579:53297373a894 772 #define LE16_TO_CPU(x) (x)
mbed_official 579:53297373a894 773 #define CPU_TO_LE16(x) (x)
mbed_official 579:53297373a894 774
mbed_official 579:53297373a894 775 #define be16_to_cpu(x) Swap16(x)
mbed_official 579:53297373a894 776 #define cpu_to_be16(x) Swap16(x)
mbed_official 579:53297373a894 777 #define BE16_TO_CPU(x) Swap16(x)
mbed_official 579:53297373a894 778 #define CPU_TO_BE16(x) Swap16(x)
mbed_official 579:53297373a894 779
mbed_official 579:53297373a894 780 #define le32_to_cpu(x) (x)
mbed_official 579:53297373a894 781 #define cpu_to_le32(x) (x)
mbed_official 579:53297373a894 782 #define LE32_TO_CPU(x) (x)
mbed_official 579:53297373a894 783 #define CPU_TO_LE32(x) (x)
mbed_official 579:53297373a894 784
mbed_official 579:53297373a894 785 #define be32_to_cpu(x) swap32(x)
mbed_official 579:53297373a894 786 #define cpu_to_be32(x) swap32(x)
mbed_official 579:53297373a894 787 #define BE32_TO_CPU(x) swap32(x)
mbed_official 579:53297373a894 788 #define CPU_TO_BE32(x) swap32(x)
mbed_official 579:53297373a894 789 /** @} */
mbed_official 579:53297373a894 790
mbed_official 579:53297373a894 791
mbed_official 579:53297373a894 792 /** \name Endianism Conversion
mbed_official 579:53297373a894 793 *
mbed_official 579:53297373a894 794 * The same considerations as for clz and ctz apply here but GCC's
mbed_official 579:53297373a894 795 * __builtin_bswap_32 and __builtin_bswap_64 do not behave like macros when
mbed_official 579:53297373a894 796 * applied to constant expressions, so two sets of macros are defined here:
mbed_official 579:53297373a894 797 * - Swap16, Swap32 and Swap64 to apply to constant expressions (values known
mbed_official 579:53297373a894 798 * at compile time);
mbed_official 579:53297373a894 799 * - swap16, swap32 and swap64 to apply to non-constant expressions (values
mbed_official 579:53297373a894 800 * unknown at compile time).
mbed_official 579:53297373a894 801 *
mbed_official 579:53297373a894 802 * @{ */
mbed_official 579:53297373a894 803
mbed_official 579:53297373a894 804 /** \brief Toggles the endianism of \a u16 (by swapping its bytes).
mbed_official 579:53297373a894 805 *
mbed_official 579:53297373a894 806 * \param[in] u16 U16 of which to toggle the endianism.
mbed_official 579:53297373a894 807 *
mbed_official 579:53297373a894 808 * \return Value resulting from \a u16 with toggled endianism.
mbed_official 579:53297373a894 809 *
mbed_official 579:53297373a894 810 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 811 */
mbed_official 579:53297373a894 812 #define Swap16(u16) ((uint16_t)(((uint16_t)(u16) >> 8) |\
mbed_official 579:53297373a894 813 ((uint16_t)(u16) << 8)))
mbed_official 579:53297373a894 814
mbed_official 579:53297373a894 815 /** \brief Toggles the endianism of \a u32 (by swapping its bytes).
mbed_official 579:53297373a894 816 *
mbed_official 579:53297373a894 817 * \param[in] u32 U32 of which to toggle the endianism.
mbed_official 579:53297373a894 818 *
mbed_official 579:53297373a894 819 * \return Value resulting from \a u32 with toggled endianism.
mbed_official 579:53297373a894 820 *
mbed_official 579:53297373a894 821 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 822 */
mbed_official 579:53297373a894 823 #define Swap32(u32) ((uint32_t)(((uint32_t)Swap16((uint32_t)(u32) >> 16)) |\
mbed_official 579:53297373a894 824 ((uint32_t)Swap16((uint32_t)(u32)) << 16)))
mbed_official 579:53297373a894 825
mbed_official 579:53297373a894 826 /** \brief Toggles the endianism of \a u64 (by swapping its bytes).
mbed_official 579:53297373a894 827 *
mbed_official 579:53297373a894 828 * \param[in] u64 U64 of which to toggle the endianism.
mbed_official 579:53297373a894 829 *
mbed_official 579:53297373a894 830 * \return Value resulting from \a u64 with toggled endianism.
mbed_official 579:53297373a894 831 *
mbed_official 579:53297373a894 832 * \note More optimized if only used with values known at compile time.
mbed_official 579:53297373a894 833 */
mbed_official 579:53297373a894 834 #define Swap64(u64) ((uint64_t)(((uint64_t)Swap32((uint64_t)(u64) >> 32)) |\
mbed_official 579:53297373a894 835 ((uint64_t)Swap32((uint64_t)(u64)) << 32)))
mbed_official 579:53297373a894 836
mbed_official 579:53297373a894 837 /** \brief Toggles the endianism of \a u16 (by swapping its bytes).
mbed_official 579:53297373a894 838 *
mbed_official 579:53297373a894 839 * \param[in] u16 U16 of which to toggle the endianism.
mbed_official 579:53297373a894 840 *
mbed_official 579:53297373a894 841 * \return Value resulting from \a u16 with toggled endianism.
mbed_official 579:53297373a894 842 *
mbed_official 579:53297373a894 843 * \note More optimized if only used with values unknown at compile time.
mbed_official 579:53297373a894 844 */
mbed_official 579:53297373a894 845 #define swap16(u16) Swap16(u16)
mbed_official 579:53297373a894 846
mbed_official 579:53297373a894 847 /** \brief Toggles the endianism of \a u32 (by swapping its bytes).
mbed_official 579:53297373a894 848 *
mbed_official 579:53297373a894 849 * \param[in] u32 U32 of which to toggle the endianism.
mbed_official 579:53297373a894 850 *
mbed_official 579:53297373a894 851 * \return Value resulting from \a u32 with toggled endianism.
mbed_official 579:53297373a894 852 *
mbed_official 579:53297373a894 853 * \note More optimized if only used with values unknown at compile time.
mbed_official 579:53297373a894 854 */
mbed_official 579:53297373a894 855 #if (defined __GNUC__)
mbed_official 579:53297373a894 856 # define swap32(u32) ((uint32_t)__builtin_bswap32((uint32_t)(u32)))
mbed_official 579:53297373a894 857 #else
mbed_official 579:53297373a894 858 # define swap32(u32) Swap32(u32)
mbed_official 579:53297373a894 859 #endif
mbed_official 579:53297373a894 860
mbed_official 579:53297373a894 861 /** \brief Toggles the endianism of \a u64 (by swapping its bytes).
mbed_official 579:53297373a894 862 *
mbed_official 579:53297373a894 863 * \param[in] u64 U64 of which to toggle the endianism.
mbed_official 579:53297373a894 864 *
mbed_official 579:53297373a894 865 * \return Value resulting from \a u64 with toggled endianism.
mbed_official 579:53297373a894 866 *
mbed_official 579:53297373a894 867 * \note More optimized if only used with values unknown at compile time.
mbed_official 579:53297373a894 868 */
mbed_official 579:53297373a894 869 #if (defined __GNUC__)
mbed_official 579:53297373a894 870 # define swap64(u64) ((uint64_t)__builtin_bswap64((uint64_t)(u64)))
mbed_official 579:53297373a894 871 #else
mbed_official 579:53297373a894 872 # define swap64(u64) ((uint64_t)(((uint64_t)swap32((uint64_t)(u64) >> 32)) |\
mbed_official 579:53297373a894 873 ((uint64_t)swap32((uint64_t)(u64)) << 32)))
mbed_official 579:53297373a894 874 #endif
mbed_official 579:53297373a894 875
mbed_official 579:53297373a894 876 /** @} */
mbed_official 579:53297373a894 877
mbed_official 579:53297373a894 878
mbed_official 579:53297373a894 879 /** \name Target Abstraction
mbed_official 579:53297373a894 880 *
mbed_official 579:53297373a894 881 * @{ */
mbed_official 579:53297373a894 882
mbed_official 579:53297373a894 883 #define _GLOBEXT_ extern /**< extern storage-class specifier. */
mbed_official 579:53297373a894 884 #define _CONST_TYPE_ const /**< const type qualifier. */
mbed_official 579:53297373a894 885 #define _MEM_TYPE_SLOW_ /**< Slow memory type. */
mbed_official 579:53297373a894 886 #define _MEM_TYPE_MEDFAST_ /**< Fairly fast memory type. */
mbed_official 579:53297373a894 887 #define _MEM_TYPE_FAST_ /**< Fast memory type. */
mbed_official 579:53297373a894 888
mbed_official 579:53297373a894 889 #define memcmp_ram2ram memcmp /**< Target-specific memcmp of RAM to RAM. */
mbed_official 579:53297373a894 890 #define memcmp_code2ram memcmp /**< Target-specific memcmp of RAM to NVRAM. */
mbed_official 579:53297373a894 891 #define memcpy_ram2ram memcpy /**< Target-specific memcpy from RAM to RAM. */
mbed_official 579:53297373a894 892 #define memcpy_code2ram memcpy /**< Target-specific memcpy from NVRAM to RAM. */
mbed_official 579:53297373a894 893
mbed_official 579:53297373a894 894 /** @} */
mbed_official 579:53297373a894 895
mbed_official 579:53297373a894 896 /**
mbed_official 579:53297373a894 897 * \brief Calculate \f$ \left\lceil \frac{a}{b} \right\rceil \f$ using
mbed_official 579:53297373a894 898 * integer arithmetic.
mbed_official 579:53297373a894 899 *
mbed_official 579:53297373a894 900 * \param[in] a An integer
mbed_official 579:53297373a894 901 * \param[in] b Another integer
mbed_official 579:53297373a894 902 *
mbed_official 579:53297373a894 903 * \return (\a a / \a b) rounded up to the nearest integer.
mbed_official 579:53297373a894 904 */
mbed_official 579:53297373a894 905 #define div_ceil(a, b) (((a) + (b) - 1) / (b))
mbed_official 579:53297373a894 906
mbed_official 579:53297373a894 907 #endif /* #ifndef __ASSEMBLY__ */
mbed_official 579:53297373a894 908 #ifdef __ICCARM__
mbed_official 579:53297373a894 909 /** \name Compiler Keywords
mbed_official 579:53297373a894 910 *
mbed_official 579:53297373a894 911 * Port of some keywords from GCC to IAR Embedded Workbench.
mbed_official 579:53297373a894 912 *
mbed_official 579:53297373a894 913 * @{ */
mbed_official 579:53297373a894 914
mbed_official 579:53297373a894 915 #define __asm__ asm
mbed_official 579:53297373a894 916 #define __inline__ inline
mbed_official 579:53297373a894 917 #define __volatile__
mbed_official 579:53297373a894 918
mbed_official 579:53297373a894 919 /** @} */
mbed_official 579:53297373a894 920
mbed_official 579:53297373a894 921 #endif
mbed_official 579:53297373a894 922
mbed_official 579:53297373a894 923 #define FUNC_PTR void *
mbed_official 579:53297373a894 924 /**
mbed_official 579:53297373a894 925 * \def unused
mbed_official 579:53297373a894 926 * \brief Marking \a v as a unused parameter or value.
mbed_official 579:53297373a894 927 */
mbed_official 579:53297373a894 928 #define unused(v) do { (void)(v); } while(0)
mbed_official 579:53297373a894 929
mbed_official 579:53297373a894 930 /* Define RAMFUNC attribute */
mbed_official 579:53297373a894 931 #if defined ( __CC_ARM ) /* Keil uVision 4 */
mbed_official 579:53297373a894 932 # define RAMFUNC __attribute__ ((section(".ramfunc")))
mbed_official 579:53297373a894 933 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
mbed_official 579:53297373a894 934 # define RAMFUNC __ramfunc
mbed_official 579:53297373a894 935 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
mbed_official 579:53297373a894 936 # define RAMFUNC __attribute__ ((section(".ramfunc")))
mbed_official 579:53297373a894 937 #endif
mbed_official 579:53297373a894 938
mbed_official 579:53297373a894 939 /* Define OPTIMIZE_HIGH attribute */
mbed_official 579:53297373a894 940 #if defined ( __CC_ARM ) /* Keil uVision 4 */
mbed_official 579:53297373a894 941 # define OPTIMIZE_HIGH _Pragma("O3")
mbed_official 579:53297373a894 942 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
mbed_official 579:53297373a894 943 # define OPTIMIZE_HIGH _Pragma("optimize=high")
mbed_official 579:53297373a894 944 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
mbed_official 579:53297373a894 945 # define OPTIMIZE_HIGH __attribute__((optimize(s)))
mbed_official 579:53297373a894 946 #endif
mbed_official 579:53297373a894 947 #define PASS 0
mbed_official 579:53297373a894 948 #define FAIL 1
mbed_official 579:53297373a894 949 #define LOW 0
mbed_official 579:53297373a894 950 #define HIGH 1
mbed_official 579:53297373a894 951
mbed_official 579:53297373a894 952 typedef int8_t S8 ; //!< 8-bit signed integer.
mbed_official 579:53297373a894 953 typedef uint8_t U8 ; //!< 8-bit unsigned integer.
mbed_official 579:53297373a894 954 typedef int16_t S16; //!< 16-bit signed integer.
mbed_official 579:53297373a894 955 typedef uint16_t U16; //!< 16-bit unsigned integer.
mbed_official 579:53297373a894 956 typedef int32_t S32; //!< 32-bit signed integer.
mbed_official 579:53297373a894 957 typedef uint32_t U32; //!< 32-bit unsigned integer.
mbed_official 579:53297373a894 958 typedef int64_t S64; //!< 64-bit signed integer.
mbed_official 579:53297373a894 959 typedef uint64_t U64; //!< 64-bit unsigned integer.
mbed_official 579:53297373a894 960 typedef float F32; //!< 32-bit floating-point number.
mbed_official 579:53297373a894 961 typedef double F64; //!< 64-bit floating-point number.
mbed_official 579:53297373a894 962
mbed_official 579:53297373a894 963 #define MSB(u16) (((U8 *)&(u16))[1]) //!< Most significant byte of \a u16.
mbed_official 579:53297373a894 964 #define LSB(u16) (((U8 *)&(u16))[0]) //!< Least significant byte of \a u16.
mbed_official 579:53297373a894 965
mbed_official 579:53297373a894 966 #define MSH(u32) (((U16 *)&(u32))[1]) //!< Most significant half-word of \a u32.
mbed_official 579:53297373a894 967 #define LSH(u32) (((U16 *)&(u32))[0]) //!< Least significant half-word of \a u32.
mbed_official 579:53297373a894 968 #define MSB0W(u32) (((U8 *)&(u32))[3]) //!< Most significant byte of 1st rank of \a u32.
mbed_official 579:53297373a894 969 #define MSB1W(u32) (((U8 *)&(u32))[2]) //!< Most significant byte of 2nd rank of \a u32.
mbed_official 579:53297373a894 970 #define MSB2W(u32) (((U8 *)&(u32))[1]) //!< Most significant byte of 3rd rank of \a u32.
mbed_official 579:53297373a894 971 #define MSB3W(u32) (((U8 *)&(u32))[0]) //!< Most significant byte of 4th rank of \a u32.
mbed_official 579:53297373a894 972 #define LSB3W(u32) MSB0W(u32) //!< Least significant byte of 4th rank of \a u32.
mbed_official 579:53297373a894 973 #define LSB2W(u32) MSB1W(u32) //!< Least significant byte of 3rd rank of \a u32.
mbed_official 579:53297373a894 974 #define LSB1W(u32) MSB2W(u32) //!< Least significant byte of 2nd rank of \a u32.
mbed_official 579:53297373a894 975 #define LSB0W(u32) MSB3W(u32) //!< Least significant byte of 1st rank of \a u32.
mbed_official 579:53297373a894 976
mbed_official 579:53297373a894 977 #define MSW(u64) (((U32 *)&(u64))[1]) //!< Most significant word of \a u64.
mbed_official 579:53297373a894 978 #define LSW(u64) (((U32 *)&(u64))[0]) //!< Least significant word of \a u64.
mbed_official 579:53297373a894 979 #define MSH0(u64) (((U16 *)&(u64))[3]) //!< Most significant half-word of 1st rank of \a u64.
mbed_official 579:53297373a894 980 #define MSH1(u64) (((U16 *)&(u64))[2]) //!< Most significant half-word of 2nd rank of \a u64.
mbed_official 579:53297373a894 981 #define MSH2(u64) (((U16 *)&(u64))[1]) //!< Most significant half-word of 3rd rank of \a u64.
mbed_official 579:53297373a894 982 #define MSH3(u64) (((U16 *)&(u64))[0]) //!< Most significant half-word of 4th rank of \a u64.
mbed_official 579:53297373a894 983 #define LSH3(u64) MSH0(u64) //!< Least significant half-word of 4th rank of \a u64.
mbed_official 579:53297373a894 984 #define LSH2(u64) MSH1(u64) //!< Least significant half-word of 3rd rank of \a u64.
mbed_official 579:53297373a894 985 #define LSH1(u64) MSH2(u64) //!< Least significant half-word of 2nd rank of \a u64.
mbed_official 579:53297373a894 986 #define LSH0(u64) MSH3(u64) //!< Least significant half-word of 1st rank of \a u64.
mbed_official 579:53297373a894 987 #define MSB0D(u64) (((U8 *)&(u64))[7]) //!< Most significant byte of 1st rank of \a u64.
mbed_official 579:53297373a894 988 #define MSB1D(u64) (((U8 *)&(u64))[6]) //!< Most significant byte of 2nd rank of \a u64.
mbed_official 579:53297373a894 989 #define MSB2D(u64) (((U8 *)&(u64))[5]) //!< Most significant byte of 3rd rank of \a u64.
mbed_official 579:53297373a894 990 #define MSB3D(u64) (((U8 *)&(u64))[4]) //!< Most significant byte of 4th rank of \a u64.
mbed_official 579:53297373a894 991 #define MSB4D(u64) (((U8 *)&(u64))[3]) //!< Most significant byte of 5th rank of \a u64.
mbed_official 579:53297373a894 992 #define MSB5D(u64) (((U8 *)&(u64))[2]) //!< Most significant byte of 6th rank of \a u64.
mbed_official 579:53297373a894 993 #define MSB6D(u64) (((U8 *)&(u64))[1]) //!< Most significant byte of 7th rank of \a u64.
mbed_official 579:53297373a894 994 #define MSB7D(u64) (((U8 *)&(u64))[0]) //!< Most significant byte of 8th rank of \a u64.
mbed_official 579:53297373a894 995 #define LSB7D(u64) MSB0D(u64) //!< Least significant byte of 8th rank of \a u64.
mbed_official 579:53297373a894 996 #define LSB6D(u64) MSB1D(u64) //!< Least significant byte of 7th rank of \a u64.
mbed_official 579:53297373a894 997 #define LSB5D(u64) MSB2D(u64) //!< Least significant byte of 6th rank of \a u64.
mbed_official 579:53297373a894 998 #define LSB4D(u64) MSB3D(u64) //!< Least significant byte of 5th rank of \a u64.
mbed_official 579:53297373a894 999 #define LSB3D(u64) MSB4D(u64) //!< Least significant byte of 4th rank of \a u64.
mbed_official 579:53297373a894 1000 #define LSB2D(u64) MSB5D(u64) //!< Least significant byte of 3rd rank of \a u64.
mbed_official 579:53297373a894 1001 #define LSB1D(u64) MSB6D(u64) //!< Least significant byte of 2nd rank of \a u64.
mbed_official 579:53297373a894 1002 #define LSB0D(u64) MSB7D(u64) //!< Least significant byte of 1st rank of \a u64.
mbed_official 579:53297373a894 1003
mbed_official 579:53297373a894 1004 #define LSB0(u32) LSB0W(u32) //!< Least significant byte of 1st rank of \a u32.
mbed_official 579:53297373a894 1005 #define LSB1(u32) LSB1W(u32) //!< Least significant byte of 2nd rank of \a u32.
mbed_official 579:53297373a894 1006 #define LSB2(u32) LSB2W(u32) //!< Least significant byte of 3rd rank of \a u32.
mbed_official 579:53297373a894 1007 #define LSB3(u32) LSB3W(u32) //!< Least significant byte of 4th rank of \a u32.
mbed_official 579:53297373a894 1008 #define MSB3(u32) MSB3W(u32) //!< Most significant byte of 4th rank of \a u32.
mbed_official 579:53297373a894 1009 #define MSB2(u32) MSB2W(u32) //!< Most significant byte of 3rd rank of \a u32.
mbed_official 579:53297373a894 1010 #define MSB1(u32) MSB1W(u32) //!< Most significant byte of 2nd rank of \a u32.
mbed_official 579:53297373a894 1011 #define MSB0(u32) MSB0W(u32) //!< Most significant byte of 1st rank of \a u32.
mbed_official 579:53297373a894 1012
mbed_official 579:53297373a894 1013 #if defined(__ICCARM__)
mbed_official 579:53297373a894 1014 #define SHORTENUM __packed
mbed_official 579:53297373a894 1015 #elif defined(__GNUC__)
mbed_official 579:53297373a894 1016 #define SHORTENUM __attribute__((packed))
mbed_official 579:53297373a894 1017 #endif
mbed_official 579:53297373a894 1018
mbed_official 579:53297373a894 1019 /* No operation */
mbed_official 579:53297373a894 1020 #if defined(__ICCARM__)
mbed_official 579:53297373a894 1021 #define nop() __no_operation()
mbed_official 579:53297373a894 1022 #elif defined(__GNUC__)
mbed_official 579:53297373a894 1023 #define nop() (__NOP())
mbed_official 579:53297373a894 1024 #endif
mbed_official 579:53297373a894 1025
mbed_official 579:53297373a894 1026 #define FLASH_DECLARE(x) const x
mbed_official 579:53297373a894 1027 #define FLASH_EXTERN(x) extern const x
mbed_official 579:53297373a894 1028 #define PGM_READ_BYTE(x) *(x)
mbed_official 579:53297373a894 1029 #define PGM_READ_WORD(x) *(x)
mbed_official 579:53297373a894 1030 #define MEMCPY_ENDIAN memcpy
mbed_official 579:53297373a894 1031 #define PGM_READ_BLOCK(dst, src, len) memcpy((dst), (src), (len))
mbed_official 579:53297373a894 1032
mbed_official 579:53297373a894 1033 /*Defines the Flash Storage for the request and response of MAC*/
mbed_official 579:53297373a894 1034 #define CMD_ID_OCTET (0)
mbed_official 579:53297373a894 1035
mbed_official 579:53297373a894 1036 /* Converting of values from CPU endian to little endian. */
mbed_official 579:53297373a894 1037 #define CPU_ENDIAN_TO_LE16(x) (x)
mbed_official 579:53297373a894 1038 #define CPU_ENDIAN_TO_LE32(x) (x)
mbed_official 579:53297373a894 1039 #define CPU_ENDIAN_TO_LE64(x) (x)
mbed_official 579:53297373a894 1040
mbed_official 579:53297373a894 1041 /* Converting of values from little endian to CPU endian. */
mbed_official 579:53297373a894 1042 #define LE16_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1043 #define LE32_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1044 #define LE64_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1045
mbed_official 579:53297373a894 1046 /* Converting of constants from little endian to CPU endian. */
mbed_official 579:53297373a894 1047 #define CLE16_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1048 #define CLE32_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1049 #define CLE64_TO_CPU_ENDIAN(x) (x)
mbed_official 579:53297373a894 1050
mbed_official 579:53297373a894 1051 /* Converting of constants from CPU endian to little endian. */
mbed_official 579:53297373a894 1052 #define CCPU_ENDIAN_TO_LE16(x) (x)
mbed_official 579:53297373a894 1053 #define CCPU_ENDIAN_TO_LE32(x) (x)
mbed_official 579:53297373a894 1054 #define CCPU_ENDIAN_TO_LE64(x) (x)
mbed_official 579:53297373a894 1055
mbed_official 579:53297373a894 1056 #define ADDR_COPY_DST_SRC_16(dst, src) ((dst) = (src))
mbed_official 579:53297373a894 1057 #define ADDR_COPY_DST_SRC_64(dst, src) ((dst) = (src))
mbed_official 579:53297373a894 1058
mbed_official 579:53297373a894 1059 /**
mbed_official 579:53297373a894 1060 * @brief Converts a 64-Bit value into a 8 Byte array
mbed_official 579:53297373a894 1061 *
mbed_official 579:53297373a894 1062 * @param[in] value 64-Bit value
mbed_official 579:53297373a894 1063 * @param[out] data Pointer to the 8 Byte array to be updated with 64-Bit value
mbed_official 579:53297373a894 1064 * @ingroup apiPalApi
mbed_official 579:53297373a894 1065 */
mbed_official 579:53297373a894 1066 static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
mbed_official 579:53297373a894 1067 {
mbed_official 579:53297373a894 1068 uint8_t index = 0;
mbed_official 579:53297373a894 1069
mbed_official 579:53297373a894 1070 while (index < 8) {
mbed_official 579:53297373a894 1071 data[index++] = value & 0xFF;
mbed_official 579:53297373a894 1072 value = value >> 8;
mbed_official 579:53297373a894 1073 }
mbed_official 579:53297373a894 1074 }
mbed_official 579:53297373a894 1075
mbed_official 579:53297373a894 1076 /**
mbed_official 579:53297373a894 1077 * @brief Converts a 16-Bit value into a 2 Byte array
mbed_official 579:53297373a894 1078 *
mbed_official 579:53297373a894 1079 * @param[in] value 16-Bit value
mbed_official 579:53297373a894 1080 * @param[out] data Pointer to the 2 Byte array to be updated with 16-Bit value
mbed_official 579:53297373a894 1081 * @ingroup apiPalApi
mbed_official 579:53297373a894 1082 */
mbed_official 579:53297373a894 1083 static inline void convert_16_bit_to_byte_array(uint16_t value, uint8_t *data)
mbed_official 579:53297373a894 1084 {
mbed_official 579:53297373a894 1085 data[0] = value & 0xFF;
mbed_official 579:53297373a894 1086 data[1] = (value >> 8) & 0xFF;
mbed_official 579:53297373a894 1087 }
mbed_official 579:53297373a894 1088
mbed_official 579:53297373a894 1089 /* Converts a 16-Bit value into a 2 Byte array */
mbed_official 579:53297373a894 1090 static inline void convert_spec_16_bit_to_byte_array(uint16_t value, uint8_t *data)
mbed_official 579:53297373a894 1091 {
mbed_official 579:53297373a894 1092 data[0] = value & 0xFF;
mbed_official 579:53297373a894 1093 data[1] = (value >> 8) & 0xFF;
mbed_official 579:53297373a894 1094 }
mbed_official 579:53297373a894 1095
mbed_official 579:53297373a894 1096 /* Converts a 16-Bit value into a 2 Byte array */
mbed_official 579:53297373a894 1097 static inline void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data)
mbed_official 579:53297373a894 1098 {
mbed_official 579:53297373a894 1099 data[0] = value & 0xFF;
mbed_official 579:53297373a894 1100 data[1] = (value >> 8) & 0xFF;
mbed_official 579:53297373a894 1101 }
mbed_official 579:53297373a894 1102
mbed_official 579:53297373a894 1103 /*
mbed_official 579:53297373a894 1104 * @brief Converts a 2 Byte array into a 16-Bit value
mbed_official 579:53297373a894 1105 *
mbed_official 579:53297373a894 1106 * @param data Specifies the pointer to the 2 Byte array
mbed_official 579:53297373a894 1107 *
mbed_official 579:53297373a894 1108 * @return 16-Bit value
mbed_official 579:53297373a894 1109 * @ingroup apiPalApi
mbed_official 579:53297373a894 1110 */
mbed_official 579:53297373a894 1111 static inline uint16_t convert_byte_array_to_16_bit(uint8_t *data)
mbed_official 579:53297373a894 1112 {
mbed_official 579:53297373a894 1113 return (data[0] | ((uint16_t)data[1] << 8));
mbed_official 579:53297373a894 1114 }
mbed_official 579:53297373a894 1115
mbed_official 579:53297373a894 1116 /* Converts a 4 Byte array into a 32-Bit value */
mbed_official 579:53297373a894 1117 static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
mbed_official 579:53297373a894 1118 {
mbed_official 579:53297373a894 1119 union {
mbed_official 579:53297373a894 1120 uint32_t u32;
mbed_official 579:53297373a894 1121 uint8_t u8[4];
mbed_official 579:53297373a894 1122 } long_addr;
mbed_official 579:53297373a894 1123 uint8_t index;
mbed_official 579:53297373a894 1124 for (index = 0; index < 4; index++) {
mbed_official 579:53297373a894 1125 long_addr.u8[index] = *data++;
mbed_official 579:53297373a894 1126 }
mbed_official 579:53297373a894 1127 return long_addr.u32;
mbed_official 579:53297373a894 1128 }
mbed_official 579:53297373a894 1129
mbed_official 579:53297373a894 1130 /**
mbed_official 579:53297373a894 1131 * @brief Converts a 8 Byte array into a 64-Bit value
mbed_official 579:53297373a894 1132 *
mbed_official 579:53297373a894 1133 * @param data Specifies the pointer to the 8 Byte array
mbed_official 579:53297373a894 1134 *
mbed_official 579:53297373a894 1135 * @return 64-Bit value
mbed_official 579:53297373a894 1136 * @ingroup apiPalApi
mbed_official 579:53297373a894 1137 */
mbed_official 579:53297373a894 1138 static inline uint64_t convert_byte_array_to_64_bit(uint8_t *data)
mbed_official 579:53297373a894 1139 {
mbed_official 579:53297373a894 1140 union {
mbed_official 579:53297373a894 1141 uint64_t u64;
mbed_official 579:53297373a894 1142 uint8_t u8[8];
mbed_official 579:53297373a894 1143 } long_addr;
mbed_official 579:53297373a894 1144
mbed_official 579:53297373a894 1145 uint8_t index;
mbed_official 579:53297373a894 1146
mbed_official 579:53297373a894 1147 for (index = 0; index < 8; index++) {
mbed_official 579:53297373a894 1148 long_addr.u8[index] = *data++;
mbed_official 579:53297373a894 1149 }
mbed_official 579:53297373a894 1150
mbed_official 579:53297373a894 1151 return long_addr.u64;
mbed_official 579:53297373a894 1152 }
mbed_official 579:53297373a894 1153
mbed_official 579:53297373a894 1154 /** @} */
mbed_official 579:53297373a894 1155
mbed_official 579:53297373a894 1156 #endif /* UTILS_COMPILER_H_INCLUDED */