forked from espressif/esp-idf
FreeRTOS: Convert portMUX_DEBUG to a configuration item
This commit is contained in:
@@ -155,4 +155,31 @@ config FREERTOS_BREAK_ON_SCHEDULER_START_JTAG
|
|||||||
If JTAG/OCD is connected, stop execution when the scheduler is started and the first
|
If JTAG/OCD is connected, stop execution when the scheduler is started and the first
|
||||||
task is executed.
|
task is executed.
|
||||||
|
|
||||||
|
menuconfig FREERTOS_DEBUG_INTERNALS
|
||||||
|
bool "Debug FreeRTOS internals"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Enable this option to show the menu with internal FreeRTOS debugging features.
|
||||||
|
This option does not change any code by itself, it just shows/hides some options.
|
||||||
|
|
||||||
|
if FREERTOS_DEBUG_INTERNALS
|
||||||
|
|
||||||
|
config FREERTOS_PORTMUX_DEBUG
|
||||||
|
bool "Debug portMUX portENTER_CRITICAL/portEXIT_CRITICAL"
|
||||||
|
depends on FREERTOS_DEBUG_INTERNALS
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
If enabled, debug information (including integrity checks) will be printed
|
||||||
|
to UART for the port-specific MUX implementation.
|
||||||
|
|
||||||
|
config FREERTOS_PORTMUX_DEBUG_RECURSIVE
|
||||||
|
bool "Debug portMUX Recursion"
|
||||||
|
depends on FREERTOS_PORTMUX_DEBUG
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
If enabled, additional debug information will be printed for recursive
|
||||||
|
portMUX usage.
|
||||||
|
|
||||||
|
endif # FREERTOS_DEBUG_INTERNALS
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@@ -120,13 +120,12 @@ typedef unsigned portBASE_TYPE UBaseType_t;
|
|||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#define portMUX_DEBUG
|
|
||||||
#define portFIRST_TASK_HOOK CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG
|
#define portFIRST_TASK_HOOK CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile uint32_t mux;
|
volatile uint32_t mux;
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
const char *lastLockedFn;
|
const char *lastLockedFn;
|
||||||
int lastLockedLine;
|
int lastLockedLine;
|
||||||
#endif
|
#endif
|
||||||
@@ -151,7 +150,7 @@ typedef struct {
|
|||||||
#define portMUX_VAL_SHIFT 0
|
#define portMUX_VAL_SHIFT 0
|
||||||
|
|
||||||
//Keep this in sync with the portMUX_TYPE struct definition please.
|
//Keep this in sync with the portMUX_TYPE struct definition please.
|
||||||
#ifdef portMUX_DEBUG
|
#ifndef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
#define portMUX_INITIALIZER_UNLOCKED { \
|
#define portMUX_INITIALIZER_UNLOCKED { \
|
||||||
.mux = portMUX_MAGIC_VAL|portMUX_FREE_VAL \
|
.mux = portMUX_MAGIC_VAL|portMUX_FREE_VAL \
|
||||||
}
|
}
|
||||||
@@ -170,13 +169,6 @@ typedef struct {
|
|||||||
|
|
||||||
#define portCRITICAL_NESTING_IN_TCB 1
|
#define portCRITICAL_NESTING_IN_TCB 1
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Enable this to enable mux debugging. With this on, the mux code will warn you for deadlocks
|
|
||||||
and double releases etc.
|
|
||||||
*/
|
|
||||||
#define portMUX_DEBUG
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Modifications to portENTER_CRITICAL:
|
Modifications to portENTER_CRITICAL:
|
||||||
|
|
||||||
@@ -198,7 +190,7 @@ This all assumes that interrupts are either entirely disabled or enabled. Interr
|
|||||||
will break this scheme.
|
will break this scheme.
|
||||||
*/
|
*/
|
||||||
void vPortCPUInitializeMutex(portMUX_TYPE *mux);
|
void vPortCPUInitializeMutex(portMUX_TYPE *mux);
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *function, int line);
|
void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *function, int line);
|
||||||
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *function, int line);
|
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *function, int line);
|
||||||
void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line );
|
void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line );
|
||||||
|
@@ -276,7 +276,7 @@ uint32_t uxPortCompareSet(volatile uint32_t *mux, uint32_t compare, uint32_t set
|
|||||||
* For kernel use: Initialize a per-CPU mux. Mux will be initialized unlocked.
|
* For kernel use: Initialize a per-CPU mux. Mux will be initialized unlocked.
|
||||||
*/
|
*/
|
||||||
void vPortCPUInitializeMutex(portMUX_TYPE *mux) {
|
void vPortCPUInitializeMutex(portMUX_TYPE *mux) {
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
ets_printf("Initializing mux %p\n", mux);
|
ets_printf("Initializing mux %p\n", mux);
|
||||||
mux->lastLockedFn="(never locked)";
|
mux->lastLockedFn="(never locked)";
|
||||||
mux->lastLockedLine=-1;
|
mux->lastLockedLine=-1;
|
||||||
@@ -288,7 +288,7 @@ void vPortCPUInitializeMutex(portMUX_TYPE *mux) {
|
|||||||
/*
|
/*
|
||||||
* For kernel use: Acquire a per-CPU mux. Spinlocks, so don't hold on to these muxes for too long.
|
* For kernel use: Acquire a per-CPU mux. Spinlocks, so don't hold on to these muxes for too long.
|
||||||
*/
|
*/
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *fnName, int line) {
|
void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *fnName, int line) {
|
||||||
#else
|
#else
|
||||||
void vPortCPUAcquireMutex(portMUX_TYPE *mux) {
|
void vPortCPUAcquireMutex(portMUX_TYPE *mux) {
|
||||||
@@ -296,7 +296,7 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux) {
|
|||||||
uint32_t res;
|
uint32_t res;
|
||||||
uint32_t recCnt;
|
uint32_t recCnt;
|
||||||
unsigned int irqStatus;
|
unsigned int irqStatus;
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
uint32_t cnt=(1<<16);
|
uint32_t cnt=(1<<16);
|
||||||
if ( (mux->mux & portMUX_MAGIC_MASK) != portMUX_MAGIC_VAL ) {
|
if ( (mux->mux & portMUX_MAGIC_MASK) != portMUX_MAGIC_VAL ) {
|
||||||
ets_printf("ERROR: vPortCPUAcquireMutex: mux %p is uninitialized (0x%X)! Called from %s line %d.\n", mux, mux->mux, fnName, line);
|
ets_printf("ERROR: vPortCPUAcquireMutex: mux %p is uninitialized (0x%X)! Called from %s line %d.\n", mux, mux->mux, fnName, line);
|
||||||
@@ -313,21 +313,21 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux) {
|
|||||||
//Mux was already locked by us. Just bump the recurse count by one.
|
//Mux was already locked by us. Just bump the recurse count by one.
|
||||||
recCnt=(res&portMUX_CNT_MASK)>>portMUX_CNT_SHIFT;
|
recCnt=(res&portMUX_CNT_MASK)>>portMUX_CNT_SHIFT;
|
||||||
recCnt++;
|
recCnt++;
|
||||||
#ifdef portMUX_DEBUG_RECURSIVE
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG_RECURSIVE
|
||||||
ets_printf("Recursive lock: recCnt=%d last non-recursive lock %s line %d, curr %s line %d\n", recCnt, mux->lastLockedFn, mux->lastLockedLine, fnName, line);
|
ets_printf("Recursive lock: recCnt=%d last non-recursive lock %s line %d, curr %s line %d\n", recCnt, mux->lastLockedFn, mux->lastLockedLine, fnName, line);
|
||||||
#endif
|
#endif
|
||||||
mux->mux=portMUX_MAGIC_VAL|(recCnt<<portMUX_CNT_SHIFT)|(xPortGetCoreID()<<portMUX_VAL_SHIFT);
|
mux->mux=portMUX_MAGIC_VAL|(recCnt<<portMUX_CNT_SHIFT)|(xPortGetCoreID()<<portMUX_VAL_SHIFT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cnt--;
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
#ifdef portMUX_DEBUG
|
cnt--;
|
||||||
if (cnt==0) {
|
if (cnt==0) {
|
||||||
ets_printf("Timeout on mux! last non-recursive lock %s line %d, curr %s line %d\n", mux->lastLockedFn, mux->lastLockedLine, fnName, line);
|
ets_printf("Timeout on mux! last non-recursive lock %s line %d, curr %s line %d\n", mux->lastLockedFn, mux->lastLockedLine, fnName, line);
|
||||||
ets_printf("Mux value %X\n", mux->mux);
|
ets_printf("Mux value %X\n", mux->mux);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} while (res!=portMUX_FREE_VAL);
|
} while (res!=portMUX_FREE_VAL);
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
if (res==portMUX_FREE_VAL) { //initial lock
|
if (res==portMUX_FREE_VAL) { //initial lock
|
||||||
mux->lastLockedFn=fnName;
|
mux->lastLockedFn=fnName;
|
||||||
mux->lastLockedLine=line;
|
mux->lastLockedLine=line;
|
||||||
@@ -340,7 +340,7 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux) {
|
|||||||
* For kernel use: Release a per-CPU mux. Returns true if everything is OK, false if mux
|
* For kernel use: Release a per-CPU mux. Returns true if everything is OK, false if mux
|
||||||
* was already unlocked or is locked by a different core.
|
* was already unlocked or is locked by a different core.
|
||||||
*/
|
*/
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *fnName, int line) {
|
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *fnName, int line) {
|
||||||
#else
|
#else
|
||||||
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) {
|
portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) {
|
||||||
@@ -351,7 +351,7 @@ portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) {
|
|||||||
portBASE_TYPE ret=pdTRUE;
|
portBASE_TYPE ret=pdTRUE;
|
||||||
// ets_printf("Unlock %p\n", mux);
|
// ets_printf("Unlock %p\n", mux);
|
||||||
irqStatus=portENTER_CRITICAL_NESTED();
|
irqStatus=portENTER_CRITICAL_NESTED();
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
const char *lastLockedFn=mux->lastLockedFn;
|
const char *lastLockedFn=mux->lastLockedFn;
|
||||||
int lastLockedLine=mux->lastLockedLine;
|
int lastLockedLine=mux->lastLockedLine;
|
||||||
mux->lastLockedFn=fnName;
|
mux->lastLockedFn=fnName;
|
||||||
@@ -362,13 +362,13 @@ portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) {
|
|||||||
res=uxPortCompareSet(&mux->mux, (xPortGetCoreID()<<portMUX_VAL_SHIFT)|portMUX_MAGIC_VAL, portMUX_FREE_VAL);
|
res=uxPortCompareSet(&mux->mux, (xPortGetCoreID()<<portMUX_VAL_SHIFT)|portMUX_MAGIC_VAL, portMUX_FREE_VAL);
|
||||||
|
|
||||||
if ( res == portMUX_FREE_VAL ) {
|
if ( res == portMUX_FREE_VAL ) {
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
ets_printf("ERROR: vPortCPUReleaseMutex: mux %p was already unlocked!\n", mux);
|
ets_printf("ERROR: vPortCPUReleaseMutex: mux %p was already unlocked!\n", mux);
|
||||||
ets_printf("Last non-recursive unlock %s line %d, curr unlock %s line %d\n", lastLockedFn, lastLockedLine, fnName, line);
|
ets_printf("Last non-recursive unlock %s line %d, curr unlock %s line %d\n", lastLockedFn, lastLockedLine, fnName, line);
|
||||||
#endif
|
#endif
|
||||||
ret=pdFALSE;
|
ret=pdFALSE;
|
||||||
} else if ( ((res&portMUX_VAL_MASK)>>portMUX_VAL_SHIFT) != xPortGetCoreID() ) {
|
} else if ( ((res&portMUX_VAL_MASK)>>portMUX_VAL_SHIFT) != xPortGetCoreID() ) {
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
ets_printf("ERROR: vPortCPUReleaseMutex: mux %p wasn't locked by this core (%d) but by core %d (ret=%x, mux=%x).\n", mux, xPortGetCoreID(), ((res&portMUX_VAL_MASK)>>portMUX_VAL_SHIFT), res, mux->mux);
|
ets_printf("ERROR: vPortCPUReleaseMutex: mux %p wasn't locked by this core (%d) but by core %d (ret=%x, mux=%x).\n", mux, xPortGetCoreID(), ((res&portMUX_VAL_MASK)>>portMUX_VAL_SHIFT), res, mux->mux);
|
||||||
ets_printf("Last non-recursive lock %s line %d\n", lastLockedFn, lastLockedLine);
|
ets_printf("Last non-recursive lock %s line %d\n", lastLockedFn, lastLockedLine);
|
||||||
ets_printf("Called by %s line %d\n", fnName, line);
|
ets_printf("Called by %s line %d\n", fnName, line);
|
||||||
@@ -378,7 +378,7 @@ portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) {
|
|||||||
//We locked this, but the reccount isn't zero. Decrease refcount and continue.
|
//We locked this, but the reccount isn't zero. Decrease refcount and continue.
|
||||||
recCnt=(res&portMUX_CNT_MASK)>>portMUX_CNT_SHIFT;
|
recCnt=(res&portMUX_CNT_MASK)>>portMUX_CNT_SHIFT;
|
||||||
recCnt--;
|
recCnt--;
|
||||||
#ifdef portMUX_DEBUG_RECURSIVE
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG_RECURSIVE
|
||||||
ets_printf("Recursive unlock: recCnt=%d last locked %s line %d, curr %s line %d\n", recCnt, lastLockedFn, lastLockedLine, fnName, line);
|
ets_printf("Recursive unlock: recCnt=%d last locked %s line %d, curr %s line %d\n", recCnt, lastLockedFn, lastLockedLine, fnName, line);
|
||||||
#endif
|
#endif
|
||||||
mux->mux=portMUX_MAGIC_VAL|(recCnt<<portMUX_CNT_SHIFT)|(xPortGetCoreID()<<portMUX_VAL_SHIFT);
|
mux->mux=portMUX_MAGIC_VAL|(recCnt<<portMUX_CNT_SHIFT)|(xPortGetCoreID()<<portMUX_VAL_SHIFT);
|
||||||
|
@@ -3754,14 +3754,14 @@ scheduler will re-enable the interrupts instead. */
|
|||||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||||
|
|
||||||
|
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line )
|
void vTaskEnterCritical( portMUX_TYPE *mux, const char *function, int line )
|
||||||
#else
|
#else
|
||||||
void vTaskEnterCritical( portMUX_TYPE *mux )
|
void vTaskEnterCritical( portMUX_TYPE *mux )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
vPortCPUAcquireMutex( mux, function, line );
|
vPortCPUAcquireMutex( mux, function, line );
|
||||||
#else
|
#else
|
||||||
vPortCPUAcquireMutex( mux );
|
vPortCPUAcquireMutex( mux );
|
||||||
@@ -3794,13 +3794,13 @@ scheduler will re-enable the interrupts instead. */
|
|||||||
|
|
||||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||||
|
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
void vTaskExitCritical( portMUX_TYPE *mux, const char *function, int line )
|
void vTaskExitCritical( portMUX_TYPE *mux, const char *function, int line )
|
||||||
#else
|
#else
|
||||||
void vTaskExitCritical( portMUX_TYPE *mux )
|
void vTaskExitCritical( portMUX_TYPE *mux )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef portMUX_DEBUG
|
#ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
|
||||||
vPortCPUReleaseMutex( mux, function, line );
|
vPortCPUReleaseMutex( mux, function, line );
|
||||||
#else
|
#else
|
||||||
vPortCPUReleaseMutex( mux );
|
vPortCPUReleaseMutex( mux );
|
||||||
|
Reference in New Issue
Block a user