/**
 * @file  hv_drv_TypecGenericDefs.h
 * @brief   Generic Defines file
 *          This file contains generic defines used in the stack.
 * @details This file provides the following functions: \n
 *          (1) \n
 *          (2) \n
 *          (3) \n
 *
 * 
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-25
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author                         <th>Date         <th>Change Description
 * <tr><td>Hiview SoC Software Team       <td>2022-08-25   <td>init
 * </table>
*/


#ifndef _HV_DRV_TYPECGENERICDEFS_H
#define    _HV_DRV_TYPECGENERICDEFS_H

#include "hv_comm_DataType.h"

#define SOC_SYS_ENDIANNESS_SEL                     1            //0: LITTLE ENDIAN, 1: BIG ENDIAN
#define SOC_NOT_SUPPORT_FLOAT                      1

/* HV_TRUE/HV_FALSE defines */
#ifndef HV_FALSE
#define HV_FALSE                                     0
#endif
#ifndef HV_TRUE
#define HV_TRUE                                      1
#endif

#ifndef NULL
#define NULL ((void *)0)
#endif

/* Unsigned integers */

#define UINT8                                     unsigned char
#define UINT16                                    unsigned short

/* Signed Integer */
#define INT8                                      signed char
#define INT16                                     short

/* Signed character */
#define CHAR                                      char

/* Unsigned character */
#define UCHAR                                     unsigned char

/* Size of operator */
#define SIZEOF(x)                                 sizeof(x)
/********************************************************************************************/
/* To obtain equivalent value from BIT position*/
#ifndef BIT
#define BIT(x)                                   (1UL << x)
#endif

/* Data Size */ 
#define BYTE_LEN_1                                1
#define BYTE_LEN_2                                2
#define BYTE_LEN_3                                3
#define BYTE_LEN_4                                4
#define BYTE_LEN_10                               10
#define BYTE_LEN_16                               16

/*Index position*/
#define INDEX_0                                 0
#define INDEX_1                                 1
#define INDEX_2                                 2
#define INDEX_3                                 3
#define INDEX_4                                 4
#define INDEX_5                                 5
#define INDEX_6                                 6
#define INDEX_7                                 7
#define INDEX_8                                 8
#define INDEX_9                                 9
#define INDEX_10                                10
#define INDEX_11                                11
#define INDEX_12                                12
#define INDEX_13                                13
#define INDEX_14                                14
#define INDEX_15                                15
#define INDEX_16                                16
#define INDEX_17                                17
#define INDEX_18                                18
#define INDEX_19                                19
#define INDEX_20                                20
#define INDEX_21                                21
#define INDEX_22                                22
#define INDEX_23                                23
#define INDEX_24                                24

/********************************************************************************************/
/*Low Byte and High byte from a UINT16*/
#define LOBYTE(u16Var)                            ((UINT8)(u16Var))
#define HIBYTE(u16Var)                            ((UINT8)((u16Var) >> 8) & 0xFF)

/*Low word and High word from a UINT32*/
#define HIWORD(u32Var)                            ((UINT16)(((u32Var) >> 16) & 0xFFFF))
#define LOWORD(u32Var)                            ((UINT16)((u32Var) & 0xFFFF))

/********************************************************************************************/
/*Make word from Bytes*/
#define MAKE_UINT16(u8HiByte, u8LoByte)            \
        (((UINT16)u8LoByte) | (((UINT16)u8HiByte) << 8))

/*Make UINT32 from word*/
#define MAKE_UINT32(u16HiWord, u16LoWord)        \
            (((UINT32)u16LoWord) | (((UINT32)u16HiWord) << 16))

/*Make UINT32 from Bytes*/
#define MAKE_UINT32_FROM_BYTES(u8LoWordLoByte, u8LoWordHiByte, u8HiWordLoByte, u8HiWordHiByte)\
                                            (((UINT32)u8LoWordLoByte)                |\
                                            (((UINT32)u8LoWordHiByte) << 8)          |\
                                            (((UINT32)u8HiWordLoByte) << 16)         |\
                                            (((UINT32)u8HiWordHiByte) << 24u))

//#define MIN(a,b) (((a) < (b)) ? (a) : (b))    /* Returns the minimum of two */
//#define MAX(a,b) ((a) > (b) ? (a) : (b))    /* Returns the maximum of two */

/* Extract first decimal value in a floating point number */
#define NO_OF_DECIMAL_POINTS_PRECISION          10 
#define EXTRACT_FIRST_DECIMAL_FROM_FLOAT(fNum)  ((UINT16)(fNum * NO_OF_DECIMAL_POINTS_PRECISION) \
                                                    % NO_OF_DECIMAL_POINTS_PRECISION)
/* Round off float value to nearest integer */
#if SOC_NOT_SUPPORT_FLOAT
#define ROUND_OFF_FLOAT_TO_INT(fNum)            (UINT16)fNum
#else
#define ROUND_OFF_FLOAT_TO_INT(fNum)            (EXTRACT_FIRST_DECIMAL_FROM_FLOAT(fNum) >= 5) \
                                                    ? ((UINT16)fNum + 1) : ((UINT16)fNum)          
#endif
/******************************CLEAR & RESET VALUE *************************************/

#define CLR_VAL                                         0x00
#define RESET_TO_ZERO                                   0
#define SET_TO_ZERO                                     0  
#define SET_TO_ONE                                      1
#define SET_TO_255                                      0xFF

#define SET_HPD_LOW                                     0
#define SET_HPD_HIGH                                    1
#define SET_HPD_IRQ                                     2
/********************************************************************************************/
/* Defines for Port reference*/
#define PORT0       0
#define PORT1       1
#define PORT2       2
#define PORT3       3

#define PORT_COUNT_1    1
#define PORT_COUNT_2    2
/**********************************************************************************************/

/****************************** RTOS Task Priority *************************************/
#define TYPEC_STANDBY_TASK_PRIORITY     1
#define TYPEC_IDLE_TASK_PRIORITY        2
#define TYPEC_NORMAL_TASK_PRIORITY      4 
#define TYPEC_URGENT_TASK_PRIORITY      6

/**********************************************************************************************/

/****************************** Debug *************************************/
#define TYPEC_DEBUG_TRACE_EN            0
#define TYPEC_DEBUG_PRINT_CONSOLE_EN    0
#if TYPEC_DEBUG_PRINT_CONSOLE_EN
#define DEBUG_PRINT_CONSOLE HV_LOGI
#else
#define DEBUG_PRINT_CONSOLE(...) 
#endif
/**********************************************************************************************/

#endif /*GENERIC_DEFS_H*/
