From 53832595db16939cf3c4d079a0a858dddc03b1d0 Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Fri, 18 Nov 2016 14:51:25 +0100 Subject: [PATCH] adapted assembler commands in atomic defines --- CMakeCommon/SetCompilerFlags.cmake | 2 +- CMakeLists.txt | 24 +++++++++++++++--------- TC_Toolchain.cmake | 6 +++++- base_c/CMakeLists.txt | 9 +++++++++ base_c/include/embb/base/c/internal/atomic/and_assign.h | 20 ++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/compare_and_swap.h | 24 ++++++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/fetch_and_add.h | 20 ++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/load.h | 23 +++++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/memory_barrier.h | 10 ++++++++++ base_c/include/embb/base/c/internal/atomic/or_assign.h | 20 ++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/store.h | 20 ++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/swap.h | 22 ++++++++++++++++++++++ base_c/include/embb/base/c/internal/atomic/xor_assign.h | 22 ++++++++++++++++++++++ base_c/include/embb/base/c/internal/platform.h | 3 ++- base_c/src/thread.c | 2 +- base_cpp/CMakeLists.txt | 2 ++ base_cpp/include/embb/base/internal/platform.h | 18 +++++++++++++++++- base_cpp/src/thread.cc | 6 ++++++ 18 files changed, 239 insertions(+), 14 deletions(-) diff --git a/CMakeCommon/SetCompilerFlags.cmake b/CMakeCommon/SetCompilerFlags.cmake index 5de3734..3320ad0 100644 --- a/CMakeCommon/SetCompilerFlags.cmake +++ b/CMakeCommon/SetCompilerFlags.cmake @@ -28,7 +28,7 @@ function(SetGNUCompilerFlags compiler_libs) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if(DEFINED CMAKE_SYSTEM_PROCESSOR) set(compiler_libs PARENT_SCOPE) - set(common_flags "-fno-common -Os") + 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") diff --git a/CMakeLists.txt b/CMakeLists.txt index 676c4a8..06c2c01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,11 +104,9 @@ 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_directories(${FREE_RTOS_LIB_PATH}/include) + include(CMakeCommon/SetCompilerFlags.cmake) SetGNUCompilerFlags(compiler_libs compiler_flags) @@ -142,16 +140,22 @@ set(EXPECTED_EMBB_TEST_EXECUTABLES "embb_algorithms_cpp_test" "embb_dataflow_cpp_test" "embb_mtapi_c_test" "embb_mtapi_cpp_test" - "embb_mtapi_network_c_test" "embb_tasks_cpp_test" ) - -# if opencl is there, we also expect the mtapi opencl test to be generated -if(BUILD_OPENCL_PLUGIN STREQUAL ON) - list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_opencl_c_test") + +if(NOT __TriCore__) + list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_network_c_test") + # if opencl is there, we also expect the mtapi opencl test to be generated + if(BUILD_OPENCL_PLUGIN STREQUAL ON) + list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_opencl_c_test") + endif() +else() + message("-- MTAPI plugins will not be build on target 'TriCore'.") endif() + + ## Copy test execution script to local binaries folder if (DEFINED CYGWIN) @@ -182,10 +186,12 @@ CheckPartestInstall(${BUILD_TESTS} partest_includepath partest_libpath) add_subdirectory(base_c) add_subdirectory(base_cpp) add_subdirectory(mtapi_c) +if(NOT __TriCore__) add_subdirectory(mtapi_plugins_c/mtapi_network_c) if(BUILD_OPENCL_PLUGIN STREQUAL ON) add_subdirectory(mtapi_plugins_c/mtapi_opencl_c) endif() +endif() add_subdirectory(tasks_cpp) add_subdirectory(mtapi_cpp) add_subdirectory(containers_cpp) diff --git a/TC_Toolchain.cmake b/TC_Toolchain.cmake index 6d09948..6b16744 100644 --- a/TC_Toolchain.cmake +++ b/TC_Toolchain.cmake @@ -3,7 +3,11 @@ SET(CMAKE_SYSTEM_NAME Generic) #this one not so much SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_SYSTEM_PROCESSOR __TriCore__) -SET(__TriCore__ 1) + +#Add __TriCore__ to compiler flags +add_definitions(-D__TriCore__) +#Add __TriCore__ to cmake flags +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) diff --git a/base_c/CMakeLists.txt b/base_c/CMakeLists.txt index a05179d..e3e353b 100644 --- a/base_c/CMakeLists.txt +++ b/base_c/CMakeLists.txt @@ -72,6 +72,15 @@ 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") + + + ## CONFIGURATION # # Check headers and create configure file with preprocessor defines diff --git a/base_c/include/embb/base/c/internal/atomic/and_assign.h b/base_c/include/embb/base/c/internal/atomic/and_assign.h index 48871ca..be407ab 100644 --- a/base_c/include/embb/base/c/internal/atomic/and_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/and_assign.h @@ -126,6 +126,26 @@ EMBB_DEFINE_AND_ASSIGN(1, "b") EMBB_DEFINE_AND_ASSIGN(2, "h") EMBB_DEFINE_AND_ASSIGN(4, "") +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +// scm34681: add atomic methods (all headers) +#define EMBB_DEFINE_AND_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX)\ + EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_and_assign_, \ + EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \ + __asm__ __volatile__("and" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[value], %[value_p]\n\t" \ + "dsync" \ + : [value]"+r" (value) \ + : [value_p]"r" (*pointer_to_value)\ + : "memory"); \ + } +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_AND_ASSIGN(1, "") +EMBB_DEFINE_AND_ASSIGN(2, "") +EMBB_DEFINE_AND_ASSIGN(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/compare_and_swap.h b/base_c/include/embb/base/c/internal/atomic/compare_and_swap.h index 8de4e09..07dcd63 100644 --- a/base_c/include/embb/base/c/internal/atomic/compare_and_swap.h +++ b/base_c/include/embb/base/c/internal/atomic/compare_and_swap.h @@ -125,6 +125,30 @@ EMBB_DEFINE_COMPARE_AND_SWAP(1, "b") EMBB_DEFINE_COMPARE_AND_SWAP(2, "h") EMBB_DEFINE_COMPARE_AND_SWAP(4, "") + +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +// scm34681: use aurix instruction set +#define EMBB_DEFINE_COMPARE_AND_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \ + EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* expected, \ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired) { \ + unsigned int result; \ + __asm__ __volatile__ ("eq" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[expected], %[desired]\n\t" \ + "mov %[desired], %[pointer_to_value]" \ + : [result]"=r" (result)\ + : [expected]"r" (*expected), [desired]"r" (desired), [pointer_to_value]"r"(*pointer_to_value)\ + : "memory", "cc" ); \ + return (result & 0xFF); \ + } +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_COMPARE_AND_SWAP(1, "ANY.B") +EMBB_DEFINE_COMPARE_AND_SWAP(2, "ANY.H") +EMBB_DEFINE_COMPARE_AND_SWAP(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h b/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h index a165744..a8689be 100644 --- a/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h +++ b/base_c/include/embb/base/c/internal/atomic/fetch_and_add.h @@ -118,6 +118,26 @@ EMBB_DEFINE_FETCH_AND_ADD(1, "b") EMBB_DEFINE_FETCH_AND_ADD(2, "h") EMBB_DEFINE_FETCH_AND_ADD(4, "") +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_FETCH_AND_ADD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE) \ + (EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) { \ + __asm__ __volatile__ ("add" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[new_value], %[value_p]\n\t" \ + "dsync" \ + : [new_value]"+r" (new_value) \ + : [value_p]"r" (*pointer_to_value) \ + : "memory", "cc" ); \ + return new_value; \ + } +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_FETCH_AND_ADD(1, ".b") +EMBB_DEFINE_FETCH_AND_ADD(2, ".h") +EMBB_DEFINE_FETCH_AND_ADD(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/load.h b/base_c/include/embb/base/c/internal/atomic/load.h index 20094b5..ebe57c0 100644 --- a/base_c/include/embb/base/c/internal/atomic/load.h +++ b/base_c/include/embb/base/c/internal/atomic/load.h @@ -109,6 +109,29 @@ EMBB_DEFINE_LOAD(1, "b") EMBB_DEFINE_LOAD(2, "h") EMBB_DEFINE_LOAD(4, "") + +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_LOAD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \ + EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value) { \ + /* no fence required for loads */ \ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \ + __asm__ __volatile__("mov" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \ + : "=r" (result) \ + : "r" (*pointer_to_value) \ + : "memory"); \ + return result; \ + } + +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_LOAD(1, "") +EMBB_DEFINE_LOAD(2, "") +EMBB_DEFINE_LOAD(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/memory_barrier.h b/base_c/include/embb/base/c/internal/atomic/memory_barrier.h index 392366f..547a320 100644 --- a/base_c/include/embb/base/c/internal/atomic/memory_barrier.h +++ b/base_c/include/embb/base/c/internal/atomic/memory_barrier.h @@ -60,6 +60,16 @@ EMBB_PLATFORM_INLINE void embb_atomic_memory_barrier() { __asm__ __volatile__ ("dmb" : : : "memory"); } +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +// Read/write barrier +EMBB_PLATFORM_INLINE void embb_atomic_memory_barrier() { + __asm__ __volatile__ ("isync" : : : "memory"); +} +#else +#error "No atomic fetch and store implementation found" +#endif + #endif #endif //DOXYGEN diff --git a/base_c/include/embb/base/c/internal/atomic/or_assign.h b/base_c/include/embb/base/c/internal/atomic/or_assign.h index 9c76cf8..5709fb4 100644 --- a/base_c/include/embb/base/c/internal/atomic/or_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/or_assign.h @@ -111,6 +111,26 @@ EMBB_DEFINE_OR_ASSIGN(1, "b") EMBB_DEFINE_OR_ASSIGN(2, "h") EMBB_DEFINE_OR_ASSIGN(4, "") +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_OR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)(\ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \ + __asm__ __volatile__("or" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[value], %[value_p]\n\t" \ + "dsync" \ + : [value]"+r" (value) \ + : [value_p]"r" (*pointer_to_value) \ + : "memory"); \ + } + +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_OR_ASSIGN(1, "") +EMBB_DEFINE_OR_ASSIGN(2, "") +EMBB_DEFINE_OR_ASSIGN(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/store.h b/base_c/include/embb/base/c/internal/atomic/store.h index fdb6a40..512768e 100644 --- a/base_c/include/embb/base/c/internal/atomic/store.h +++ b/base_c/include/embb/base/c/internal/atomic/store.h @@ -106,6 +106,26 @@ EMBB_DEFINE_STORE(1, "b") EMBB_DEFINE_STORE(2, "h") EMBB_DEFINE_STORE(4, "") +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_STORE(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX)\ + EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) {\ + __asm__ __volatile__("st" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[value]\n\t" \ + "dsync" \ + : [result]"=m" (pointer_to_value)\ + : [value]"r" (new_value)\ + : "memory"); \ + } // scm34681: check correct implementation + +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_STORE(1, ".b") +EMBB_DEFINE_STORE(2, ".h") +EMBB_DEFINE_STORE(4, ".w") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/swap.h b/base_c/include/embb/base/c/internal/atomic/swap.h index 70c397c..f2f125b 100644 --- a/base_c/include/embb/base/c/internal/atomic/swap.h +++ b/base_c/include/embb/base/c/internal/atomic/swap.h @@ -114,6 +114,28 @@ EMBB_DEFINE_SWAP(1, "b") EMBB_DEFINE_SWAP(2, "h") EMBB_DEFINE_SWAP(4, "") +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value)\ + { \ + /*the lock prefix is implicit for xchg*/ \ + __asm__ __volatile__("swap" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \ + : "+m" (pointer_to_value), "+r" (new_value) \ + : \ + : "memory"); \ + return new_value; \ + } + +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_SWAP(1, ".w") +EMBB_DEFINE_SWAP(2, ".w") +EMBB_DEFINE_SWAP(4, ".w") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/atomic/xor_assign.h b/base_c/include/embb/base/c/internal/atomic/xor_assign.h index 8de71fe..1814316 100644 --- a/base_c/include/embb/base/c/internal/atomic/xor_assign.h +++ b/base_c/include/embb/base/c/internal/atomic/xor_assign.h @@ -112,6 +112,28 @@ EMBB_DEFINE_XOR_ASSIGN(1, "b") EMBB_DEFINE_XOR_ASSIGN(2, "h") EMBB_DEFINE_XOR_ASSIGN(4, "") + +#elif defined(EMBB_PLATFORM_ARCH_TC) +#if defined(EMBB_PLATFORM_COMPILER_GNUC) +#define EMBB_DEFINE_XOR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \ + EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)(\ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \ + __asm__ __volatile__("lock xor" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[value], %[value_p]\n\t" \ + "dsync" \ + : [value]"+r" (value) \ + : [value_p]"r" (*pointer_to_value) \ + : "memory"); \ + } + +#else +#error "No atomic fetch and store implementation found" +#endif + +EMBB_DEFINE_XOR_ASSIGN(1, "") +EMBB_DEFINE_XOR_ASSIGN(2, "") +EMBB_DEFINE_XOR_ASSIGN(4, "") + #else #error "Unknown architecture" #endif diff --git a/base_c/include/embb/base/c/internal/platform.h b/base_c/include/embb/base/c/internal/platform.h index 3a6e505..7420331 100644 --- a/base_c/include/embb/base/c/internal/platform.h +++ b/base_c/include/embb/base/c/internal/platform.h @@ -99,6 +99,7 @@ typedef pthread_cond_t embb_condition_t; /* EMBB_PLATFORM_THREADING_POSIXTHREADS */ #elif defined EMBB_PLATFORM_THREADING_RTOSTASKS +#include #include #include @@ -112,7 +113,7 @@ typedef struct embb_thread_t { struct embb_internal_thread_arg_t* embb_internal_arg; } embb_thread_t; -typedef TaskStatus_t embb_thread_id_t; +typedef TaskHandle_t embb_thread_id_t; typedef SemaphoreHandle_t embb_mutex_t; typedef SemaphoreHandle_t embb_condition_t; // scm34681: implement FreeRTOS condition variable diff --git a/base_c/src/thread.c b/base_c/src/thread.c index 773e1ab..138a919 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -360,7 +360,7 @@ embb_thread_start_t func, void *arg) { thread->embb_internal_arg->func = func; thread->embb_internal_arg->arg = arg; - status = xTaskCreate( embb_internal_thread_start, // entry function + status = xTaskCreate( (TaskFunction_t) embb_internal_thread_start, // entry function 0, // task name (not needed) 128, // stack size thread->embb_internal_arg, // parameters diff --git a/base_cpp/CMakeLists.txt b/base_cpp/CMakeLists.txt index e7cfd27..8b9c587 100644 --- a/base_cpp/CMakeLists.txt +++ b/base_cpp/CMakeLists.txt @@ -27,6 +27,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/../base_c/include ) + + ## BUILD TARGETS # add_library (embb_base_cpp ${EMBB_BASE_CPP_SOURCES} ${EMBB_BASE_CPP_HEADERS}) diff --git a/base_cpp/include/embb/base/internal/platform.h b/base_cpp/include/embb/base/internal/platform.h index 65b82f1..ed70e5d 100644 --- a/base_cpp/include/embb/base/internal/platform.h +++ b/base_cpp/include/embb/base/internal/platform.h @@ -64,7 +64,23 @@ typedef embb_condition_t ConditionVariableType; } // namespace base } // namespace embb -#else // EMBB_PLATFORM_THREADING_POSIXTHREADS +// EMBB_PLATFORM_THREADING_POSIXTHREADS +#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS + +namespace embb { +namespace base { +namespace internal { + +typedef embb_thread_t ThreadType; +typedef embb_thread_id_t IDType; +typedef embb_mutex_t MutexType; +typedef embb_condition_t ConditionVariableType; + +} // namespace internal +} // namespace base +} // namespace embb + +#else //EMBB_PLATFORM_THREADING_RTOSTASKS #error "No threading platform defined!" diff --git a/base_cpp/src/thread.cc b/base_cpp/src/thread.cc index 3766dd9..280274d 100644 --- a/base_cpp/src/thread.cc +++ b/base_cpp/src/thread.cc @@ -61,6 +61,8 @@ void Thread::Join() { Thread::ID Thread::GetID() { #if defined EMBB_PLATFORM_THREADING_WINTHREADS return Thread::ID(GetCurrentThreadId()); +#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS + return Thread::ID(rep_.embb_internal_handle); // scm34681: check if this works with rtos tasks #elif defined EMBB_PLATFORM_THREADING_POSIXTHREADS return Thread::ID(rep_.embb_internal_handle); #endif @@ -69,6 +71,8 @@ Thread::ID Thread::GetID() { bool operator==(Thread::ID lhs, Thread::ID rhs) { #if defined EMBB_PLATFORM_THREADING_WINTHREADS return lhs.id_ == rhs.id_; +#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS + return lhs.id_ == rhs.id_; // scm34681 check if this works with rtos tasks #else return pthread_equal(lhs.id_, rhs.id_) != 0; #endif @@ -77,6 +81,8 @@ bool operator==(Thread::ID lhs, Thread::ID rhs) { bool operator!=(Thread::ID lhs, Thread::ID rhs) { #if defined EMBB_PLATFORM_THREADING_WINTHREADS return lhs.id_ != rhs.id_; +#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS + return lhs.id_ != rhs.id_; // scm34681 check if this works with rtos tasks #else return pthread_equal(lhs.id_, rhs.id_) == 0; #endif -- libgit2 0.26.0