Commit 53832595 by Michael Schmid

adapted assembler commands in atomic defines

parent 29d124d0
......@@ -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")
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -99,6 +99,7 @@ typedef pthread_cond_t embb_condition_t;
/* EMBB_PLATFORM_THREADING_POSIXTHREADS */
#elif defined EMBB_PLATFORM_THREADING_RTOSTASKS
#include <FreeRTOS/FreeRTOS.h>
#include <FreeRTOS/task.h>
#include <FreeRTOS/semphr.h>
......@@ -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
......
......@@ -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
......
......@@ -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})
......
......@@ -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!"
......
......@@ -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
......
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