1 #include "amp_memmgt.h"
2 #include "aos_system.h"
3
amp_memory_init()4 void amp_memory_init()
5 {
6 static int memory_initialized = 0;
7
8 if(0 == memory_initialized) {
9 amp_memmgt_config_t config;
10 memset(&config, 0, sizeof(config));
11 config.malloc_fn = aos_malloc;
12 config.realloc_fn = aos_realloc;
13 config.free_fn = aos_free;
14 config.pt_num = 2;
15 config.trace_pt = 1; //b0001
16 config.mem_limit[1] = 512000;
17
18 amp_memmgt_init(&config);
19 memory_initialized = 1;
20 }
21 }
22
amp_malloc(unsigned int size)23 void *amp_malloc(unsigned int size)
24 {
25 void *ptr = NULL;
26
27 AMP_MEMMGT_MALLOC(ptr, size, 0);
28
29 return ptr;
30 }
31
amp_free(void * ptr)32 void amp_free(void *ptr)
33 {
34 AMP_MEMMGT_FREE(ptr, 0);
35 }
36
amp_calloc(unsigned int nitems,unsigned int size)37 void *amp_calloc(unsigned int nitems, unsigned int size)
38 {
39 void *ptr = NULL;
40
41 AMP_MEMMGT_MALLOC(ptr, nitems * size, 0);
42 if (ptr)
43 memset(ptr, 0, nitems * size);
44
45 return ptr;
46 }
47
amp_realloc(void * ptr,unsigned int size)48 void *amp_realloc(void *ptr, unsigned int size)
49 {
50 void *ptr_new = NULL;
51
52 if (ptr != NULL) {
53 AMP_MEMMGT_REALLOC(ptr_new, ptr, size, 0);
54 } else {
55 AMP_MEMMGT_MALLOC(ptr_new, size, 0);
56 }
57
58 return ptr_new;
59 }