1 /* 2 * Copyright (c) 2025 Croxel Inc. 3 * Copyright (c) 2025 CogniPilot Foundation 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <stddef.h> 9 #include <zephyr/kernel.h> 10 #include <zephyr/sys/check.h> 11 12 #define DT_DRV_COMPAT brcm_afbr_s50 13 #define NUM_AFBR_INST DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) 14 15 BUILD_ASSERT(NUM_AFBR_INST > 0, "Invalid number of AFBR-S50 instances"); 16 17 /** Defined separate memslab to isolate library from the other components. 18 * Through debugging, the library requests an initial allocation of ~4-KiB, 19 * which is why the total pool is sized to 8-KiB per instance. 20 */ 21 K_MEM_SLAB_DEFINE(argus_memslab, 64, 128 * NUM_AFBR_INST, sizeof(void *)); 22 Argus_Malloc(size_t size)23void *Argus_Malloc(size_t size) 24 { 25 void *ptr = NULL; 26 int err; 27 28 err = k_mem_slab_alloc(&argus_memslab, &ptr, K_NO_WAIT); 29 30 CHECKIF(err != 0 || ptr == NULL) { 31 return NULL; 32 } 33 34 return ptr; 35 } 36 Argus_Free(void * ptr)37void Argus_Free(void *ptr) 38 { 39 k_mem_slab_free(&argus_memslab, ptr); 40 } 41