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