1 /** 2 ****************************************************************************** 3 * @file stm32_wpan_common.h 4 * @author MCD Application Team 5 * @brief Common file to utilities 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2018-2021 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __STM32_WPAN_COMMON_H 22 #define __STM32_WPAN_COMMON_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #if defined ( __CC_ARM )||defined (__ARMCC_VERSION) 29 #define __ASM __asm /*!< asm keyword for ARM Compiler */ 30 #define __INLINE __inline /*!< inline keyword for ARM Compiler */ 31 #define __STATIC_INLINE static __inline 32 #elif defined ( __ICCARM__ ) 33 #define __ASM __asm /*!< asm keyword for IAR Compiler */ 34 #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ 35 #define __STATIC_INLINE static inline 36 #elif defined ( __GNUC__ ) 37 #define __ASM __asm /*!< asm keyword for GNU Compiler */ 38 #define __INLINE inline /*!< inline keyword for GNU Compiler */ 39 #define __STATIC_INLINE static inline 40 #endif 41 42 #include <stdint.h> 43 #include <string.h> 44 #include <stdio.h> 45 #include <stdlib.h> 46 #include <stdarg.h> 47 #include "cmsis_compiler.h" 48 49 /* -------------------------------- * 50 * Basic definitions * 51 * -------------------------------- */ 52 53 #undef NULL 54 #define NULL 0U 55 56 #undef FALSE 57 #define FALSE 0U 58 59 #undef TRUE 60 #define TRUE (!0U) 61 62 /* -------------------------------- * 63 * Critical Section definition * 64 * -------------------------------- */ 65 #undef BACKUP_PRIMASK 66 #define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() 67 68 #undef DISABLE_IRQ 69 #define DISABLE_IRQ() __disable_irq() 70 71 #undef RESTORE_PRIMASK 72 #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) 73 74 /* -------------------------------- * 75 * Macro delimiters * 76 * -------------------------------- */ 77 #undef M_BEGIN 78 #define M_BEGIN do { 79 80 #undef M_END 81 #define M_END } while(0) 82 83 /* -------------------------------- * 84 * Some useful macro definitions * 85 * -------------------------------- */ 86 #undef MAX 87 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 88 89 #undef MIN 90 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 91 92 #undef MODINC 93 #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END 94 95 #undef MODDEC 96 #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END 97 98 #undef MODADD 99 #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END 100 101 #undef MODSUB 102 #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) 103 104 #undef ALIGN 105 #ifdef WIN32 106 #define ALIGN(n) 107 #else 108 #define ALIGN(n) __attribute__((aligned(n))) 109 #endif 110 111 #undef PAUSE 112 #define PAUSE( t ) M_BEGIN \ 113 volatile int _i; \ 114 for ( _i = t; _i > 0; _i -- ); \ 115 M_END 116 #undef DIVF 117 #define DIVF( x, y ) ((x)/(y)) 118 119 #undef DIVC 120 #define DIVC( x, y ) (((x)+(y)-1)/(y)) 121 122 #undef DIVR 123 #define DIVR( x, y ) (((x)+((y)/2))/(y)) 124 125 #undef SHRR 126 #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) 127 128 #undef BITN 129 #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) 130 131 #undef BITNSET 132 #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END 133 134 /* -------------------------------- * 135 * Section attribute * 136 * -------------------------------- */ 137 #undef PLACE_IN_SECTION 138 #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) 139 140 /* ----------------------------------- * 141 * Packed usage (compiler dependent) * 142 * ----------------------------------- */ 143 #undef PACKED__ 144 #undef PACKED_STRUCT 145 146 #if defined ( __CC_ARM ) 147 #if defined ( __GNUC__ ) 148 /* GNU extension */ 149 #define PACKED__ __attribute__((packed)) 150 #define PACKED_STRUCT struct PACKED__ 151 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) 152 #define PACKED__ __attribute__((packed)) 153 #define PACKED_STRUCT struct PACKED__ 154 #else 155 #define PACKED__(TYPE) __packed TYPE 156 #define PACKED_STRUCT PACKED__(struct) 157 #endif 158 #elif defined ( __GNUC__ ) 159 #define PACKED__ __attribute__((packed)) 160 #define PACKED_STRUCT struct PACKED__ 161 #elif defined (__ICCARM__) 162 #define PACKED_STRUCT __packed struct 163 #else 164 #define PACKED_STRUCT __packed struct 165 #endif 166 167 #ifdef __cplusplus 168 } 169 #endif 170 171 #endif /*__STM32_WPAN_COMMON_H */ 172