Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1218ddc3
authored
Nov 30, 2016
by
Michael Schmid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
atomic functions for 32bit, small changes in base_c
parent
14d6030e
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
102 additions
and
40 deletions
+102
-40
CMakeLists.txt
+1
-1
base_c/include/embb/base/c/internal/atomic/and_assign.h
+3
-3
base_c/include/embb/base/c/internal/atomic/compare_and_swap.h
+12
-9
base_c/include/embb/base/c/internal/atomic/fetch_and_add.h
+3
-2
base_c/include/embb/base/c/internal/atomic/load.h
+6
-6
base_c/include/embb/base/c/internal/atomic/or_assign.h
+3
-3
base_c/include/embb/base/c/internal/atomic/store.h
+1
-1
base_c/include/embb/base/c/internal/atomic/swap.h
+6
-7
base_c/include/embb/base/c/internal/atomic/xor_assign.h
+4
-4
base_c/include/embb/base/c/internal/platform.h
+2
-1
base_c/src/condition_variable.c
+48
-0
base_c/src/core_set.c
+1
-1
base_c/src/thread.c
+2
-2
base_c/src/time.c
+10
-0
No files found.
CMakeLists.txt
View file @
1218ddc3
...
...
@@ -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"
O
N
)
option
(
BUILD_TESTS
"Specify whether tests should be built"
O
FF
)
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
)
...
...
base_c/include/embb/base/c/internal/atomic/and_assign.h
View file @
1218ddc3
...
...
@@ -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"
...
...
base_c/include/embb/base/c/internal/atomic/compare_and_swap.h
View file @
1218ddc3
...
...
@@ -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
...
...
base_c/include/embb/base/c/internal/atomic/fetch_and_add.h
View file @
1218ddc3
...
...
@@ -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; \
}
...
...
base_c/include/embb/base/c/internal/atomic/load.h
View file @
1218ddc3
...
...
@@ -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"
...
...
base_c/include/embb/base/c/internal/atomic/or_assign.h
View file @
1218ddc3
...
...
@@ -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"
...
...
base_c/include/embb/base/c/internal/atomic/store.h
View file @
1218ddc3
...
...
@@ -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
...
...
base_c/include/embb/base/c/internal/atomic/swap.h
View file @
1218ddc3
...
...
@@ -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"
...
...
base_c/include/embb/base/c/internal/atomic/xor_assign.h
View file @
1218ddc3
...
...
@@ -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"
...
...
base_c/include/embb/base/c/internal/platform.h
View file @
1218ddc3
...
...
@@ -102,6 +102,7 @@ typedef pthread_cond_t embb_condition_t;
#include <FreeRTOS/FreeRTOS.h>
#include <FreeRTOS/task.h>
#include <FreeRTOS/semphr.h>
#include <FreeRTOS/cond.h>
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
...
...
base_c/src/condition_variable.c
View file @
1218ddc3
...
...
@@ -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 */
base_c/src/core_set.c
View file @
1218ddc3
...
...
@@ -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
...
...
base_c/src/thread.c
View file @
1218ddc3
...
...
@@ -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
...
...
base_c/src/time.c
View file @
1218ddc3
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment