1 /** 2 ****************************************************************************** 3 * @file ble_common.h 4 * @author MCD Application Team 5 * @brief Common file to BLE Middleware 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2018 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under Ultimate Liberty license 13 * SLA0044, the "License"; You may not use this file except in compliance with 14 * the License. You may obtain a copy of the License at: 15 * www.st.com/SLA0044 16 * 17 ****************************************************************************** 18 */ 19 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef __BLE_COMMON_H 23 #define __BLE_COMMON_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <stdint.h> 30 #include <string.h> 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <stdarg.h> 34 35 #include "ble_conf.h" 36 #include "ble_dbg_conf.h" 37 38 /* -------------------------------- * 39 * Basic definitions * 40 * -------------------------------- */ 41 42 #undef NULL 43 #define NULL 0 44 45 #undef FALSE 46 #define FALSE 0 47 48 #undef TRUE 49 #define TRUE (!0) 50 51 52 /* -------------------------------- * 53 * Macro delimiters * 54 * -------------------------------- */ 55 56 #define M_BEGIN do { 57 58 #define M_END } while(0) 59 60 61 /* -------------------------------- * 62 * Some useful macro definitions * 63 * -------------------------------- */ 64 65 #define MAX( x, y ) (((x)>(y))?(x):(y)) 66 67 #define MIN( x, y ) (((x)<(y))?(x):(y)) 68 69 #define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END 70 71 #define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END 72 73 #define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END 74 75 #define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) 76 77 #ifdef WIN32 78 #define ALIGN(n) 79 #else 80 #define ALIGN(n) __attribute__((aligned(n))) 81 #endif 82 83 #define PAUSE( t ) M_BEGIN \ 84 volatile int _i; \ 85 for ( _i = t; _i > 0; _i -- ); \ 86 M_END 87 88 #define DIVF( x, y ) ((x)/(y)) 89 90 #define DIVC( x, y ) (((x)+(y)-1)/(y)) 91 92 #define DIVR( x, y ) (((x)+((y)/2))/(y)) 93 94 #define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) 95 96 #define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) 97 98 #define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END 99 100 /* -------------------------------- * 101 * Compiler * 102 * -------------------------------- */ 103 #define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) 104 105 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif /*__BLE_COMMON_H */ 112 113 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114