/*
 * @file hv_pm51_driver_I2C.h
 * @brief Header file of I2C driver.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */



#ifndef _HV_VOS_MACRO_H
#define _HV_VOS_MACRO_H

#include "hv_vos_Types.h"
#include "hv_vos_Log.h"

/** @defgroup VOS_MACRO VOS_MACRO
*   VOS type definitions
 *  @{
 * 
 */
VOS_EXTERN_C_BEGIN

/*  unified strstr function  */
#define HV_STRSTR(str, substr) strstr(str, substr)

/*  unified strcpy function  */
#define HV_STRCPY(dest, src) strcpy(dest, src)

/*  unified strncpy function  */
#define HV_STRNCPY(dest, src, len) strncpy(dest, src, len)

/*  mark as unused for prevent compiler warning  */
#ifndef HV_UNUSED
#define HV_UNUSED(var) (void)(var)
#endif


/*  mask assignment  */
#define HV_MASK_ASSIGN(old, mask, val) (((old) & ~mask) | ((val) & (mask)))

/*  show prompt and wait a key to continue  */
#define HV_WAIT_KEY() do {char ch = 0;  HV_LOGA("Press enter key to continue.\n"); Hv_Vos_STDIO_GetChar(&ch); } while (0)

/*  register exiting function  */
#define HV_REGISTER_EXIT(func) atexit(func)


/*  change 32 bits endianess  */
INLINE UINT32 CHANGE_ENDIAN_U32(UINT32 x)
{
    return ((( x >> 24) & 0x000000FF) | ((x >> 8) & 0x0000FF00) | ((x << 8) & 0x00FF0000) | ((x << 24) & 0xFF000000));
}

/*  change 16 bits endianess  */
INLINE USHORT16 CHANGE_ENDIAN_U16(USHORT16 x)
{
    return ((x >> 8) & 0x000000FF) | ((x << 8) & 0x0000FF00);
}

/*  UCHAR8* to UINT32 using big endian  */
INLINE UINT32 CHANGE_TO_U16_BE(const UCHAR8 *p)
{
    return ((UINT32)(*p << 8) | (UINT32)(*(p + 1)));
}

/*  UCHAR8* to UINT32 using little endian  */
INLINE UINT32 CHANGE_TO_U16_LE(const UCHAR8 *p)
{
    return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8));
}

/*  UCHAR8* to UINT32 using big endian  */
INLINE UINT32 CHANGE_TO_U24_BE(const UCHAR8 *p)
{
    return ((UINT32)(*p << 16) | (UINT32)((*(p + 1)) << 8) | (UINT32)(*(p + 2)));
}

/*  UCHAR8* to UINT32 using little endian  */
INLINE UINT32 CHANGE_TO_U24_LE(const UCHAR8 *p)
{
    return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8)|(UINT32)((*(p + 2)) << 16));
}


/*  UCHAR8* to UINT32 using big endian  */
INLINE UINT32 CHANGE_TO_U32_BE(const UCHAR8 *p)
{
    return ((UINT32)(*p << 24) | (UINT32)((*(p + 1)) << 16) | (UINT32)((*(p + 2)) << 8) | (UINT32)((*(p + 3)) << 0));
}

/* UCHAR8* to UINT32 using little endian */
INLINE UINT32 CHANGE_TO_U32_LE(const UCHAR8 *p)
{
    return ((UINT32)(*p) | (UINT32)((*(p + 1)) << 8) | (UINT32)((*(p + 2)) << 16) | (UINT32)((*(p + 3)) << 24));
}

/**
 *  @}
 */

VOS_EXTERN_C_END
#endif



