Commit 1218ddc3 by Michael Schmid

atomic functions for 32bit, small changes in base_c

parent 14d6030e
...@@ -76,7 +76,7 @@ endif() ...@@ -76,7 +76,7 @@ endif()
# The set option will be converted to uppercase letters by cmake!! --> ON/OFF # 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. # 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(BUILD_EXAMPLES "Specify whether examples should be built" OFF)
option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON) option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON)
option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON) option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON)
......
...@@ -142,9 +142,9 @@ EMBB_DEFINE_AND_ASSIGN(4, "") ...@@ -142,9 +142,9 @@ EMBB_DEFINE_AND_ASSIGN(4, "")
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_AND_ASSIGN(1, "") EMBB_DEFINE_AND_ASSIGN(1, ".b")
EMBB_DEFINE_AND_ASSIGN(2, "") EMBB_DEFINE_AND_ASSIGN(2, ".h")
EMBB_DEFINE_AND_ASSIGN(4, "") EMBB_DEFINE_AND_ASSIGN(4, ".w")
#else #else
#error "Unknown architecture" #error "Unknown architecture"
......
...@@ -133,20 +133,23 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "") ...@@ -133,20 +133,23 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "")
EMBB_PLATFORM_INLINE int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \ 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_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) { \ EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired) { \
unsigned int result; \ EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result = 0; \
__asm__ __volatile__ ("eq" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[expected], %[desired]\n\t" \ __asm__ __volatile__ ( \
"mov %[desired], %[pointer_to_value]" \ "eq" EMBB_ATOMIC_X86_SIZE_SUFFIX " %%d15, %[expected], %[pointer_to_value]\n\t" \
: [result]"=r" (result)\ "cmov" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[pointer_to_value], %%d15, %[desired]\n\t" \
: [expected]"r" (*expected), [desired]"r" (desired), [pointer_to_value]"r"(*pointer_to_value)\ "cmovn" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[expected], %%d15, %[pointer_to_value]\n\t" \
: "memory", "cc" ); \ "mov %[result], %%d15\n\t" \
return (result & 0xFF); \ : [result]"+r" (result), [expected]"+r" (*expected), [pointer_to_value]"+r"(*pointer_to_value)\
: [desired]"r" (desired) \
: "%d15", "memory", "cc"); \
return result; \
} }
#else #else
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_COMPARE_AND_SWAP(1, "ANY.B") EMBB_DEFINE_COMPARE_AND_SWAP(1, "")
EMBB_DEFINE_COMPARE_AND_SWAP(2, "ANY.H") EMBB_DEFINE_COMPARE_AND_SWAP(2, "")
EMBB_DEFINE_COMPARE_AND_SWAP(4, "") EMBB_DEFINE_COMPARE_AND_SWAP(4, "")
#else #else
......
...@@ -123,10 +123,11 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "") ...@@ -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) \ #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_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) { \ (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" \ "dsync" \
: [new_value]"+r" (new_value) \ : [new_value]"+r" (new_value) \
: [value_p]"r" (*pointer_to_value) \ : [pointer_to_value]"r" (*pointer_to_value) \
: "memory", "cc" ); \ : "memory", "cc" ); \
return new_value; \ return new_value; \
} }
......
...@@ -117,9 +117,9 @@ EMBB_DEFINE_LOAD(4, "") ...@@ -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) { \ 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 */ \ /* no fence required for loads */ \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \ EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \
__asm__ __volatile__("mov" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \ __asm__ __volatile__("ld" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[value]" \
: "=r" (result) \ : [result]"=r" (result) \
: "r" (*pointer_to_value) \ : [value]"m" (*pointer_to_value) \
: "memory"); \ : "memory"); \
return result; \ return result; \
} }
...@@ -128,9 +128,9 @@ EMBB_DEFINE_LOAD(4, "") ...@@ -128,9 +128,9 @@ EMBB_DEFINE_LOAD(4, "")
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_LOAD(1, "") EMBB_DEFINE_LOAD(1, ".b")
EMBB_DEFINE_LOAD(2, "") EMBB_DEFINE_LOAD(2, ".h")
EMBB_DEFINE_LOAD(4, "") EMBB_DEFINE_LOAD(4, ".w")
#else #else
#error "Unknown architecture" #error "Unknown architecture"
......
...@@ -127,9 +127,9 @@ EMBB_DEFINE_OR_ASSIGN(4, "") ...@@ -127,9 +127,9 @@ EMBB_DEFINE_OR_ASSIGN(4, "")
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_OR_ASSIGN(1, "") EMBB_DEFINE_OR_ASSIGN(1, ".b")
EMBB_DEFINE_OR_ASSIGN(2, "") EMBB_DEFINE_OR_ASSIGN(2, ".h")
EMBB_DEFINE_OR_ASSIGN(4, "") EMBB_DEFINE_OR_ASSIGN(4, ".w")
#else #else
#error "Unknown architecture" #error "Unknown architecture"
......
...@@ -113,7 +113,7 @@ EMBB_DEFINE_STORE(4, "") ...@@ -113,7 +113,7 @@ EMBB_DEFINE_STORE(4, "")
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_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" \ __asm__ __volatile__("st" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[result], %[value]\n\t" \
"dsync" \ "dsync" \
: [result]"=m" (pointer_to_value)\ : [result]"=m" (*pointer_to_value)\
: [value]"r" (new_value)\ : [value]"r" (new_value)\
: "memory"); \ : "memory"); \
} // scm34681: check correct implementation } // scm34681: check correct implementation
......
...@@ -120,9 +120,8 @@ EMBB_DEFINE_SWAP(4, "") ...@@ -120,9 +120,8 @@ 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_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)\ 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.w" EMBB_ATOMIC_X86_SIZE_SUFFIX " %[pointer_to_value], %[new_value]" \
__asm__ __volatile__("swap" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \ : [pointer_to_value]"+m" (*pointer_to_value), [new_value]"+q" (new_value) \
: "+m" (pointer_to_value), "+r" (new_value) \
: \ : \
: "memory"); \ : "memory"); \
return new_value; \ return new_value; \
...@@ -132,9 +131,9 @@ EMBB_DEFINE_SWAP(4, "") ...@@ -132,9 +131,9 @@ EMBB_DEFINE_SWAP(4, "")
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_SWAP(1, ".w") EMBB_DEFINE_SWAP(1, "")
EMBB_DEFINE_SWAP(2, ".w") EMBB_DEFINE_SWAP(2, "")
EMBB_DEFINE_SWAP(4, ".w") EMBB_DEFINE_SWAP(4, "")
#else #else
#error "Unknown architecture" #error "Unknown architecture"
......
...@@ -119,7 +119,7 @@ EMBB_DEFINE_XOR_ASSIGN(4, "") ...@@ -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_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) volatile* pointer_to_value, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) 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" \ "dsync" \
: [value]"+r" (value) \ : [value]"+r" (value) \
: [value_p]"r" (*pointer_to_value) \ : [value_p]"r" (*pointer_to_value) \
...@@ -130,9 +130,9 @@ EMBB_DEFINE_XOR_ASSIGN(4, "") ...@@ -130,9 +130,9 @@ EMBB_DEFINE_XOR_ASSIGN(4, "")
#error "No atomic fetch and store implementation found" #error "No atomic fetch and store implementation found"
#endif #endif
EMBB_DEFINE_XOR_ASSIGN(1, "") EMBB_DEFINE_XOR_ASSIGN(1, ".b")
EMBB_DEFINE_XOR_ASSIGN(2, "") EMBB_DEFINE_XOR_ASSIGN(2, ".h")
EMBB_DEFINE_XOR_ASSIGN(4, "") EMBB_DEFINE_XOR_ASSIGN(4, ".w")
#else #else
#error "Unknown architecture" #error "Unknown architecture"
......
...@@ -102,6 +102,7 @@ typedef pthread_cond_t embb_condition_t; ...@@ -102,6 +102,7 @@ typedef pthread_cond_t embb_condition_t;
#include <FreeRTOS/FreeRTOS.h> #include <FreeRTOS/FreeRTOS.h>
#include <FreeRTOS/task.h> #include <FreeRTOS/task.h>
#include <FreeRTOS/semphr.h> #include <FreeRTOS/semphr.h>
#include <FreeRTOS/cond.h>
struct embb_internal_thread_arg_t; struct embb_internal_thread_arg_t;
...@@ -115,7 +116,7 @@ typedef struct embb_thread_t { ...@@ -115,7 +116,7 @@ typedef struct embb_thread_t {
typedef TaskHandle_t embb_thread_id_t; typedef TaskHandle_t embb_thread_id_t;
typedef SemaphoreHandle_t embb_mutex_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 #define EMBB_DURATION_MIN_NANOSECONDS 1000
......
...@@ -188,4 +188,52 @@ int embb_condition_destroy(embb_condition_t* condition_var) { ...@@ -188,4 +188,52 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS #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 */ #endif /* EMBB_PLATFORM_THREADING_RTOSTASKS */
...@@ -127,7 +127,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) { ...@@ -127,7 +127,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
#ifdef EMBB_PLATFORM_THREADING_RTOSTASKS #ifdef EMBB_PLATFORM_THREADING_RTOSTASKS
#ifdef __TriCore__ #ifdef __TriCore__
#define CORE_COUNT 3 #define CORE_COUNT 1
#endif #endif
......
...@@ -361,8 +361,8 @@ embb_thread_start_t func, void *arg) { ...@@ -361,8 +361,8 @@ embb_thread_start_t func, void *arg) {
thread->embb_internal_arg->arg = arg; thread->embb_internal_arg->arg = arg;
status = xTaskCreate( (TaskFunction_t) embb_internal_thread_start, // entry function status = xTaskCreate( (TaskFunction_t) embb_internal_thread_start, // entry function
0, // task name (not needed) "EMBB_Task", // task name (not needed)
128, // stack size 300, // stack size
thread->embb_internal_arg, // parameters thread->embb_internal_arg, // parameters
1, // priority 1, // priority
thread->embb_internal_handle); // thread handle thread->embb_internal_handle); // thread handle
......
...@@ -103,3 +103,12 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { ...@@ -103,3 +103,12 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */ #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
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