Merge pull request #11947 from gschorcht/cpu/esp32/freertos-critcial-sections
cpu/esp32: critcial section handling changed in FreeRTOS adaptation layer
This commit is contained in:
commit
dbd97b7588
@ -4,7 +4,6 @@ MODULE = cpu
|
|||||||
# Add a list of subdirectories, that should also be built:
|
# Add a list of subdirectories, that should also be built:
|
||||||
DIRS += $(RIOTCPU)/esp_common
|
DIRS += $(RIOTCPU)/esp_common
|
||||||
DIRS += periph
|
DIRS += periph
|
||||||
DIRS += freertos
|
|
||||||
DIRS += vendor
|
DIRS += vendor
|
||||||
|
|
||||||
ifneq (, $(filter esp_cxx, $(USEMODULE)))
|
ifneq (, $(filter esp_cxx, $(USEMODULE)))
|
||||||
@ -23,4 +22,8 @@ ifneq (, $(filter esp_wifi, $(USEMODULE)))
|
|||||||
DIRS += esp-wifi
|
DIRS += esp-wifi
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (, $(filter riot_freertos, $(USEMODULE)))
|
||||||
|
DIRS += freertos
|
||||||
|
endif
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.base
|
include $(RIOTBASE)/Makefile.base
|
||||||
|
|||||||
@ -79,6 +79,7 @@ USEMODULE += periph_hwrng
|
|||||||
USEMODULE += periph_flash
|
USEMODULE += periph_flash
|
||||||
USEMODULE += periph_rtc
|
USEMODULE += periph_rtc
|
||||||
USEMODULE += periph_uart
|
USEMODULE += periph_uart
|
||||||
|
USEMODULE += riot_freertos
|
||||||
USEMODULE += random
|
USEMODULE += random
|
||||||
USEMODULE += stdio_uart
|
USEMODULE += stdio_uart
|
||||||
USEMODULE += xtensa
|
USEMODULE += xtensa
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#ifndef DOXYGEN
|
#ifndef DOXYGEN
|
||||||
|
|
||||||
#define ENABLE_DEBUG 0
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -139,8 +139,14 @@ void vTaskEnterCritical( portMUX_TYPE *mux )
|
|||||||
/* disable interrupts */
|
/* disable interrupts */
|
||||||
uint32_t state = irq_disable();
|
uint32_t state = irq_disable();
|
||||||
|
|
||||||
/* aquire the mutex with interrupts disabled */
|
/* Locking the given mutex does not work here, as this function can also
|
||||||
mutex_lock(mux); /* TODO should be only a spin lock */
|
be called in the interrupt context. Therefore, the given mutex is not
|
||||||
|
used. Instead, the basic default FreeRTOS mechanism for critical
|
||||||
|
sections is used by simply disabling interrupts. Since context
|
||||||
|
switches for the ESP32 are also based on interrupts, there is no
|
||||||
|
possibility that another thread will enter the critical section
|
||||||
|
once the interrupts are disabled. */
|
||||||
|
/* mutex_lock(mux); */ /* TODO should be only a spin lock */
|
||||||
|
|
||||||
/* increment nesting counter and save old interrupt level */
|
/* increment nesting counter and save old interrupt level */
|
||||||
threads_arch_exts[my_pid].critical_nesting++;
|
threads_arch_exts[my_pid].critical_nesting++;
|
||||||
@ -157,8 +163,9 @@ void vTaskExitCritical( portMUX_TYPE *mux )
|
|||||||
DEBUG("%s pid=%d prio=%d mux=%p\n", __func__,
|
DEBUG("%s pid=%d prio=%d mux=%p\n", __func__,
|
||||||
my_pid, sched_threads[my_pid]->priority, mux);
|
my_pid, sched_threads[my_pid]->priority, mux);
|
||||||
|
|
||||||
/* release the mutex with interrupts disabled */
|
/* The given mutex is not used (see vTaskEnterCritical) and has not to
|
||||||
mutex_unlock(mux); /* TODO should be only a spin lock */
|
be unlocked here. */
|
||||||
|
/* mutex_unlock(mux); */ /* TODO should be only a spin lock */
|
||||||
|
|
||||||
/* decrement nesting counter and restore old interrupt level */
|
/* decrement nesting counter and restore old interrupt level */
|
||||||
if (threads_arch_exts[my_pid].critical_nesting) {
|
if (threads_arch_exts[my_pid].critical_nesting) {
|
||||||
|
|||||||
@ -30,8 +30,8 @@ extern "C" {
|
|||||||
#define portMUX_TYPE mutex_t
|
#define portMUX_TYPE mutex_t
|
||||||
#define portMUX_INITIALIZER_UNLOCKED MUTEX_INIT
|
#define portMUX_INITIALIZER_UNLOCKED MUTEX_INIT
|
||||||
|
|
||||||
#define portENTER_CRITICAL(pm) mutex_lock(pm)
|
#define portENTER_CRITICAL(mux) vTaskEnterCritical(mux)
|
||||||
#define portEXIT_CRITICAL(pm) mutex_unlock(pm)
|
#define portEXIT_CRITICAL(mux) vTaskExitCritical(mux)
|
||||||
#define portENTER_CRITICAL_NESTED irq_disable
|
#define portENTER_CRITICAL_NESTED irq_disable
|
||||||
#define portEXIT_CRITICAL_NESTED irq_restore
|
#define portEXIT_CRITICAL_NESTED irq_restore
|
||||||
|
|
||||||
@ -39,15 +39,18 @@ extern "C" {
|
|||||||
#define portEXIT_CRITICAL_ISR(mux) vTaskExitCritical(mux)
|
#define portEXIT_CRITICAL_ISR(mux) vTaskExitCritical(mux)
|
||||||
|
|
||||||
#define taskENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
|
#define taskENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
|
||||||
#define taskENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux)
|
#define taskENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux)
|
||||||
#define taskEXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
|
#define taskEXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
|
||||||
#define taskEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux)
|
#define taskEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux)
|
||||||
|
|
||||||
#define portYIELD_FROM_ISR thread_yield_higher
|
#define portYIELD_FROM_ISR thread_yield_higher
|
||||||
#define portNUM_PROCESSORS 2
|
#define portNUM_PROCESSORS 2
|
||||||
|
|
||||||
#define xPortGetCoreID() PRO_CPU_NUM
|
#define xPortGetCoreID() PRO_CPU_NUM
|
||||||
|
|
||||||
|
extern void vTaskEnterCritical(portMUX_TYPE *mux);
|
||||||
|
extern void vTaskExitCritical(portMUX_TYPE *mux);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user