Commit 29d124d0 by Michael Schmid

added FreeRTOS implementation

parent dd88ea03
......@@ -26,36 +26,51 @@
#
function(SetGNUCompilerFlags compiler_libs)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(compiler_libs pthread rt PARENT_SCOPE)
# -Wall -> All warnings
# -Wextra -> Even more warnings
# -Werror -> Warnings are errors
set(warning_flags "-Wall -Wextra")
if (WARNINGS_ARE_ERRORS STREQUAL ON)
set(warning_flags "${warning_flags} -Werror")
endif()
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -std=c99 ${warning_flags}"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DEMBB_DEBUG"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_COVERAGE
"${CMAKE_C_FLAGS_COVERAGE} -O0 -fprofile-arcs -ftest-coverage"
PARENT_SCOPE)
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++03 ${warning_flags}"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DEMBB_DEBUG"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_COVERAGE
"${CMAKE_CXX_FLAGS_COVERAGE} -O0 -fprofile-arcs -ftest-coverage"
PARENT_SCOPE)
endif()
if(DEFINED CMAKE_SYSTEM_PROCESSOR)
set(compiler_libs PARENT_SCOPE)
set(common_flags "-fno-common -Os")
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")
if (WARNINGS_ARE_ERRORS STREQUAL ON)
set(warning_flags "${warning_flags} -Werror")
endif()
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${common_flags} ${warning_flags} ${target_flags}"
PARENT_SCOPE)
endif()
else()
set(compiler_libs pthread rt PARENT_SCOPE)
# -Wall -> All warnings
# -Wextra -> Even more warnings
# -Werror -> Warnings are errors
set(warning_flags "-Wall -Wextra")
if (WARNINGS_ARE_ERRORS STREQUAL ON)
set(warning_flags "${warning_flags} -Werror")
endif()
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -std=c99 ${warning_flags}"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DEMBB_DEBUG"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG"
PARENT_SCOPE)
set(CMAKE_C_FLAGS_COVERAGE
"${CMAKE_C_FLAGS_COVERAGE} -O0 -fprofile-arcs -ftest-coverage"
PARENT_SCOPE)
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++03 ${warning_flags}"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DEMBB_DEBUG"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG"
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_COVERAGE
"${CMAKE_CXX_FLAGS_COVERAGE} -O0 -fprofile-arcs -ftest-coverage"
PARENT_SCOPE)
endif()
endif()
endif()
endfunction()
......
......@@ -76,7 +76,7 @@ endif()
# The set option will be converted to uppercase letters by cmake!! --> ON/OFF
# Note that the help string (second argument) cannot be printed by cmake.
#
option(BUILD_TESTS "Specify whether tests should be built" ON)
option(BUILD_TESTS "Specify whether tests should be built" OFF)
option(BUILD_EXAMPLES "Specify whether examples should be built" OFF)
option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON)
option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON)
......@@ -104,6 +104,12 @@ else()
endif()
message(" (set with command line option -DUSE_AUTOMATIC_INITIALIZATION=ON/OFF)")
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)
set(__TriCore__ 1)
include(CMakeCommon/SetCompilerFlags.cmake)
SetGNUCompilerFlags(compiler_libs compiler_flags)
SetVisualStudioCompilerFlags(compiler_libs compiler_flags)
......
......@@ -2,7 +2,8 @@
SET(CMAKE_SYSTEM_NAME Generic)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR TriCore)
SET(CMAKE_SYSTEM_PROCESSOR __TriCore__)
SET(__TriCore__ 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER C:/HighTec/toolchains/tricore/v4.6.6.0-infineon-1.1/bin/tricore-gcc.exe)
......@@ -11,6 +12,9 @@ SET(CMAKE_CXX_COMPILER C:/HighTec/toolchains/tricore/v4.6.6.0-infineon-1.1/bin/t
# where is the 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_lib/)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
# for libraries and headers in the target directories
......
......@@ -46,6 +46,8 @@
*/
#if defined(_M_IA64) || defined(_IA64)
#define EMBB_PLATFORM_CACHE_LINE_SIZE 128
#elif defined(__TriCore__)
#define EMBB_PLATFORM_CACHE_LINE_SIZE 32
#else
#define EMBB_PLATFORM_CACHE_LINE_SIZE 64
#endif
......@@ -86,6 +88,8 @@
#define EMBB_PLATFORM_ARCH_X86
#elif defined(__arm__)
#define EMBB_PLATFORM_ARCH_ARM
#elif defined(__TriCore__)
#define EMBB_PLATFORM_ARCH_TC
#else
#define EMBB_PLATFORM_ARCH_UNKNOWN
#endif
......@@ -93,7 +97,11 @@
#if defined(EMBB_PLATFORM_COMPILER_MSVC)
#define EMBB_PLATFORM_THREADING_WINTHREADS
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_PLATFORM_THREADING_POSIXTHREADS
#if defined(EMBB_PLATFORM_ARCH_TC)
#define EMBB_PLATFORM_THREADING_RTOSTASKS
#else
#define EMBB_PLATFORM_THREADING_POSIXTHREADS
#endif
#else
#error "No thread implementation could be determined"
#endif
......
......@@ -71,6 +71,7 @@ typedef CONDITION_VARIABLE embb_condition_t;
#define EMBB_THREAD_SPECIFIC static __declspec(thread)
/* EMBB_PLATFORM_THREADING_WINTHREADS */
#elif defined EMBB_PLATFORM_THREADING_POSIXTHREADS
#include <pthread.h>
......@@ -95,7 +96,31 @@ typedef pthread_cond_t embb_condition_t;
#define EMBB_THREAD_SPECIFIC __thread
#else /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
/* EMBB_PLATFORM_THREADING_POSIXTHREADS */
#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS
#include <FreeRTOS/task.h>
#include <FreeRTOS/semphr.h>
struct embb_internal_thread_arg_t;
/**
* Opaque handle for a thread.
*/
typedef struct embb_thread_t {
TaskHandle_t embb_internal_handle;
struct embb_internal_thread_arg_t* embb_internal_arg;
} embb_thread_t;
typedef TaskStatus_t embb_thread_id_t;
typedef SemaphoreHandle_t embb_mutex_t;
typedef SemaphoreHandle_t embb_condition_t; // scm34681: implement FreeRTOS condition variable
#define EMBB_DURATION_MIN_NANOSECONDS 1000
#define EMBB_THREAD_SPECIFIC
#else /* EMBB_PLATFORM_THREADING_RTOSTASKS */
#error "No threading platform defined!"
......
......@@ -185,3 +185,7 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
}
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS
#endif /* EMBB_PLATFORM_THREADING_RTOSTASKS */
......@@ -125,6 +125,32 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS
#ifdef __TriCore__
#define CORE_COUNT 3
#endif
unsigned int embb_core_count_available() {
return CORE_COUNT;
}
void embb_core_set_init(embb_core_set_t* core_set, int initializer) { // scm34681: rework
assert(core_set != NULL);
assert(embb_core_count_available() < 64 &&
"Core sets are only supported up to 64 processors!");
if (initializer == 0) {
embb_bitset_clear_all(&core_set->rep);
} else {
embb_bitset_set_n(&core_set->rep, embb_core_count_available());
}
}
#endif EMBB_PLATFORM_THREADING_RTOSTASKS
void embb_core_set_add(embb_core_set_t* core_set, unsigned int core_number) {
assert(core_set != NULL);
assert(core_number < embb_core_count_available());
......
......@@ -178,6 +178,14 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
*/
malloc_addr = _aligned_malloc(size, alignment);
#elif defined EMBB_PLATFORM_COMPILER_GNUC
#ifdef __TRICORE__
/*
* The TriCore Toolchain uses obsolete function memalign() for
* aligned memory allocation.
*/
#include <malloc.h> // scm3681: rework
malloc_addr = memalign(alignment, size);
#else /* __TRICORE__ */
/*
* From the Documentation:
* The posix_memalign() function shall allocate size bytes aligned on a
......@@ -190,6 +198,7 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
int status = posix_memalign(&malloc_addr, alignment, size);
EMBB_UNUSED(status);
#endif
#endif
return malloc_addr;
}
......
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