/*
* @file hv_drv_UsbMusbIO.h
* @brief Header of MUSB OTG driver register I/O.
*
* @author HiView SoC Software Team
* @version 1.0.0
* @date 2022-06-15
*/


#ifndef __HV_DRV_USB_MUSB_IO_H_
#define __HV_DRV_USB_MUSB_IO_H_

#include "hv_vos_Comm.h"

static inline u16 musb_readw(void *mbase, u16 offset) {
    return HAL_R16((u32)mbase + offset);
}

static inline void musb_writew(void *mbase, u16 offset, u16 data) {
    HAL_W16((u32)mbase + offset, data);
}

static inline void musb_writew_lo(void *mbase, u16 offset, u16 data) {
}

static inline void musb_writew_hi(void *mbase, u16 offset, u16 data) {
}

static inline u32 musb_readl(void *mbase, u16 offset) {
    return 0;
}

static inline void musb_writel(void *mbase, u16 offset, u32 data) {
}

static inline u8 musb_readb(void *mbase, u16 offset) {
    return HAL_R8((u32)mbase + offset);
}

static inline void musb_writeb(void *mbase, u16 offset, u8 data) {
    HAL_W8((u32)mbase + offset, data);
}


static inline void readsb(unsigned int *addr, void *data, int bytelen)
{
    unsigned char *ptr;
    unsigned char *ptr2;

    ptr = (unsigned char *)addr;
    ptr2 = (unsigned char *)data;

    while (bytelen) {
        *ptr2 = *ptr;
        ptr2++;
        bytelen--;
    }
}

static inline void readsw(unsigned int *addr, void *data, int wordlen)
{
    unsigned short *ptr;
    unsigned short *ptr2;

    ptr = (unsigned short *)addr;
    ptr2 = (unsigned short *)data;

    while (wordlen) {
        *ptr2 = *ptr;
        ptr2++;
        wordlen--;
    }
}

static inline void readsl(unsigned int *addr, void *data, int longlen)
{
    unsigned int *ptr;
    unsigned int *ptr2;

    ptr = (unsigned int *)addr;
    ptr2 = (unsigned int *)data;

    while (longlen) {
        *ptr2 = *ptr;
        ptr2++;
        longlen--;
    }
}


static inline void writesb(unsigned int *addr, const void *data, int bytelen)
{
    unsigned char *ptr;
    unsigned char *ptr2;

    ptr = (unsigned char *)addr;
    ptr2 = (unsigned char *)data;

    while (bytelen) {
        *ptr = *ptr2;
        ptr2++;
        bytelen--;
    }
}

static inline void writesw(unsigned int *addr, const void *data, int wordlen)
{
    unsigned short *ptr;
    unsigned short *ptr2;

    ptr = (unsigned short *)addr;
    ptr2 = (unsigned short *)data;

    while (wordlen) {
        *ptr = *ptr2;
        ptr2++;
        wordlen--;
    }
}

static inline void writesl(unsigned int *addr, const void *data, int longlen)
{
    unsigned int *ptr;
    unsigned int *ptr2;

    ptr = (unsigned int *)addr;
    ptr2 = (unsigned int *)data;

    while (longlen) {
        *ptr = *ptr2;
        ptr2++;
        longlen--;
    }
}

#endif
