93 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
/* os shim includes */
 | 
						|
#include "os_types.h"
 | 
						|
#include "os_mem.h"
 | 
						|
 | 
						|
/* common includes */
 | 
						|
#include "iot_utils.h"
 | 
						|
 | 
						|
static uint8_t *g_mem_bank_start;
 | 
						|
static uint32_t g_mem_bytes_rem;
 | 
						|
static uint8_t *g_current_mem_ptr;
 | 
						|
 | 
						|
/* below functions should be implemented in c lib */
 | 
						|
extern void* memset(void* s, int32_t c, uint32_t size);
 | 
						|
extern void* memcpy(void* dest, const void* src, uint32_t size);
 | 
						|
extern void* memmove(void* dest, const void* src, uint32_t size);
 | 
						|
extern int32_t memcmp(const void *s1, const void *s2, size_t n);
 | 
						|
 | 
						|
void os_mem_cpy(void *dst, const void *src, uint32_t len)
 | 
						|
{
 | 
						|
    memcpy(dst, (void *)src, len);
 | 
						|
}
 | 
						|
 | 
						|
void os_mem_move(void *dst, const void *src, uint32_t len)
 | 
						|
{
 | 
						|
    memmove(dst, (void *)src, len);
 | 
						|
}
 | 
						|
 | 
						|
int32_t os_mem_cmp(const void *dst, const void *src, uint32_t len)
 | 
						|
{
 | 
						|
    return (int32_t)memcmp(dst, src, len);
 | 
						|
}
 | 
						|
 | 
						|
void os_mem_set(void *ptr, uint8_t value, uint32_t len)
 | 
						|
{
 | 
						|
    memset(ptr, value, len);
 | 
						|
}
 | 
						|
 | 
						|
void os_mem_init(void *start_addr, uint32_t byte_len)
 | 
						|
{
 | 
						|
    IOT_ASSERT(start_addr && byte_len > 4);
 | 
						|
    g_mem_bank_start = start_addr;
 | 
						|
    g_mem_bytes_rem = byte_len;
 | 
						|
    g_current_mem_ptr = start_addr;
 | 
						|
}
 | 
						|
 | 
						|
#if IOT_OS_MALLOC_DEBUG
 | 
						|
void *os_mem_malloc_debug(uint8_t *file, uint32_t line,
 | 
						|
    module_id_t module_id, size_t size)
 | 
						|
#else
 | 
						|
void *os_mem_malloc(module_id_t module_id, size_t size)
 | 
						|
#endif
 | 
						|
{
 | 
						|
    (void)module_id;  // avoid warning. to be fixed.
 | 
						|
 | 
						|
    /* double word align */
 | 
						|
    uint32_t size_dw = (size >> 2) + 1;
 | 
						|
    uint32_t size_byte = size_dw << 2;
 | 
						|
    void *buf = NULL;
 | 
						|
    if (size_byte < g_mem_bytes_rem) {
 | 
						|
        buf = g_current_mem_ptr;
 | 
						|
        g_current_mem_ptr += size_byte;
 | 
						|
        g_mem_bytes_rem -= size_byte;
 | 
						|
    } else {
 | 
						|
        IOT_ASSERT(0);
 | 
						|
    }
 | 
						|
 | 
						|
    if (buf) {
 | 
						|
        os_mem_set(buf, 0, size_byte);
 | 
						|
    }
 | 
						|
    return buf;
 | 
						|
}
 | 
						|
 | 
						|
void os_mem_free(void *ptr)
 | 
						|
{
 | 
						|
    (void)ptr;
 | 
						|
    return;
 | 
						|
}
 |