utils.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 BITMASK_1 (0x01) /*!< Bit mask for lsb bit */
  60. #define BITMASK_2 (0x03) /*!< Bit mask for two lsb bits */
  61. #define BITMASK_3 (0x07) /*!< Bit mask for three lsb bits */
  62. #define BITMASK_4 (0x0F) /*!< Bit mask for four lsb bits */
  63. #define U16TOU8(a) ((a)&0x00FF) /*!< Cast 16-bit unsigned to 8-bit unsigned */
  64. #define GETU16(a) \
  65. (uint16_t)( \
  66. (a[0] << 8) | a[1]) /*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
  67. #define REVERSE_BYTES(pData, nDataSize) \
  68. unsigned char swap, *lo = pData, *hi = pData + nDataSize - 1; \
  69. while(lo < hi) { \
  70. swap = *lo; \
  71. *lo++ = *hi; \
  72. *hi-- = swap; \
  73. }
  74. #define ST_MEMMOVE memmove /*!< map memmove to string library code */
  75. #define ST_MEMCPY memcpy /*!< map memcpy to string library code */
  76. #define ST_MEMSET memset /*!< map memset to string library code */
  77. #define ST_BYTECMP memcmp /*!< map bytecmp to string library code */
  78. #define NO_WARNING(v) ((void)(v)) /*!< Macro to suppress compiler warning */
  79. #ifndef NULL
  80. #define NULL (void*)0 /*!< represents a NULL pointer */
  81. #endif /* !NULL */
  82. /*
  83. ******************************************************************************
  84. * GLOBAL FUNCTION PROTOTYPES
  85. ******************************************************************************
  86. */
  87. #endif /* UTILS_H */