/**
 * @file hv_vos_Memory.c
 * @brief vos memory source code
 * @details 
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 20230301
 * @copyright Copyright(c),2023-3, Hiview Software. All rights reserved.
 * @par History: 
 * <table>
 * <tr><th>author                     <th>date           <th>description
 * <tr><td>HiView SoC Software Team   <td>20230301       <td>Create and first Version.
 * </table>
**/

#include "hv_vos_Types.h"
#include "hv_vos_Assert.h"
#include "hv_vos_Memory.h"
#include "hv_vos_Log.h"
#include "FreeRTOS.h"
#include "hv_vos_Conn.h"


#define HV_VOS_MEMORY_ALIGNMENT_BYTE 4

#define HV_VOS_MEMORY_ALIGNMENT_MASK 3

static UCHAR8 *heapAlign = NULL;

void *Hv_Vos_Calloc(UINT32 nmemb, UINT32 size)
{
    UINT32 memsize = nmemb * size;
    void *p = Hv_Vos_Malloc(memsize);
    HV_MEMSET(p, 0, memsize);
    return p;
}

void *Hv_Vos_Malloc(UINT32 size)
{
    void* pmalloc= NULL;
    pmalloc = pvPortMalloc(size);
    return pmalloc;
}

UINT32 Hv_Vos_MemoryRemaining(void)
{
    return xPortGetFreeHeapSize();
}


void *Hv_Vos_Realloc(void *p, UINT32 size)
{
    return NULL;
}

void *Hv_Vos_Memcpy(void *dest, const void *src, UINT32 n)
{
    UINT32 srcAddr = (UINT32)src;

    return memcpy(dest, src, n);
}

void *Hv_Vos_VolatileMemcpy(void *dest, const volatile void *src, UINT32 n)
{
    UINT32 uiLoop = 0;
    UINT32 srcAddr = (UINT32)src;
    UINT32 destAddr = (UINT32)dest;

    for(uiLoop = 0; uiLoop < n; uiLoop++)
    {
        *((volatile UCHAR8 *)destAddr)= *((volatile UCHAR8 *)srcAddr);

        destAddr++;
        srcAddr++;
    }

    return dest;
}

void *Hv_Vos_Memset(void *s, int c, UINT32 n)
{
   return memset(s, c, n);
}

void Hv_Vos_Free(void *p) {
    vPortFree(p);
}

char *Hv_Vos_Strdup(const char *s)
{
    int size = strlen(s) + 1;
    char *p = HV_MALLOC(size);
    HV_MEMCPY(p, s, size);
    return p;
}



