hv_vos_Macro.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * @file hv_pm51_driver_I2C.h
  3. * @brief Header file of I2C driver.
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. * (+) Use ()
  10. *
  11. * @endverbatim
  12. * @author HiView SoC Software Team
  13. * @version 1.0.0
  14. * @date 2023-03-01
  15. */
  16. #ifndef _HV_VOS_MACRO_H
  17. #define _HV_VOS_MACRO_H
  18. #include "hv_vos_Types.h"
  19. #include "hv_vos_Log.h"
  20. /** @defgroup VOS_MACRO VOS_MACRO
  21. * VOS type definitions
  22. * @{
  23. *
  24. */
  25. VOS_EXTERN_C_BEGIN
  26. /* unified strstr function */
  27. #define HV_STRSTR(str, substr) strstr(str, substr)
  28. /* unified strcpy function */
  29. #define HV_STRCPY(dest, src) strcpy(dest, src)
  30. /* unified strncpy function */
  31. #define HV_STRNCPY(dest, src, len) strncpy(dest, src, len)
  32. /* mark as unused for prevent compiler warning */
  33. #ifndef HV_UNUSED
  34. #define HV_UNUSED(var) (void)(var)
  35. #endif
  36. /* mask assignment */
  37. #define HV_MASK_ASSIGN(old, mask, val) (((old) & ~mask) | ((val) & (mask)))
  38. /* show prompt and wait a key to continue */
  39. #define HV_WAIT_KEY() do {char ch = 0; HV_LOGA("Press enter key to continue.\n"); Hv_Vos_STDIO_GetChar(&ch); } while (0)
  40. /* register exiting function */
  41. #define HV_REGISTER_EXIT(func) atexit(func)
  42. /* change 32 bits endianess */
  43. INLINE UINT32 CHANGE_ENDIAN_U32(UINT32 x)
  44. {
  45. return ((( x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) | ((x << 8) & 0x00FF0000) | ((x << 24) & 0xFF000000));
  46. }
  47. /* change 16 bits endianess */
  48. INLINE USHORT16 CHANGE_ENDIAN_U16(USHORT16 x)
  49. {
  50. return ((x >> 8) & 0x000000FF) | ((x << 8) & 0x0000FF00);
  51. }
  52. /* UCHAR8* to UINT32 using big endian */
  53. INLINE UINT32 CHANGE_TO_U16_BE(const UCHAR8 *p)
  54. {
  55. return ((UINT32)(*p << 8) | (UINT32)(*(p + 1)));
  56. }
  57. /* UCHAR8* to UINT32 using little endian */
  58. INLINE UINT32 CHANGE_TO_U16_LE(const UCHAR8 *p)
  59. {
  60. return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8));
  61. }
  62. /* UCHAR8* to UINT32 using big endian */
  63. INLINE UINT32 CHANGE_TO_U24_BE(const UCHAR8 *p)
  64. {
  65. return ((UINT32)(*p << 16) | (UINT32)((*(p + 1)) << 8) | (UINT32)(*(p + 2)));
  66. }
  67. /* UCHAR8* to UINT32 using little endian */
  68. INLINE UINT32 CHANGE_TO_U24_LE(const UCHAR8 *p)
  69. {
  70. return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8)|(UINT32)((*(p + 2)) << 16));
  71. }
  72. /* UCHAR8* to UINT32 using big endian */
  73. INLINE UINT32 CHANGE_TO_U32_BE(const UCHAR8 *p)
  74. {
  75. return ((UINT32)(*p << 24) | (UINT32)((*(p + 1)) << 16) | (UINT32)((*(p + 2)) << 8) | (UINT32)((*(p + 3)) << 0));
  76. }
  77. /* UCHAR8* to UINT32 using little endian */
  78. INLINE UINT32 CHANGE_TO_U32_LE(const UCHAR8 *p)
  79. {
  80. return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8) | (UINT32)((*(p + 2)) << 16) | (UINT32)((*(p + 3)) << 24));
  81. }
  82. /**
  83. * @}
  84. */
  85. VOS_EXTERN_C_END
  86. #endif