utils.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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) (uint16_t)((a[0] << 8) | a[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
  65. #define REVERSE_BYTES(pData, nDataSize) \
  66. unsigned char swap, *lo = pData, *hi = pData + nDataSize - 1; \
  67. while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; }
  68. #define ST_MEMMOVE memmove /*!< map memmove to string library code */
  69. #define ST_MEMCPY memcpy /*!< map memcpy to string library code */
  70. #define ST_MEMSET memset /*!< map memset to string library code */
  71. #define ST_BYTECMP memcmp /*!< map bytecmp to string library code */
  72. #define NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */
  73. #ifndef NULL
  74. #define NULL (void*)0 /*!< represents a NULL pointer */
  75. #endif /* !NULL */
  76. /*
  77. ******************************************************************************
  78. * GLOBAL FUNCTION PROTOTYPES
  79. ******************************************************************************
  80. */
  81. #endif /* UTILS_H */