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-2022 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 #include <stdint.h> 29 #include <string.h> 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <stdarg.h> 33 #include "cmsis_compiler.h" 34 35 /* -------------------------------- * 36 * Basic definitions * 37 * -------------------------------- */ 38 39 #undef NULL 40 #define NULL 0U 41 42 #undef FALSE 43 #define FALSE 0U 44 45 #undef TRUE 46 #define TRUE (!0U) 47 48 /* -------------------------------- * 49 * Critical Section definition * 50 * -------------------------------- */ 51 #undef BACKUP_PRIMASK 52 #define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() 53 54 #undef DISABLE_IRQ 55 #define DISABLE_IRQ() __disable_irq() 56 57 #undef RESTORE_PRIMASK 58 #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) 59 60 /* -------------------------------- * 61 * Macro delimiters * 62 * -------------------------------- */ 63 #undef M_BEGIN 64 #define M_BEGIN do { 65 66 #undef M_END 67 #define M_END } while(0) 68 69 /* -------------------------------- * 70 * Some useful macro definitions * 71 * -------------------------------- */ 72 #undef MAX 73 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 74 75 #undef MIN 76 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 77 78 #undef MODINC 79 #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END 80 81 #undef MODDEC 82 #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END 83 84 #undef MODADD 85 #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END 86 87 #undef MODSUB 88 #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) 89 90 #undef ALIGN 91 #ifdef WIN32 92 #define ALIGN(n) 93 #else 94 #define ALIGN(n) __attribute__((aligned(n))) 95 #endif 96 97 #undef PAUSE 98 #define PAUSE( t ) M_BEGIN \ 99 volatile int _i; \ 100 for ( _i = t; _i > 0; _i -- ); \ 101 M_END 102 #undef DIVF 103 #define DIVF( x, y ) ((x)/(y)) 104 105 #undef DIVC 106 #define DIVC( x, y ) (((x)+(y)-1)/(y)) 107 108 #undef DIVR 109 #define DIVR( x, y ) (((x)+((y)/2))/(y)) 110 111 #undef SHRR 112 #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) 113 114 #undef BITN 115 #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) 116 117 #undef BITNSET 118 #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END 119 120 /* -------------------------------- * 121 * Section attribute * 122 * -------------------------------- */ 123 #undef PLACE_IN_SECTION 124 #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) 125 126 #ifdef __cplusplus 127 } 128 #endif 129 130 #endif /*__STM32_WPAN_COMMON_H */ 131