From fb960f42b37ef1d9fa07ff0f868ed83bfcb74214 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Mon, 1 Aug 2022 17:32:40 +0800 Subject: [PATCH] freertos: Synchronize vTaskPlaceOnEventList...() functions to v10.4.3 This commit synchronizes the following vTaskPlaceOnEventList...() with upstream v10.4.3. The functions updated are: - vTaskPlaceOnEventList() - vTaskPlaceOnUnorderedEventList() - vTaskPlaceOnEventListRestricted() The traceTASK_DELAY_UNTIL() macro has also been updated. --- .../Sample/OS/SEGGER_SYSVIEW_FreeRTOS.h | 2 +- components/freertos/FreeRTOS-Kernel/tasks.c | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/components/app_trace/sys_view/Sample/OS/SEGGER_SYSVIEW_FreeRTOS.h b/components/app_trace/sys_view/Sample/OS/SEGGER_SYSVIEW_FreeRTOS.h index 3fd508bfde..9837e57531 100644 --- a/components/app_trace/sys_view/Sample/OS/SEGGER_SYSVIEW_FreeRTOS.h +++ b/components/app_trace/sys_view/Sample/OS/SEGGER_SYSVIEW_FreeRTOS.h @@ -263,7 +263,7 @@ define away all of the tracing macros. #define traceTASK_NOTIFY_TAKE( uxIndexToWait ) SEGGER_SYSVIEW_RecordU32x2(apiFastID_OFFSET + apiID_ULTASKNOTIFYTAKE, xClearCountOnExit, xTicksToWait) #define traceTASK_DELAY() SEGGER_SYSVIEW_RecordU32(apiFastID_OFFSET + apiID_VTASKDELAY, xTicksToDelay) -#define traceTASK_DELAY_UNTIL() SEGGER_SYSVIEW_RecordVoid(apiFastID_OFFSET + apiID_VTASKDELAYUNTIL) +#define traceTASK_DELAY_UNTIL( xTimeToWake ) SEGGER_SYSVIEW_RecordVoid(apiFastID_OFFSET + apiID_VTASKDELAYUNTIL) #define traceTASK_DELETE( pxTCB ) if (pxTCB != NULL) { \ SEGGER_SYSVIEW_RecordU32(apiFastID_OFFSET + apiID_VTASKDELETE, \ SEGGER_SYSVIEW_ShrinkId((U32)pxTCB)); \ diff --git a/components/freertos/FreeRTOS-Kernel/tasks.c b/components/freertos/FreeRTOS-Kernel/tasks.c index 5a24f92363..ed0e23c986 100644 --- a/components/freertos/FreeRTOS-Kernel/tasks.c +++ b/components/freertos/FreeRTOS-Kernel/tasks.c @@ -1589,7 +1589,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) if( xShouldDelay != pdFALSE ) { - traceTASK_DELAY_UNTIL(); + traceTASK_DELAY_UNTIL( xTimeToWake ); /* prvAddCurrentTaskToDelayedList() needs the block time, not * the time to wake, so subtract the current tick count. */ @@ -3731,6 +3731,8 @@ void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) { configASSERT( pxEventList ); + + /* Take the kernel lock as we are about to access the task lists. */ taskENTER_CRITICAL( &xKernelLock ); /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE @@ -3740,9 +3742,10 @@ void vTaskPlaceOnEventList( List_t * const pxEventList, * This is placed in the list in priority order so the highest priority task * is the first to be woken by the event. The queue that contains the event * list is locked, preventing simultaneous access from interrupts. */ - vListInsert( pxEventList, &( pxCurrentTCB[xPortGetCoreID()]->xEventListItem ) ); + vListInsert( pxEventList, &( pxCurrentTCB[ xPortGetCoreID() ]->xEventListItem ) ); prvAddCurrentTaskToDelayedList( xPortGetCoreID(), xTicksToWait); + taskEXIT_CRITICAL( &xKernelLock ); } /*-----------------------------------------------------------*/ @@ -3752,21 +3755,29 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xTicksToWait ) { configASSERT( pxEventList ); + + /* Take the kernel lock as we are about to access the task lists. */ taskENTER_CRITICAL( &xKernelLock ); + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by + * the event groups implementation. */ + /* Note. We currently don't always suspend the scheduler. Todo: IDF-3755 + * configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] != 0 ); */ + /* Store the item value in the event list item. It is safe to access the * event list item here as interrupts won't access the event list item of a * task that is not in the Blocked state. */ - listSET_LIST_ITEM_VALUE( &( pxCurrentTCB[xPortGetCoreID()]->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB[ xPortGetCoreID() ]->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); /* Place the event list item of the TCB at the end of the appropriate event * list. It is safe to access the event list here because it is part of an * event group implementation - and interrupts don't access event groups * directly (instead they access them indirectly by pending function calls to * the task level). */ - vListInsertEnd( pxEventList, &( pxCurrentTCB[xPortGetCoreID()]->xEventListItem ) ); + vListInsertEnd( pxEventList, &( pxCurrentTCB[ xPortGetCoreID() ]->xEventListItem ) ); prvAddCurrentTaskToDelayedList( xPortGetCoreID(), xTicksToWait ); + taskEXIT_CRITICAL( &xKernelLock ); } /*-----------------------------------------------------------*/ @@ -3775,9 +3786,11 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) { - taskENTER_CRITICAL( &xKernelLock ); configASSERT( pxEventList ); + /* Take the kernel lock as we are about to access the task lists. */ + taskENTER_CRITICAL( &xKernelLock ); + /* This function should not be called by application code hence the * 'Restricted' in its name. It is not part of the public API. It is * designed for use by kernel code, and has special calling requirements - @@ -3788,7 +3801,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, * In this case it is assume that this is the only task that is going to * be waiting on this event list, so the faster vListInsertEnd() function * can be used in place of vListInsert. */ - vListInsertEnd( pxEventList, &( pxCurrentTCB[xPortGetCoreID()]->xEventListItem ) ); + vListInsertEnd( pxEventList, &( pxCurrentTCB[ xPortGetCoreID() ]->xEventListItem ) ); /* If the task should block indefinitely then set the block time to a * value that will be recognised as an indefinite delay inside the @@ -3798,8 +3811,9 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, xTicksToWait = portMAX_DELAY; } - traceTASK_DELAY_UNTIL( ); + traceTASK_DELAY_UNTIL( ( xTickCount + xTicksToWait ) ); prvAddCurrentTaskToDelayedList( xPortGetCoreID(), xTicksToWait ); + taskEXIT_CRITICAL( &xKernelLock ); }