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