diff --git a/CMakeLists.txt b/CMakeLists.txt index 68257df..1e87110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) 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 be407ab..abdcfba 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 @@ -142,9 +142,9 @@ EMBB_DEFINE_AND_ASSIGN(4, "") #error "No atomic fetch and store implementation found" #endif -EMBB_DEFINE_AND_ASSIGN(1, "") -EMBB_DEFINE_AND_ASSIGN(2, "") -EMBB_DEFINE_AND_ASSIGN(4, "") +EMBB_DEFINE_AND_ASSIGN(1, ".b") +EMBB_DEFINE_AND_ASSIGN(2, ".h") +EMBB_DEFINE_AND_ASSIGN(4, ".w") #else #error "Unknown architecture" 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 07dcd63..0cf1335 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 @@ -133,20 +133,23 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "") 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); \ + EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result = 0; \ + __asm__ __volatile__ ( \ + "eq" EMBB_ATOMIC_X86_SIZE_SUFFIX " %%d15, %[expected], %[pointer_to_value]\n\t" \ + "cmov" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[pointer_to_value], %%d15, %[desired]\n\t" \ + "cmovn" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[expected], %%d15, %[pointer_to_value]\n\t" \ + "mov %[result], %%d15\n\t" \ + : [result]"+r" (result), [expected]"+r" (*expected), [pointer_to_value]"+r"(*pointer_to_value)\ + : [desired]"r" (desired) \ + : "%d15", "memory", "cc"); \ + return result; \ } #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(1, "") +EMBB_DEFINE_COMPARE_AND_SWAP(2, "") EMBB_DEFINE_COMPARE_AND_SWAP(4, "") #else 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 a8689be..566daa5 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 @@ -123,10 +123,11 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "") #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" \ + \ + __asm__ __volatile__ ("add" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[new_value],%[new_value], %[pointer_to_value]\n\t" \ "dsync" \ : [new_value]"+r" (new_value) \ - : [value_p]"r" (*pointer_to_value) \ + : [pointer_to_value]"r" (*pointer_to_value) \ : "memory", "cc" ); \ return new_value; \ } 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 ebe57c0..0b24e30 100644 --- a/base_c/include/embb/base/c/internal/atomic/load.h +++ b/base_c/include/embb/base/c/internal/atomic/load.h @@ -117,9 +117,9 @@ EMBB_DEFINE_LOAD(4, "") 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) \ + __asm__ __volatile__("ld" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[value]" \ + : [result]"=r" (result) \ + : [value]"m" (*pointer_to_value) \ : "memory"); \ return result; \ } @@ -128,9 +128,9 @@ EMBB_DEFINE_LOAD(4, "") #error "No atomic fetch and store implementation found" #endif -EMBB_DEFINE_LOAD(1, "") -EMBB_DEFINE_LOAD(2, "") -EMBB_DEFINE_LOAD(4, "") +EMBB_DEFINE_LOAD(1, ".b") +EMBB_DEFINE_LOAD(2, ".h") +EMBB_DEFINE_LOAD(4, ".w") #else #error "Unknown architecture" 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 5709fb4..d8b1368 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 @@ -127,9 +127,9 @@ EMBB_DEFINE_OR_ASSIGN(4, "") #error "No atomic fetch and store implementation found" #endif -EMBB_DEFINE_OR_ASSIGN(1, "") -EMBB_DEFINE_OR_ASSIGN(2, "") -EMBB_DEFINE_OR_ASSIGN(4, "") +EMBB_DEFINE_OR_ASSIGN(1, ".b") +EMBB_DEFINE_OR_ASSIGN(2, ".h") +EMBB_DEFINE_OR_ASSIGN(4, ".w") #else #error "Unknown architecture" 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 512768e..4a1db7f 100644 --- a/base_c/include/embb/base/c/internal/atomic/store.h +++ b/base_c/include/embb/base/c/internal/atomic/store.h @@ -113,7 +113,7 @@ EMBB_DEFINE_STORE(4, "") 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)\ + : [result]"=m" (*pointer_to_value)\ : [value]"r" (new_value)\ : "memory"); \ } // scm34681: check correct implementation 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 f2f125b..06b1e15 100644 --- a/base_c/include/embb/base/c/internal/atomic/swap.h +++ b/base_c/include/embb/base/c/internal/atomic/swap.h @@ -120,10 +120,9 @@ EMBB_DEFINE_SWAP(4, "") 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) \ - : \ + __asm__ __volatile__("swap.w" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[pointer_to_value], %[new_value]" \ + : [pointer_to_value]"+m" (*pointer_to_value), [new_value]"+q" (new_value) \ + : \ : "memory"); \ return new_value; \ } @@ -132,9 +131,9 @@ EMBB_DEFINE_SWAP(4, "") #error "No atomic fetch and store implementation found" #endif -EMBB_DEFINE_SWAP(1, ".w") -EMBB_DEFINE_SWAP(2, ".w") -EMBB_DEFINE_SWAP(4, ".w") +EMBB_DEFINE_SWAP(1, "") +EMBB_DEFINE_SWAP(2, "") +EMBB_DEFINE_SWAP(4, "") #else #error "Unknown architecture" 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 1814316..dce874e 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 @@ -119,7 +119,7 @@ EMBB_DEFINE_XOR_ASSIGN(4, "") 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" \ + __asm__ __volatile__("xor" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[value], %[value_p]\n\t" \ "dsync" \ : [value]"+r" (value) \ : [value_p]"r" (*pointer_to_value) \ @@ -130,9 +130,9 @@ EMBB_DEFINE_XOR_ASSIGN(4, "") #error "No atomic fetch and store implementation found" #endif -EMBB_DEFINE_XOR_ASSIGN(1, "") -EMBB_DEFINE_XOR_ASSIGN(2, "") -EMBB_DEFINE_XOR_ASSIGN(4, "") +EMBB_DEFINE_XOR_ASSIGN(1, ".b") +EMBB_DEFINE_XOR_ASSIGN(2, ".h") +EMBB_DEFINE_XOR_ASSIGN(4, ".w") #else #error "Unknown architecture" diff --git a/base_c/include/embb/base/c/internal/platform.h b/base_c/include/embb/base/c/internal/platform.h index 7420331..4f802bb 100644 --- a/base_c/include/embb/base/c/internal/platform.h +++ b/base_c/include/embb/base/c/internal/platform.h @@ -102,6 +102,7 @@ typedef pthread_cond_t embb_condition_t; #include #include #include +#include struct embb_internal_thread_arg_t; @@ -115,7 +116,7 @@ typedef struct embb_thread_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 +typedef cond_t embb_condition_t; #define EMBB_DURATION_MIN_NANOSECONDS 1000 diff --git a/base_c/src/condition_variable.c b/base_c/src/condition_variable.c index f5b7fdd..7ddd745 100644 --- a/base_c/src/condition_variable.c +++ b/base_c/src/condition_variable.c @@ -188,4 +188,52 @@ int embb_condition_destroy(embb_condition_t* condition_var) { #ifdef EMBB_PLATFORM_THREADING_RTOSTASKS +int embb_condition_init(embb_condition_t* condition_var) { + if (condition_var == NULL) { + return EMBB_ERROR; + } + int result = cond_init(condition_var); + return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; +} + +int embb_condition_notify_one(embb_condition_t* condition_var) { + if (condition_var == NULL) { + return EMBB_ERROR; + } + int result = cond_signal(condition_var); + return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; +} + +int embb_condition_notify_all(embb_condition_t* condition_var) { + if (condition_var == NULL) { + return EMBB_ERROR; + } + int result = cond_broadcast(condition_var); + return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; +} + +int embb_condition_wait(embb_condition_t* condition_var, embb_mutex_t* mutex) { + if (condition_var == NULL || mutex == NULL) { + return EMBB_ERROR; + } + int result = cond_wait(condition_var, mutex); + return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; +} + +int embb_condition_wait_until(embb_condition_t* condition_var, + embb_mutex_t* mutex, const embb_time_t* time) { + return EMBB_ERROR; /* scm34681: try something else */ +} + +int embb_condition_destroy(embb_condition_t* condition_var) { + if (condition_var == NULL) { + return EMBB_ERROR; + } + int status = cond_destroy(condition_var); + if (status != 0) { + return EMBB_ERROR; + } + return EMBB_SUCCESS; +} + #endif /* EMBB_PLATFORM_THREADING_RTOSTASKS */ diff --git a/base_c/src/core_set.c b/base_c/src/core_set.c index deec0a5..969dba8 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 3 +#define CORE_COUNT 1 #endif diff --git a/base_c/src/thread.c b/base_c/src/thread.c index 138a919..be449c1 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -361,8 +361,8 @@ embb_thread_start_t func, void *arg) { thread->embb_internal_arg->arg = arg; status = xTaskCreate( (TaskFunction_t) embb_internal_thread_start, // entry function - 0, // task name (not needed) - 128, // stack size + "EMBB_Task", // task name (not needed) + 300, // stack size thread->embb_internal_arg, // parameters 1, // priority thread->embb_internal_handle); // thread handle diff --git a/base_c/src/time.c b/base_c/src/time.c index 0b0d3fe..1b9171b 100644 --- a/base_c/src/time.c +++ b/base_c/src/time.c @@ -103,3 +103,12 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { #endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */ +#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS + +int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { + + return EMBB_ERROR; // scm34681: try something else + +} + +#endif /* EMBB_PLATFORM_THREADING_RTOSTASKS */ \ No newline at end of file