/*
* @file hv_drv_UsbPortingTypes.h
* @brief Header file of usb adapting to os about types self define.
*
* @author HiView SoC Software Team
* @version 1.0.0
* @date 2022-06-15
*/

#ifndef __HV_DRV_USB_PORTING_TYPES_H
#define __HV_DRV_USB_PORTING_TYPES_H

#include <stdio.h>
#include <string.h>
#include "hv_comm_DataType.h"
#include "hv_vos_Comm.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "hv_drv_UsbComm.h"

typedef uint32_t            HANDLE;

typedef unsigned char       boolean;
typedef unsigned char       byte;

typedef unsigned char       u8;
typedef unsigned short      u16;
typedef unsigned int        u32;
typedef unsigned long long  u64;

#ifdef bool
#undef bool
#endif
#define bool    unsigned char


#ifdef false
#undef false
#endif
#ifdef true
#undef true
#endif
#define false   0
#define true    !false

#define USB_ASSERT(...)

#define USB_OFFSET_OF(type, member)   (size_t)&(((type *)0)->member)
#define USB_CONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr) - USB_OFFSET_OF(type,member)))

#define USB_MAX(x, y) ((x) > (y) ? (x) : (y))
#define USB_MIN(x, y) ((x) < (y) ? (x) : (y))
#define USB_CLAMP(x, lval, uval) USB_MIN(USB_MAX(x, lval), uval)

#define INLINE static inline


#define spin_lock_irq()         portDISABLE_INTERRUPTS()// NULL
#define spin_unlock_irq(sc)     portENABLE_INTERRUPTS()

#define unlikely(x) x
#define likely(x) x

#define MYFILE(x)   strrchr(x,'/')?strrchr(x,'/')+1:x

#define USB_LOGW        HV_LOGW
#define USB_LOGI        HV_LOGI
#define USB_LOGE        HV_LOGE
#define USB_LOGV        HV_LOGV
#define USB_LOGF        HV_LOGF
#define USB_LOGA        HV_LOGA


#define USB_MSleep(x)   Hv_Vos_MSleep(x) //Hv_Vos_Delayus(x*1000)

//#define USB_MALLOC      HV_MALLOC
//#define USB_FREE        HV_FREE
#define USB_MEMCPY          HV_MEMCPY
#ifdef USB_TRACKED_FILE_POSITION
#define USB_MALLOC(size)    HV_Drv_USB_TrackedMalloc(size, __FILE__, __LINE__)
#else
#define USB_MALLOC(size)    HV_Drv_USB_TrackedMalloc(size)
#endif
#define USB_FREE(ptr)       HV_Drv_USB_TrackedFree(ptr)


#define USB_W32         HV_W32
#define USB_R32         HV_R32
#define USB_W16         HV_W16
#define USB_R16         HV_R16
#define USB_W8          HV_W8
#define USB_R8          HV_R8
#define USB_W32_MASK    HV_W32_MASK


#define USB_SEMA_INIT(x, y)               xSemaphoreCreateCounting(x, y)
#define USB_SEMA_FINI(x)                  vSemaphoreDelete(x)
#define USB_SEMA_TAKE(x, y)               xSemaphoreTake(x, y)
#define USB_SEMA_GIVE(x)                  xSemaphoreGive(x)
#define USB_SEMA_TAKE_FROM_ISR(x, y)      xSemaphoreTakeFromISR(x, y)
#define USB_SEMA_GIVE_FROM_ISR(x, y)      xSemaphoreGiveFromISR(x, y)


#endif

