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