Commit 41f038e0 by Michael Schmid

use of FreeRTOS malloc and free, small changes

parent 269af5d7
......@@ -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")
......
# 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)
......
......@@ -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
......
......@@ -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
......
......@@ -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!");
......
......@@ -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);
......
......@@ -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() {
......
......@@ -304,6 +304,7 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS
#include <FreeRTOS/task.h>
#include <FreeRTOS/core_set.h>
/**
* 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;
}
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment