mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
arch: move stdatomic
This commit is contained in:
parent
98d34e5f6d
commit
5f2fabb2b1
@ -16,6 +16,7 @@ set(srcs
|
|||||||
"newlib_init.c"
|
"newlib_init.c"
|
||||||
"syscalls.c"
|
"syscalls.c"
|
||||||
"termios.c"
|
"termios.c"
|
||||||
|
"stdatomic.c"
|
||||||
"time.c")
|
"time.c")
|
||||||
set(include_dirs platform_include)
|
set(include_dirs platform_include)
|
||||||
|
|
||||||
|
@ -4,3 +4,4 @@ entries:
|
|||||||
heap (noflash)
|
heap (noflash)
|
||||||
abort (noflash)
|
abort (noflash)
|
||||||
assert (noflash)
|
assert (noflash)
|
||||||
|
stdatomic (noflash)
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __XTENSA__
|
||||||
|
|
||||||
#include "xtensa/config/core-isa.h"
|
#include "xtensa/config/core-isa.h"
|
||||||
#include "xtensa/xtruntime.h"
|
#include "xtensa/xtruntime.h"
|
||||||
|
|
||||||
//reserved to measure atomic operation time
|
|
||||||
#define atomic_benchmark_intr_disable()
|
|
||||||
#define atomic_benchmark_intr_restore(STATE)
|
|
||||||
|
|
||||||
// This allows nested interrupts disabling and restoring via local registers or stack.
|
// This allows nested interrupts disabling and restoring via local registers or stack.
|
||||||
// They can be called from interrupts too.
|
// They can be called from interrupts too.
|
||||||
// WARNING: Only applies to current CPU.
|
// WARNING: Only applies to current CPU.
|
||||||
@ -37,14 +37,37 @@
|
|||||||
XTOS_RESTORE_JUST_INTLEVEL(state); \
|
XTOS_RESTORE_JUST_INTLEVEL(state); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ATOMIC_EXCHANGE(n, type) type __atomic_exchange_ ## n (type* mem, type val, int memorder) \
|
#ifndef XCHAL_HAVE_S32C1I
|
||||||
{ \
|
#error "XCHAL_HAVE_S32C1I not defined, include correct header!"
|
||||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
#endif
|
||||||
type ret = *mem; \
|
|
||||||
*mem = val; \
|
#define NO_ATOMICS_SUPPORT (XCHAL_HAVE_S32C1I == 0)
|
||||||
_ATOMIC_EXIT_CRITICAL(state); \
|
#else // RISCV
|
||||||
return ret; \
|
|
||||||
}
|
#include "freertos/portmacro.h"
|
||||||
|
|
||||||
|
// This allows nested interrupts disabling and restoring via local registers or stack.
|
||||||
|
// They can be called from interrupts too.
|
||||||
|
// WARNING: Only applies to current CPU.
|
||||||
|
#define _ATOMIC_ENTER_CRITICAL(void) ({ \
|
||||||
|
unsigned state = portENTER_CRITICAL_NESTED(); \
|
||||||
|
atomic_benchmark_intr_disable(); \
|
||||||
|
state; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#define _ATOMIC_EXIT_CRITICAL(state) do { \
|
||||||
|
atomic_benchmark_intr_restore(state); \
|
||||||
|
portEXIT_CRITICAL_NESTED(state); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define NO_ATOMICS_SUPPORT 1 // [todo] Get the equivalent XCHAL_HAVE_S32C1I check for RISCV
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//reserved to measure atomic operation time
|
||||||
|
#define atomic_benchmark_intr_disable()
|
||||||
|
#define atomic_benchmark_intr_restore(STATE)
|
||||||
|
|
||||||
#define CMP_EXCHANGE(n, type) bool __atomic_compare_exchange_ ## n (type* mem, type* expect, type desired, int success, int failure) \
|
#define CMP_EXCHANGE(n, type) bool __atomic_compare_exchange_ ## n (type* mem, type* expect, type desired, int success, int failure) \
|
||||||
{ \
|
{ \
|
||||||
@ -105,47 +128,9 @@
|
|||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SYNC_FETCH_OP(op, n, type) type __sync_fetch_and_ ## op ##_ ## n (type* ptr, type value, ...) \
|
|
||||||
{ \
|
|
||||||
return __atomic_fetch_ ## op ##_ ## n (ptr, value, __ATOMIC_SEQ_CST); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SYNC_BOOL_CMP_EXCHANGE(n, type) bool __sync_bool_compare_and_swap_ ## n (type *ptr, type oldval, type newval, ...) \
|
|
||||||
{ \
|
|
||||||
bool ret = false; \
|
|
||||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
|
||||||
if (*ptr == oldval) { \
|
|
||||||
*ptr = newval; \
|
|
||||||
ret = true; \
|
|
||||||
} \
|
|
||||||
_ATOMIC_EXIT_CRITICAL(state); \
|
|
||||||
return ret; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SYNC_VAL_CMP_EXCHANGE(n, type) type __sync_val_compare_and_swap_ ## n (type *ptr, type oldval, type newval, ...) \
|
|
||||||
{ \
|
|
||||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
|
||||||
type ret = *ptr; \
|
|
||||||
if (*ptr == oldval) { \
|
|
||||||
*ptr = newval; \
|
|
||||||
} \
|
|
||||||
_ATOMIC_EXIT_CRITICAL(state); \
|
|
||||||
return ret; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef XCHAL_HAVE_S32C1I
|
|
||||||
#error "XCHAL_HAVE_S32C1I not defined, include correct header!"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//this piece of code should only be compiled if the cpu doesn't support atomic compare and swap (s32c1i)
|
|
||||||
#if XCHAL_HAVE_S32C1I == 0
|
|
||||||
|
|
||||||
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
|
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
|
||||||
|
|
||||||
ATOMIC_EXCHANGE(1, uint8_t)
|
#if NO_ATOMICS_SUPPORT
|
||||||
ATOMIC_EXCHANGE(2, uint16_t)
|
|
||||||
ATOMIC_EXCHANGE(4, uint32_t)
|
|
||||||
ATOMIC_EXCHANGE(8, uint64_t)
|
|
||||||
|
|
||||||
CMP_EXCHANGE(1, uint8_t)
|
CMP_EXCHANGE(1, uint8_t)
|
||||||
CMP_EXCHANGE(2, uint16_t)
|
CMP_EXCHANGE(2, uint16_t)
|
@ -11,7 +11,6 @@ else()
|
|||||||
"expression_with_stack_riscv_asm.S"
|
"expression_with_stack_riscv_asm.S"
|
||||||
"instruction_decode.c"
|
"instruction_decode.c"
|
||||||
"interrupt.c"
|
"interrupt.c"
|
||||||
"stdatomic.c"
|
|
||||||
"vectors.S")
|
"vectors.S")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -3,4 +3,3 @@ archive: libriscv.a
|
|||||||
entries:
|
entries:
|
||||||
interrupt (noflash_text)
|
interrupt (noflash_text)
|
||||||
vectors (noflash_text)
|
vectors (noflash_text)
|
||||||
stdatomic (noflash_text)
|
|
||||||
|
@ -18,9 +18,6 @@ else()
|
|||||||
"${target}/trax_init.c"
|
"${target}/trax_init.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(IDF_TARGET STREQUAL "esp32s2")
|
|
||||||
list(APPEND srcs "stdatomic.c")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
|
@ -3,8 +3,6 @@ archive: libxtensa.a
|
|||||||
entries:
|
entries:
|
||||||
eri (noflash_text)
|
eri (noflash_text)
|
||||||
xtensa_intr_asm (noflash_text)
|
xtensa_intr_asm (noflash_text)
|
||||||
if IDF_TARGET_ESP32S2 = y:
|
|
||||||
stdatomic (noflash)
|
|
||||||
|
|
||||||
[mapping:xt_hal]
|
[mapping:xt_hal]
|
||||||
archive: libxt_hal.a
|
archive: libxt_hal.a
|
||||||
|
Loading…
Reference in New Issue
Block a user