Merge branch 'bugfix/core_id_arg' into 'master'

doc: Add clarifications Xtensa Core ID and "Core ID" used in FreeRTOS are different

Closes IDFGH-407

See merge request espressif/esp-idf!5661
This commit is contained in:
Angus Gratton 2019-08-12 15:16:51 +08:00
commit 212e7be28c
5 changed files with 28 additions and 15 deletions

View file

@ -136,11 +136,15 @@ typedef unsigned portBASE_TYPE UBaseType_t;
/* "mux" data structure (spinlock) */ /* "mux" data structure (spinlock) */
typedef struct { typedef struct {
/* owner field values: /* owner field values:
* 0 - Uninitialized (invalid) * 0 - Uninitialized (invalid)
* portMUX_FREE_VAL - Mux is free, can be locked by either CPU * portMUX_FREE_VAL - Mux is free, can be locked by either CPU
* CORE_ID_PRO / CORE_ID_APP - Mux is locked to the particular core * CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core
* *
* Any value other than portMUX_FREE_VAL, CORE_ID_PRO, CORE_ID_APP indicates corruption * Note that for performance reasons we use the full Xtensa CORE ID values
* (CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP) and not the 0,1 values which are used in most
* other FreeRTOS code.
*
* Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption
*/ */
uint32_t owner; uint32_t owner;
/* count field: /* count field:

View file

@ -185,7 +185,7 @@ typedef struct xTASK_STATUS
StackType_t *pxStackBase; /*!< Points to the lowest address of the task's stack area. */ StackType_t *pxStackBase; /*!< Points to the lowest address of the task's stack area. */
uint32_t usStackHighWaterMark; /*!< The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ uint32_t usStackHighWaterMark; /*!< The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
#if configTASKLIST_INCLUDE_COREID #if configTASKLIST_INCLUDE_COREID
BaseType_t xCoreID; /*!< Core this task is pinned to. This field is present if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is set. */ BaseType_t xCoreID; /*!< Core this task is pinned to (0, 1, or -1 for tskNO_AFFINITY). This field is present if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is set. */
#endif #endif
} TaskStatus_t; } TaskStatus_t;
@ -324,7 +324,7 @@ is used in assert() statements. */
* *
* @param xCoreID If the value is tskNO_AFFINITY, the created task is not * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
* pinned to any CPU, and the scheduler can run it on any core available. * pinned to any CPU, and the scheduler can run it on any core available.
* Other values indicate the index number of the CPU which the task should * Values 0 or 1 indicate the index number of the CPU which the task should
* be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
* cause the function to fail. * cause the function to fail.
* *
@ -476,7 +476,7 @@ is used in assert() statements. */
* *
* @param xCoreID If the value is tskNO_AFFINITY, the created task is not * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
* pinned to any CPU, and the scheduler can run it on any core available. * pinned to any CPU, and the scheduler can run it on any core available.
* Other values indicate the index number of the CPU which the task should * Values 0 or 1 indicate the index number of the CPU which the task should
* be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
* cause the function to fail. * cause the function to fail.
* *

View file

@ -325,8 +325,17 @@ STRUCT_END(XtSolFrame)
.endm .endm
#endif #endif
#define CORE_ID_PRO 0xCDCD /* Note: These are different to xCoreID used in ESP-IDF FreeRTOS, most places use
#define CORE_ID_APP 0xABAB 0 and 1 which are determined by checking bit 13 (see previous comment)
*/
#define CORE_ID_REGVAL_PRO 0xCDCD
#define CORE_ID_REGVAL_APP 0xABAB
/* Included for compatibility, recommend using CORE_ID_REGVAL_PRO instead */
#define CORE_ID_PRO CORE_ID_REGVAL_PRO
/* Included for compatibility, recommend using CORE_ID_REGVAL_APP instead */
#define CORE_ID_APP CORE_ID_REGVAL_APP
/* /*
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View file

@ -49,7 +49,7 @@
#include "soc/soc_memory_layout.h" #include "soc/soc_memory_layout.h"
/* XOR one core ID with this value to get the other core ID */ /* XOR one core ID with this value to get the other core ID */
#define CORE_ID_XOR_SWAP (CORE_ID_PRO ^ CORE_ID_APP) #define CORE_ID_REGVAL_XOR_SWAP (CORE_ID_REGVAL_PRO ^ CORE_ID_REGVAL_APP)

View file

@ -61,7 +61,7 @@ PORTMUX_AQUIRE_MUX_FN_NAME(portMUX_TYPE *mux, int timeout_cycles) {
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
uint32_t owner = mux->owner; uint32_t owner = mux->owner;
if (owner != portMUX_FREE_VAL && owner != CORE_ID_PRO && owner != CORE_ID_APP) { if (owner != portMUX_FREE_VAL && owner != CORE_ID_REGVAL_PRO && owner != CORE_ID_REGVAL_APP) {
ets_printf("ERROR: vPortCPUAcquireMutex: mux %p is uninitialized (0x%X)! Called from %s line %d.\n", mux, owner, fnName, line); ets_printf("ERROR: vPortCPUAcquireMutex: mux %p is uninitialized (0x%X)! Called from %s line %d.\n", mux, owner, fnName, line);
mux->owner=portMUX_FREE_VAL; mux->owner=portMUX_FREE_VAL;
} }
@ -70,13 +70,13 @@ PORTMUX_AQUIRE_MUX_FN_NAME(portMUX_TYPE *mux, int timeout_cycles) {
/* Spin until we own the core */ /* Spin until we own the core */
RSR(PRID, coreID); RSR(PRID, coreID);
/* Note: coreID is the full 32 bit core ID (CORE_ID_PRO/CORE_ID_APP), /* Note: coreID is the full 32 bit core ID (CORE_ID_REGVAL_PRO/CORE_ID_REGVAL_APP),
not the 0/1 value returned by xPortGetCoreID() not the 0/1 value returned by xPortGetCoreID()
*/ */
otherCoreID = CORE_ID_XOR_SWAP ^ coreID; otherCoreID = CORE_ID_REGVAL_XOR_SWAP ^ coreID;
do { do {
/* mux->owner should be one of portMUX_FREE_VAL, CORE_ID_PRO, /* mux->owner should be one of portMUX_FREE_VAL, CORE_ID_REGVAL_PRO,
CORE_ID_APP: CORE_ID_REGVAL_APP:
- If portMUX_FREE_VAL, we want to atomically set to 'coreID'. - If portMUX_FREE_VAL, we want to atomically set to 'coreID'.
- If "our" coreID, we can drop through immediately. - If "our" coreID, we can drop through immediately.
@ -138,7 +138,7 @@ static inline void PORTMUX_RELEASE_MUX_FN_NAME(portMUX_TYPE *mux) {
mux->lastLockedFn=fnName; mux->lastLockedFn=fnName;
mux->lastLockedLine=line; mux->lastLockedLine=line;
uint32_t owner = mux->owner; uint32_t owner = mux->owner;
if (owner != portMUX_FREE_VAL && owner != CORE_ID_PRO && owner != CORE_ID_APP) { if (owner != portMUX_FREE_VAL && owner != CORE_ID_REGVAL_PRO && owner != CORE_ID_REGVAL_APP) {
ets_printf("ERROR: vPortCPUReleaseMutex: mux %p is invalid (0x%x)!\n", mux, mux->owner); ets_printf("ERROR: vPortCPUReleaseMutex: mux %p is invalid (0x%x)!\n", mux, mux->owner);
} }
#endif #endif