Arduino AudioKit HAL
audio_mem.h
1 /*
2  * ESPRESSIF MIT License
3  *
4  * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef _AUDIO_MEM_H_
26 #define _AUDIO_MEM_H_
27 
28 #include <audio_types.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @brief Malloc memory in ADF
36  *
37  * @param[in] size memory size
38  *
39  * @return
40  * - valid pointer on success
41  * - NULL when any errors
42  */
43 void *audio_malloc(size_t size);
44 
45 /**
46  * @brief Free memory in ADF
47  *
48  * @param[in] ptr memory pointer
49  *
50  * @return
51  * - void
52  */
53 void audio_free(void *ptr);
54 
55 /**
56  * @brief Malloc memory in ADF, if spi ram is enabled, it will malloc memory in the spi ram
57  *
58  * @param[in] nmemb number of block
59  * @param[in] size block memory size
60  *
61  * @return
62  * - valid pointer on success
63  * - NULL when any errors
64  */
65 void *audio_calloc(size_t nmemb, size_t size);
66 
67 /**
68  * @brief Malloc memory in ADF, it will malloc to internal memory
69  *
70  * @param[in] nmemb number of block
71  * @param[in] size block memory size
72  *
73  * @return
74  * - valid pointer on success
75  * - NULL when any errors
76  */
77 void *audio_calloc_inner(size_t nmemb, size_t size);
78 
79 /**
80  * @brief Print heap memory status
81  *
82  * @param[in] tag tag of log
83  * @param[in] line line of log
84  * @param[in] func function name of log
85  *
86  * @return
87  * - void
88  */
89 void audio_mem_print(const char *tag, int line, const char *func);
90 
91 /**
92  * @brief Reallocate memory in ADF, if spi ram is enabled, it will allocate memory in the spi ram
93  *
94  * @param[in] ptr memory pointer
95  * @param[in] size block memory size
96  *
97  * @return
98  * - valid pointer on success
99  * - NULL when any errors
100  */
101 void *audio_realloc(void *ptr, size_t size);
102 
103 /**
104  * @brief Duplicate given string.
105  *
106  * Allocate new memory, copy contents of given string into it and return the pointer
107  *
108  * @param[in] str String to be duplicated
109  *
110  * @return
111  * - Pointer to new malloc'ed string
112  * - NULL otherwise
113  */
114 char *audio_strdup(const char *str);
115 
116 /**
117  * @brief SPI ram is enabled or not
118  *
119  * @return
120  * - true, spi ram is enabled
121  * - false, spi ram is not enabled
122  */
123 bool audio_mem_spiram_is_enabled(void);
124 
125 /**
126  * @brief Stack on external SPI ram is enabled or not
127  *
128  * @return
129  * - true, stack on spi ram is enabled
130  * - false, stack on spi ram is not enabled
131  */
132 bool audio_mem_spiram_stack_is_enabled(void);
133 
134 #define AUDIO_MEM_SHOW(x) audio_mem_print(x, __LINE__, __func__)
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /*_AUDIO_MEM_H_*/
Platform independent audio types.