atomic: support for esp32s2beta
This commit is contained in:
parent
ea1dcf7fe4
commit
0bbeb502a8
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
#ifndef __CAS_H__
|
|
||||||
#define __CAS_H__
|
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/portmacro.h"
|
|
||||||
|
|
||||||
#define __cas_temp_sync_compare_and_swap_test(ptr, expected, desired) ({\
|
|
||||||
bool ret = false;\
|
|
||||||
unsigned state = portENTER_CRITICAL_NESTED(); \
|
|
||||||
if (*ptr == expected) { \
|
|
||||||
*ptr = desired; \
|
|
||||||
ret = true;\
|
|
||||||
}\
|
|
||||||
portEXIT_CRITICAL_NESTED(state); \
|
|
||||||
ret; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define __sync_bool_compare_and_swap(ptr, expected, desired) __cas_temp_sync_compare_and_swap_test(ptr, expected, desired)
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -3,6 +3,7 @@ if(NOT BOOTLOADER_BUILD)
|
||||||
if(IDF_TARGET STREQUAL "esp32")
|
if(IDF_TARGET STREQUAL "esp32")
|
||||||
list(APPEND COMPONENT_SRCS "trax.c")
|
list(APPEND COMPONENT_SRCS "trax.c")
|
||||||
endif()
|
endif()
|
||||||
|
list(APPEND COMPONENT_SRCS "stdatomic.c")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(COMPONENT_ADD_INCLUDEDIRS "include" "${IDF_TARGET}/include")
|
set(COMPONENT_ADD_INCLUDEDIRS "include" "${IDF_TARGET}/include")
|
||||||
|
|
47
components/xtensa/stdatomic.c
Normal file
47
components/xtensa/stdatomic.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//replacement for gcc built-in functions
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/portmacro.h"
|
||||||
|
#include "xtensa/config/core-isa.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define CMP_EXCHANGE(n, type) bool __atomic_compare_exchange_ ## n (type* mem, type* expect, type desired, int success, int failure) \
|
||||||
|
{ \
|
||||||
|
bool ret = false; \
|
||||||
|
unsigned state = portENTER_CRITICAL_NESTED(); \
|
||||||
|
if (*mem == *expect) { \
|
||||||
|
ret = true; \
|
||||||
|
*mem = desired; \
|
||||||
|
} else { \
|
||||||
|
*expect = *mem; \
|
||||||
|
} \
|
||||||
|
portEXIT_CRITICAL_NESTED(state); \
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
|
//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"
|
||||||
|
|
||||||
|
CMP_EXCHANGE(1, uint8_t)
|
||||||
|
CMP_EXCHANGE(2, uint16_t)
|
||||||
|
CMP_EXCHANGE(4, uint32_t)
|
||||||
|
CMP_EXCHANGE(8, uint64_t)
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue