1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * @file app_common.h 5 * @author MCD Application Team 6 * @brief App Common application configuration file for STM32WPAN Middleware. 7 ****************************************************************************** 8 * @attention 9 * 10 * Copyright (c) 2020-2021 STMicroelectronics. 11 * All rights reserved. 12 * 13 * This software is licensed under terms that can be found in the LICENSE file 14 * in the root directory of this software component. 15 * If no LICENSE file comes with this software, it is provided AS-IS. 16 * 17 ****************************************************************************** 18 */ 19 /* USER CODE END Header */ 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef APP_COMMON_H 22 #define APP_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 34 #include "app_conf.h" 35 36 /* -------------------------------- * 37 * Basic definitions * 38 * -------------------------------- */ 39 #undef NULL 40 #define NULL 0 41 42 #undef FALSE 43 #define FALSE 0 44 45 #undef TRUE 46 #define TRUE (!0) 47 48 /* -------------------------------- * 49 * Critical Section definition * 50 * -------------------------------- */ 51 #define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() 52 #define DISABLE_IRQ() __disable_irq() 53 #define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) 54 55 /* -------------------------------- * 56 * Macro delimiters * 57 * -------------------------------- */ 58 #define M_BEGIN do { 59 60 #define M_END } while(0) 61 62 /* -------------------------------- * 63 * Some useful macro definitions * 64 * -------------------------------- */ 65 #ifndef MAX 66 #define MAX( x, y ) (((x)>(y))?(x):(y)) 67 #endif 68 69 #ifndef MIN 70 #define MIN( x, y ) (((x)<(y))?(x):(y)) 71 #endif 72 73 #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END 74 75 #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END 76 77 #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END 78 79 #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) 80 81 #define PAUSE( t ) M_BEGIN \ 82 __IO int _i; \ 83 for ( _i = t; _i > 0; _i -- ); \ 84 M_END 85 86 #define DIVF( x, y ) ((x)/(y)) 87 88 #define DIVC( x, y ) (((x)+(y)-1)/(y)) 89 90 #define DIVR( x, y ) (((x)+((y)/2))/(y)) 91 92 #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) 93 94 #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) 95 96 #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END 97 98 /* -------------------------------- * 99 * Compiler * 100 * -------------------------------- */ 101 #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) 102 103 #ifdef WIN32 104 #define ALIGN(n) 105 #else 106 #define ALIGN(n) __attribute__((aligned(n))) 107 #endif 108 109 #ifdef __cplusplus 110 } /* extern "C" */ 111 #endif 112 113 #endif /* APP_COMMON_H */ 114