Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
utils.h
00001 00002 /****************************************************************************** 00003 * @attention 00004 * 00005 * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> 00006 * 00007 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); 00008 * You may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at: 00010 * 00011 * http://www.st.com/myliberty 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 00016 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 ******************************************************************************/ 00022 00023 00024 /* 00025 * PROJECT: NFCC firmware 00026 * $Revision: $ 00027 * LANGUAGE: ISO C99 00028 */ 00029 00030 /*! \file 00031 * 00032 * \author Ulrich Herrmann 00033 * 00034 * \brief Common and helpful macros 00035 * 00036 */ 00037 00038 #ifndef UTILS_H 00039 #define UTILS_H 00040 00041 /* 00042 ****************************************************************************** 00043 * INCLUDES 00044 ****************************************************************************** 00045 */ 00046 #include <string.h> 00047 00048 /* 00049 ****************************************************************************** 00050 * GLOBAL MACROS 00051 ****************************************************************************** 00052 */ 00053 /*! 00054 * this macro evaluates an error variable \a ERR against an error code \a EC. 00055 * in case it is not equal it jumps to the given label \a LABEL. 00056 */ 00057 #define EVAL_ERR_NE_GOTO(EC, ERR, LABEL) \ 00058 if (EC != ERR) goto LABEL; 00059 00060 /*! 00061 * this macro evaluates an error variable \a ERR against an error code \a EC. 00062 * in case it is equal it jumps to the given label \a LABEL. 00063 */ 00064 #define EVAL_ERR_EQ_GOTO(EC, ERR, LABEL) \ 00065 if (EC == ERR) goto LABEL; 00066 00067 #define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0])) /*!< Compute the size of an array */ 00068 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */ 00069 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */ 00070 #define BITMASK_1 (0x01) /*!< Bit mask for lsb bit */ 00071 #define BITMASK_2 (0x03) /*!< Bit mask for two lsb bits */ 00072 #define BITMASK_3 (0x07) /*!< Bit mask for three lsb bits */ 00073 #define BITMASK_4 (0x0F) /*!< Bit mask for four lsb bits */ 00074 #define U16TOU8(a) ((a) & 0x00FF) /*!< Cast 16-bit unsigned to 8-bit unsigned */ 00075 #define GETU16(a) (uint16_t)((a[0] << 8) | a[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */ 00076 00077 00078 #define REVERSE_BYTES(pData, nDataSize) \ 00079 unsigned char swap, *lo = pData, *hi = pData + nDataSize - 1; \ 00080 while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; } 00081 00082 00083 #define ST_MEMMOVE memmove /*!< map memmove to string library code */ 00084 #define ST_MEMCPY memcpy /*!< map memcpy to string library code */ 00085 #define ST_MEMSET memset /*!< map memset to string library code */ 00086 #define ST_BYTECMP memcmp /*!< map bytecmp to string library code */ 00087 00088 #define NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */ 00089 00090 00091 #ifndef NULL 00092 #define NULL (void*)0 /*!< represents a NULL pointer */ 00093 #endif /* !NULL */ 00094 00095 /* 00096 ****************************************************************************** 00097 * GLOBAL FUNCTION PROTOTYPES 00098 ****************************************************************************** 00099 */ 00100 00101 #endif /* UTILS_H */ 00102
Generated on Tue Jul 12 2022 18:07:56 by
1.7.2