1 /* 2 * Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /* 8 * @file zephyr/alloc.h 9 * @brief zephyr libmetal memory allocattion definitions. 10 */ 11 12 #ifndef __METAL_ALLOC__H__ 13 #error "Include metal/alloc.h instead of metal/zephyr/alloc.h" 14 #endif 15 16 #ifndef __METAL_ZEPHYR_ALLOC__H__ 17 #define __METAL_ZEPHYR_ALLOC__H__ 18 19 #include <zephyr/kernel.h> 20 #include <stdlib.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #if (K_HEAP_MEM_POOL_SIZE > 0) __metal_allocate_memory(unsigned int size)27static inline void *__metal_allocate_memory(unsigned int size) 28 { 29 return k_malloc(size); 30 } 31 __metal_free_memory(void * ptr)32static inline void __metal_free_memory(void *ptr) 33 { 34 k_free(ptr); 35 } 36 #else 37 38 void *metal_zephyr_allocate_memory(unsigned int size); 39 void metal_zephyr_free_memory(void *ptr); 40 41 static inline void *__metal_allocate_memory(unsigned int size) 42 { 43 return metal_zephyr_allocate_memory(size); 44 } 45 46 static inline void __metal_free_memory(void *ptr) 47 { 48 metal_zephyr_free_memory(ptr); 49 } 50 #endif /* K_HEAP_MEM_POOL_SIZE */ 51 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif /* __METAL_ZEPHYR_ALLOC__H__ */ 58