/* * Copyright (C) Siddharth Bharat Purohit 2017 * This file is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /* wrappers for allocation functions Relies on linker wrap options Note that not all functions that have been wrapped are implemented here. The others are wrapped to ensure the function is not used without an implementation. If we need them then we can implement as needed. */ #include #include #include #include #include #include "stm32_util.h" #define MEM_REGION_FLAG_DMA_OK 1 #define MEM_REGION_FLAG_FAST 2 #define MEM_REGION_FLAG_SDCARD 4 static const struct memory_region { void *address; uint32_t size; uint32_t flags; } memory_regions[] = { HAL_MEMORY_REGIONS }; // the first memory region is already setup as the ChibiOS // default heap, so we will index from 1 in the allocators #define NUM_MEMORY_REGIONS (sizeof(memory_regions)/sizeof(memory_regions[0])) #if CH_CFG_USE_HEAP == TRUE static memory_heap_t heaps[NUM_MEMORY_REGIONS]; #define MIN_ALIGNMENT 8 #if defined(STM32H7) #define DMA_ALIGNMENT 32 #else #define DMA_ALIGNMENT 8 #endif // size of memory reserved for dma-capable alloc #ifndef DMA_RESERVE_SIZE #define DMA_RESERVE_SIZE 4096 #endif #if DMA_RESERVE_SIZE != 0 static memory_heap_t dma_reserve_heap; #endif /* initialise memory handling */ void malloc_init(void) { uint8_t i; for (i=1; i