1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

cpu/esp_common: move ESP32 specific locking variables to cpu/esp32

This commit is contained in:
Gunar Schorcht 2022-09-01 15:09:58 +02:00
parent 1ab0b77543
commit 270001a42e
2 changed files with 47 additions and 11 deletions

View File

@ -24,6 +24,8 @@
#include "div.h"
#include "esp/common_macros.h"
#include "irq_arch.h"
#include "mutex.h"
#include "rmutex.h"
#include "periph_cpu.h"
#include "periph/pm.h"
#include "syscalls.h"
@ -255,8 +257,53 @@ timer_hal_context_t sys_timer = {
.idx = TIMER_SYSTEM_INDEX,
};
#if defined(_RETARGETABLE_LOCKING)
/* all locking variables share the same mutex respectively the same rmutex */
static mutex_t s_shared_mutex = MUTEX_INIT;
static rmutex_t s_shared_rmutex = RMUTEX_INIT;
/* definition of locks required by the newlib if retargetable locking is used */
extern struct __lock __attribute__((alias("s_shared_rmutex"))) __lock___sinit_recursive_mutex;
extern struct __lock __attribute__((alias("s_shared_rmutex"))) __lock___sfp_recursive_mutex;
extern struct __lock __attribute__((alias("s_shared_rmutex"))) __lock___atexit_recursive_mutex;
extern struct __lock __attribute__((alias("s_shared_rmutex"))) __lock___malloc_recursive_mutex;
extern struct __lock __attribute__((alias("s_shared_rmutex"))) __lock___env_recursive_mutex;
extern struct __lock __attribute__((alias("s_shared_mutex"))) __lock___at_quick_exit_mutex;
extern struct __lock __attribute__((alias("s_shared_mutex"))) __lock___tz_mutex;
extern struct __lock __attribute__((alias("s_shared_mutex"))) __lock___dd_hash_mutex;
extern struct __lock __attribute__((alias("s_shared_mutex"))) __lock___arc4random_mutex;
#endif
void IRAM syscalls_init_arch(void)
{
#if defined(_RETARGETABLE_LOCKING)
/* initialization of static locking variables in ROM, different ROM
* versions of newlib use different locking variables */
#if defined(CPU_FAM_ESP32)
extern _lock_t __sfp_lock;
extern _lock_t __sinit_lock;
extern _lock_t __env_lock_object;
extern _lock_t __tz_lock_object;
__sfp_lock = (_lock_t)&s_shared_rmutex;
__sinit_lock = (_lock_t)&s_shared_rmutex;
__env_lock_object = (_lock_t)&s_shared_mutex;
__tz_lock_object = (_lock_t)&s_shared_rmutex;
#elif defined(CPU_FAM_ESP32S2)
extern _lock_t __sinit_recursive_mutex;
extern _lock_t __sfp_recursive_mutex;
__sinit_recursive_mutex = (_lock_t)&s_shared_rmutex;
__sfp_recursive_mutex = (_lock_t)&s_shared_rmutex;
#else
/* TODO: Other platforms don't provide access to these ROM variables.
* It could be necessary to call `esp_rom_newlib_init_common_mutexes`. For
* the moment it doesn't seems to be necessary to call this function. */
#endif
#endif /* _RETARGETABLE_LOCKING */
/* initialize and enable the system timer in us (TMG0 is enabled by default) */
timer_hal_init(&sys_timer, TIMER_SYSTEM_GROUP, TIMER_SYSTEM_INDEX);
timer_hal_set_divider(&sys_timer, rtc_clk_apb_freq_get() / MHZ);

View File

@ -257,17 +257,6 @@ void IRAM_ATTR _lock_release_recursive(_lock_t *lock)
static_assert(sizeof(struct __lock) >= sizeof(rmutex_t),
"struct __lock is too small to hold a recursive mutex of type rmutex_t");
/* definition of locks required by the newlib if retargetable locking is used */
struct __lock __lock___sinit_recursive_mutex;
struct __lock __lock___sfp_recursive_mutex;
struct __lock __lock___atexit_recursive_mutex;
struct __lock __lock___at_quick_exit_mutex;
struct __lock __lock___malloc_recursive_mutex;
struct __lock __lock___env_recursive_mutex;
struct __lock __lock___tz_mutex;
struct __lock __lock___dd_hash_mutex;
struct __lock __lock___arc4random_mutex;
/* map newlib's `__retarget_*` functions to the existing `_lock_*` functions */
void __retarget_lock_init(_LOCK_T *lock)