From 68d56d947ecf011dea38d8a55691f62302ec8318 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Sun, 18 Mar 2018 12:44:26 +0100 Subject: [PATCH] - made memory alignment configurable --- config/stack_config.h | 3 +++ config/stack_config.h.cmake | 3 +++ src/common/simple_allocator.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/config/stack_config.h b/config/stack_config.h index 770353c2..aec739c3 100644 --- a/config/stack_config.h +++ b/config/stack_config.h @@ -157,6 +157,9 @@ /* include support for IEC 61850 log services */ #define CONFIG_IEC61850_LOG_SERVICE 1 +/* Force memory alignment - required for some platforms (required more memory for buffered reporting) */ +#define CONFIG_IEC61850_FORCE_MEMORY_ALIGNMENT 1 + /* overwrite default results for MMS identify service */ //#define CONFIG_DEFAULT_MMS_VENDOR_NAME "libiec61850.com" //#define CONFIG_DEFAULT_MMS_MODEL_NAME "LIBIEC61850" diff --git a/config/stack_config.h.cmake b/config/stack_config.h.cmake index c36f782d..6e9197f7 100644 --- a/config/stack_config.h.cmake +++ b/config/stack_config.h.cmake @@ -151,6 +151,9 @@ /* include support for IEC 61850 log services */ #cmakedefine01 CONFIG_IEC61850_LOG_SERVICE +/* Force memory alignment - required for some platforms (required more memory for buffered reporting) */ +#define CONFIG_IEC61850_FORCE_MEMORY_ALIGNMENT 1 + /* default results for MMS identify service */ #define CONFIG_DEFAULT_MMS_VENDOR_NAME "libiec61850.com" #define CONFIG_DEFAULT_MMS_MODEL_NAME "LIBIEC61850" diff --git a/src/common/simple_allocator.c b/src/common/simple_allocator.c index 2c4c5a24..d9bcd223 100644 --- a/src/common/simple_allocator.c +++ b/src/common/simple_allocator.c @@ -23,6 +23,7 @@ #include "libiec61850_platform_includes.h" #include "simple_allocator.h" +#include "stack_config.h" void MemoryAllocator_init(MemoryAllocator* self, char* memoryBlock, int size) @@ -35,10 +36,14 @@ MemoryAllocator_init(MemoryAllocator* self, char* memoryBlock, int size) int inline MemoryAllocator_getAlignedSize(int size) { +#if (CONFIG_IEC61850_FORCE_MEMORY_ALIGNMENT == 1) if ((size % sizeof(void*)) > 0) return sizeof(void*) * ((size + sizeof(void*) - 1) / sizeof(void*)); else return size; +#else + return size; +#endif } char*