1 /*
2 // Copyright (C) 2022 Beken Corporation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <common/bk_include.h>
17 #include "arm_arch.h"
18 #include <string.h>
19
20 #include "sys_rtos.h"
21 #include "uart_pub.h"
22 #include <os/mem.h>
23 #include <os/os.h>
24 #include "rtos_init.h"
25
26 //TODO remove it
27 void *beken_malloc( size_t xWantedSize );
28 void beken_free( void *pv );
29 void *beken_realloc( void *pv, size_t xWantedSize );
30
os_memcmp(const void * s1,const void * s2,UINT32 n)31 INT32 os_memcmp(const void *s1, const void *s2, UINT32 n)
32 {
33 return memcmp(s1, s2, (unsigned int)n);
34 }
35
os_memmove(void * out,const void * in,UINT32 n)36 void *os_memmove(void *out, const void *in, UINT32 n)
37 {
38 return memmove(out, in, n);
39 }
40
os_memcpy(void * out,const void * in,UINT32 n)41 void *os_memcpy(void *out, const void *in, UINT32 n)
42 {
43 return memcpy(out, in, n);
44 }
45
os_memset(void * b,int c,UINT32 len)46 void *os_memset(void *b, int c, UINT32 len)
47 {
48 return (void *)memset(b, c, (unsigned int)len);
49 }
50
os_memcmp_const(const void * a,const void * b,size_t len)51 int os_memcmp_const(const void *a, const void *b, size_t len)
52 {
53 return memcmp(a, b, len);
54 }
55
os_realloc(void * ptr,size_t size)56 void *os_realloc(void *ptr, size_t size)
57 {
58 return beken_realloc(ptr, size);
59 }
60
61 #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
62
os_malloc_debug(const char * func_name,int line,size_t size,int need_zero)63 void *os_malloc_debug(const char *func_name, int line, size_t size, int need_zero)
64 {
65 if (0 == need_zero) {
66 return (void *)beken_malloc(size);
67 } else {
68 void *p = (void *)beken_malloc(size);
69 if (NULL != p) {
70 (void *)memset(p, 0, size);
71 }
72 return p;
73 }
74 }
75
76 #else // #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
77
os_malloc(size_t size)78 void *os_malloc(size_t size)
79 {
80 return (void *)beken_malloc(size);
81 }
82
os_zalloc(size_t size)83 void * os_zalloc(size_t size)
84 {
85 void *n = (void *)os_malloc(size);
86
87 if (n)
88 os_memset(n, 0, size);
89 return n;
90 }
91
os_malloc_debug(const char * func_name,int line,size_t size,int need_zero)92 void *os_malloc_debug(const char *func_name, int line, size_t size, int need_zero)
93 {
94 if (need_zero) {
95 return (void *)os_zalloc(size);
96 }
97 return (void *)os_malloc(size);
98 }
99
100 #endif // #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
101
102
103
104 #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
105
os_free_debug(const char * func_name,int line,void * pv)106 void *os_free_debug(const char *func_name, int line, void *pv)
107 {
108 beken_free(pv);
109 return NULL;
110 }
111
112 #else // #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
113
os_free(void * ptr)114 void os_free(void *ptr)
115 {
116 beken_free(ptr);
117 }
118
os_free_debug(const char * func_name,int line,void * pv)119 void *os_free_debug(const char *func_name, int line, void *pv)
120 {
121 os_free(pv);
122 return NULL;
123 }
124
125 #endif // #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
126
os_malloc_wifi_buffer(size_t size)127 void* os_malloc_wifi_buffer(size_t size)
128 {
129 return (void*)beken_malloc(size);
130 }
131
os_show_memory_config_info(void)132 void os_show_memory_config_info(void)
133 {
134 }
135
136 #if (CONFIG_MALLOC_STATIS || CONFIG_MEM_DEBUG)
psram_malloc_debug(const char * func_name,int line,size_t size,int need_zero)137 void *psram_malloc_debug(const char *func_name, int line, size_t size, int need_zero)
138 {
139 return NULL;
140 }
141 #endif
142