utils.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******************************************************************************
  2. * @attention
  3. *
  4. * <h2><center>&copy; COPYRIGHT 2018 STMicroelectronics</center></h2>
  5. *
  6. * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  7. * You may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.st.com/myliberty
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  15. * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. /*
  22. * PROJECT: NFCC firmware
  23. * $Revision: $
  24. * LANGUAGE: ISO C99
  25. */
  26. /*! \file
  27. *
  28. * \author Ulrich Herrmann
  29. *
  30. * \brief Common and helpful macros
  31. *
  32. */
  33. #ifndef UTILS_H
  34. #define UTILS_H
  35. /*
  36. ******************************************************************************
  37. * INCLUDES
  38. ******************************************************************************
  39. */
  40. #include <string.h>
  41. #include <stdint.h>
  42. /*
  43. ******************************************************************************
  44. * GLOBAL MACROS
  45. ******************************************************************************
  46. */
  47. /*!
  48. * this macro evaluates an error variable \a ERR against an error code \a EC.
  49. * in case it is not equal it jumps to the given label \a LABEL.
  50. */
  51. #define EVAL_ERR_NE_GOTO(EC, ERR, LABEL) \
  52. if (EC != ERR) goto LABEL;
  53. /*!
  54. * this macro evaluates an error variable \a ERR against an error code \a EC.
  55. * in case it is equal it jumps to the given label \a LABEL.
  56. */
  57. #define EVAL_ERR_EQ_GOTO(EC, ERR, LABEL) \
  58. if (EC == ERR) goto LABEL;
  59. #define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0])) /*!< Compute the size of an array */
  60. #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */
  61. #define MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */
  62. #define BITMASK_1 (0x01) /*!< Bit mask for lsb bit */
  63. #define BITMASK_2 (0x03) /*!< Bit mask for two lsb bits */
  64. #define BITMASK_3 (0x07) /*!< Bit mask for three lsb bits */
  65. #define BITMASK_4 (0x0F) /*!< Bit mask for four lsb bits */
  66. #define U16TOU8(a) ((a) & 0x00FF) /*!< Cast 16-bit unsigned to 8-bit unsigned */
  67. #define GETU16(a) (uint16_t)((a[0] << 8) | a[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
  68. #define REVERSE_BYTES(pData, nDataSize) \
  69. unsigned char swap, *lo = pData, *hi = pData + nDataSize - 1; \
  70. while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; }
  71. #define ST_MEMMOVE memmove /*!< map memmove to string library code */
  72. #define ST_MEMCPY memcpy /*!< map memcpy to string library code */
  73. #define ST_MEMSET memset /*!< map memset to string library code */
  74. #define ST_BYTECMP memcmp /*!< map bytecmp to string library code */
  75. #define NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */
  76. #ifndef NULL
  77. #define NULL (void*)0 /*!< represents a NULL pointer */
  78. #endif /* !NULL */
  79. /*
  80. ******************************************************************************
  81. * GLOBAL FUNCTION PROTOTYPES
  82. ******************************************************************************
  83. */
  84. #endif /* UTILS_H */