1/*
2 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
3 * Permission to use, copy, modify, and/or distribute this software for
4 * any purpose with or without fee is hereby granted, provided that the
5 * above copyright notice and this permission notice appear in all copies.
6 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
12 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
13 */
14
15#ifndef _AOS_MEM_H
16#define _AOS_MEM_H
17
18#include "sal/os/aos_types.h"
19#ifdef KERNEL_MODULE
20#include "sal/os/linux/aos_mem_pvt.h"
21#else
22#include "sal/os/linux_user/aos_mem_pvt.h"
23#endif
24
25/**
26 * @g aos_mem mem
27 * @{
28 *
29 * @ig shim_ext
30 */
31
32/**
33 * @brief Allocate a memory buffer. Note it's a non-blocking call.
34 * This call can block.
35 *
36 * @param[in] size    buffer size
37 *
38 * @return Buffer pointer or NULL if there's not enough memory.
39 */
40static inline void *
41aos_mem_alloc(aos_size_t size)
42{
43    return __aos_mem_alloc(size);
44}
45
46/**
47 * @brief Free malloc'ed buffer
48 *
49 * @param[in] buf     buffer pointer allocated by aos_alloc()
50 * @param[in] size    buffer size
51 */
52static inline void
53aos_mem_free(void *buf)
54{
55    __aos_mem_free(buf);
56}
57
58/**
59 * @brief Move a memory buffer
60 *
61 * @param[in] dst     destination address
62 * @param[in] src     source address
63 * @param[in] size    buffer size
64 */
65static inline void
66aos_mem_copy(void *dst, void *src, aos_size_t size)
67{
68    __aos_mem_copy(dst, src, size);
69}
70
71/**
72 * @brief Fill a memory buffer
73 *
74 * @param[in] buf   buffer to be filled
75 * @param[in] b     byte to fill
76 * @param[in] size  buffer size
77 */
78static inline void
79aos_mem_set(void *buf, a_uint8_t b, aos_size_t size)
80{
81    __aos_mem_set(buf, b, size);
82}
83
84/**
85 * @brief Zero a memory buffer
86 *
87 * @param[in] buf   buffer to be zeroed
88 * @param[in] size  buffer size
89 */
90static inline void
91aos_mem_zero(void *buf, aos_size_t size)
92{
93    __aos_mem_zero(buf, size);
94}
95
96/**
97 * @brief Compare two memory buffers
98 *
99 * @param[in] buf1  first buffer
100 * @param[in] buf2  second buffer
101 * @param[in] size  buffer size
102 *
103 * @retval    0     equal
104 * @retval    1     not equal
105 */
106static inline int
107aos_mem_cmp(void *buf1, void *buf2, aos_size_t size)
108{
109    return __aos_mem_cmp(buf1, buf2, size);
110}
111
112/**
113 * @}
114 */
115
116#endif
117