From 41f038e0400b4bfcd0bf2f534dec28dbdc6561a8 Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Fri, 13 Jan 2017 11:57:15 +0100 Subject: [PATCH] use of FreeRTOS malloc and free, small changes --- CMakeCommon/SetCompilerFlags.cmake | 2 +- TC_Toolchain.cmake | 14 +++++++------- base_c/CMakeLists.txt | 12 ++++++------ base_c/include/embb/base/c/internal/config.h | 4 ++-- base_c/src/core_set.c | 4 ++-- base_c/src/log.c | 3 +++ base_c/src/memory_allocation.c | 8 ++++---- base_c/src/thread.c | 39 ++++++++++++++------------------------- partest.tar | Bin 161792 -> 0 bytes 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/CMakeCommon/SetCompilerFlags.cmake b/CMakeCommon/SetCompilerFlags.cmake index 3320ad0..a34734f 100644 --- a/CMakeCommon/SetCompilerFlags.cmake +++ b/CMakeCommon/SetCompilerFlags.cmake @@ -30,7 +30,7 @@ function(SetGNUCompilerFlags compiler_libs) set(compiler_libs PARENT_SCOPE) set(common_flags "-fno-common -Os -std=c99") set(warning_flags "-W -Wall -Wextra -Wdiv-by-zero -Warray-bounds -Wcast-align -Wignored-qualifiers -Wformat -Wformat-security") - set(target_flags "-DAPPKIT_TC277TFT -fshort-double -mcpu=tc27xx -mversion-info") + set(target_flags "-DAPPKIT_TC277TFT -DEMBB_DEBUG -fshort-double -mcpu=tc27xx -mversion-info") if (WARNINGS_ARE_ERRORS STREQUAL ON) set(warning_flags "${warning_flags} -Werror") diff --git a/TC_Toolchain.cmake b/TC_Toolchain.cmake index 109479c..fcf0029 100644 --- a/TC_Toolchain.cmake +++ b/TC_Toolchain.cmake @@ -1,23 +1,23 @@ -# this one is important SET(CMAKE_SYSTEM_NAME Generic) -#this one not so much SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_SYSTEM_PROCESSOR __TriCore__) -#Add __TriCore__ to compiler flags +# add __TriCore__ to compiler flags add_definitions(-D__TriCore__) -#Add __TriCore__ to cmake flags +add_definitions(-DEMBB_OS_FREERTOS) +# add __TriCore__ to cmake flags set(__TriCore__ 1) +set(EMBB_OS_FREERTOS 1) # specify the cross compiler SET(CMAKE_C_COMPILER C:/HighTec/toolchains/tricore/v4.6.6.0-infineon-1.1/bin/tricore-gcc.exe) SET(CMAKE_CXX_COMPILER C:/HighTec/toolchains/tricore/v4.6.6.0-infineon-1.1/bin/tricore-g++.exe) -# where is the target environment +# target environment SET(CMAKE_FIND_ROOT_PATH C:/HighTec/toolchains/tricore/v4.6.6.0-infineon-1.1) - -SET(FREE_RTOS_LIB_PATH C:/Data/Projekte/FreeRTOS_TC27x/) +# path to FreeRTOS +SET(FREE_RTOS_LIB_PATH C:/Data/Projekte/FreeRTOS_TC27x) # search for programs in the build host directories SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) diff --git a/base_c/CMakeLists.txt b/base_c/CMakeLists.txt index e3e353b..190a6d2 100644 --- a/base_c/CMakeLists.txt +++ b/base_c/CMakeLists.txt @@ -73,12 +73,12 @@ if(MSVC) endif() - -set(CMAKE_CXX_STANDARD_LIBRARIES ${FREE_RTOS_LIB_PATH}/iRom/libFreeRTOS_Lib.a) -set(CMAKE_C_STANDARD_LIBRARIES ${FREE_RTOS_LIB_PATH}/iRom/libFreeRTOS_Lib.a) -set(CMAKE_INSTALL_RPATH ${FREE_RTOS_LIB_PATH}) -file(GLOB_RECURSE FREE_RTOS_HEADERS "${FREE_RTOS_LIB_PATH}/*.h") - +if(DEFINED EMBB_OS_FREERTOS) + #set(CMAKE_CXX_STANDARD_LIBRARIES ${FREE_RTOS_LIB_PATH}/iRom/libFreeRTOS_Lib.a) + #set(CMAKE_C_STANDARD_LIBRARIES ${FREE_RTOS_LIB_PATH}/iRom/libFreeRTOS_Lib.a) + #set(CMAKE_INSTALL_RPATH ${FREE_RTOS_LIB_PATH}) + file(GLOB_RECURSE FREE_RTOS_HEADERS "${FREE_RTOS_LIB_PATH}/*.h") +endif() ## CONFIGURATION diff --git a/base_c/include/embb/base/c/internal/config.h b/base_c/include/embb/base/c/internal/config.h index e679577..2fbfd11 100644 --- a/base_c/include/embb/base/c/internal/config.h +++ b/base_c/include/embb/base/c/internal/config.h @@ -47,7 +47,7 @@ #if defined(_M_IA64) || defined(_IA64) #define EMBB_PLATFORM_CACHE_LINE_SIZE 128 #elif defined(__TriCore__) -#define EMBB_PLATFORM_CACHE_LINE_SIZE 32 +#define EMBB_PLATFORM_CACHE_LINE_SIZE 16 #else #define EMBB_PLATFORM_CACHE_LINE_SIZE 64 #endif @@ -97,7 +97,7 @@ #if defined(EMBB_PLATFORM_COMPILER_MSVC) #define EMBB_PLATFORM_THREADING_WINTHREADS #elif defined(EMBB_PLATFORM_COMPILER_GNUC) - #if defined(EMBB_PLATFORM_ARCH_TC) + #if defined(EMBB_OS_FREERTOS) #define EMBB_PLATFORM_THREADING_RTOSTASKS #else #define EMBB_PLATFORM_THREADING_POSIXTHREADS diff --git a/base_c/src/core_set.c b/base_c/src/core_set.c index 969dba8..c8b1866 100644 --- a/base_c/src/core_set.c +++ b/base_c/src/core_set.c @@ -127,7 +127,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) { #ifdef EMBB_PLATFORM_THREADING_RTOSTASKS #ifdef __TriCore__ -#define CORE_COUNT 1 +#define CORE_COUNT 2 //scm34681: 3 #endif @@ -137,7 +137,7 @@ unsigned int embb_core_count_available() { -void embb_core_set_init(embb_core_set_t* core_set, int initializer) { // scm34681: rework +void embb_core_set_init(embb_core_set_t* core_set, int initializer) { assert(core_set != NULL); assert(embb_core_count_available() < 64 && "Core sets are only supported up to 64 processors!"); diff --git a/base_c/src/log.c b/base_c/src/log.c index 02e7bf4..f999203 100644 --- a/base_c/src/log.c +++ b/base_c/src/log.c @@ -102,12 +102,15 @@ void embb_log_write_internal( channel_str, log_level_str, msg_buffer); embb_log_global_log_function(log_context, buffer); #elif defined(EMBB_PLATFORM_COMPILER_GNUC) +#if defined(EMBB_OS_FREERTOS) +#else char msg_buffer[400]; char buffer[500]; vsnprintf(msg_buffer, sizeof(msg_buffer), message, argp); snprintf(buffer, sizeof(buffer), "[%s] - [%s] %s", channel_str, log_level_str, msg_buffer); embb_log_global_log_function(log_context, buffer); +#endif #else embb_log_global_log_function(log_context, "["); embb_log_global_log_function(log_context, channel_str); diff --git a/base_c/src/memory_allocation.c b/base_c/src/memory_allocation.c index 0a0b0fa..d238465 100644 --- a/base_c/src/memory_allocation.c +++ b/base_c/src/memory_allocation.c @@ -44,7 +44,7 @@ enum { void* embb_alloc(size_t bytes) { size_t bytes_to_allocate = 2 * sizeof(size_t)+bytes; - void* allocated = malloc(bytes_to_allocate); + void* allocated = pvPortMalloc(bytes_to_allocate); if (allocated == NULL) return NULL; @@ -75,7 +75,7 @@ void embb_free(void * ptr) { embb_atomic_fetch_and_add_long( &embb_bytes_allocated, (long)(0 - (size_t)(*bytes_allocated))); - free((size_t*)ptr - 2); + vPortFree((size_t*)ptr - 2); } void* embb_alloc_aligned(size_t alignment, size_t size) { @@ -98,7 +98,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) { size_t bytes_to_allocate = (n + 1)*alignment + (additional_bytes - 1); - char* allocated = (char *)malloc(bytes_to_allocate); + char* allocated = (char *)pvPortMalloc(bytes_to_allocate); if (allocated == NULL) return NULL; @@ -147,7 +147,7 @@ void embb_free_aligned(void* ptr) { embb_atomic_fetch_and_add_long( &embb_bytes_allocated, (long)((long)0 - ptr_conv[-3])); - free((void*)ptr_conv[-2]); + vPortFree((void*)ptr_conv[-2]); } size_t embb_get_bytes_allocated() { diff --git a/base_c/src/thread.c b/base_c/src/thread.c index 3f0f05d..5aaf003 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -304,6 +304,7 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { #ifdef EMBB_PLATFORM_THREADING_RTOSTASKS #include +#include /** * Used to wrap client thread start function and argument when calling internal @@ -347,6 +348,7 @@ void embb_thread_yield() { int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, embb_thread_start_t func, void *arg) { int status; + core_set_t rtos_core_set; if (thread == NULL) { return EMBB_ERROR; } @@ -356,16 +358,19 @@ embb_thread_start_t func, void *arg) { thread->embb_internal_handle = NULL; return EMBB_NOMEM; } - - thread->embb_internal_arg->func = func; - thread->embb_internal_arg->arg = arg; - status = xTaskCreate( (TaskFunction_t) embb_internal_thread_start, // entry function - "EMBB_Task", // task name (not needed) - 500, // stack size - thread->embb_internal_arg, // parameters - 1, // priority - thread->embb_internal_handle); // thread handle + rtos_core_set.rep = core_set->rep; + + thread->embb_internal_arg->func = func; + thread->embb_internal_arg->arg = arg; + + status = TaskCreateWithCoreSet( + (TaskFunction_t) embb_internal_thread_start, // entry function + 500, // stack depth + rtos_core_set, // core set + thread->embb_internal_arg, // parameters + thread->embb_internal_handle // thread handle + ); if (status != 1) { @@ -374,22 +379,6 @@ embb_thread_start_t func, void *arg) { return EMBB_ERROR; } - /*if (core_set != NULL) { // scm34681: implement core affinity - DWORD_PTR core_mask = 0; - DWORD bit_mask = 1; - assert(embb_core_count_available() < 64); - for (unsigned int i = 0; i < embb_core_count_available(); i++) { - if (embb_core_set_contains(core_set, i)) { - core_mask |= bit_mask; - } - bit_mask <<= 1; - } - if (SetThreadAffinityMask(thread->embb_internal_handle, core_mask) - == (DWORD_PTR)NULL) { - return EMBB_ERROR; - } -}*/ - return EMBB_SUCCESS; } diff --git a/partest.tar b/partest.tar index 6ec9367..5d4fa13 100644 Binary files a/partest.tar and b/partest.tar differ -- libgit2 0.26.0