Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the task application function of FreeRTOS real-time operating system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what is the task application function of the FreeRTOS real-time operating system". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the task application function of the FreeRTOS real-time operating system" can help you solve your doubts.

1. Get task system status 1.1 function description UBaseType_t uxTaskGetSystemState (TaskStatus_t * constpxTaskStatusArray, const UBaseType_tuxArraySize, unsigned long * constpulTotalRunTime)

This function populates the TaskStatus_t structure with relevant information, and the information for each task in the system can be populated into the TaskStatus_t structure array, the size of which is specified by uxArraySize. The structure TaskStatus_t is defined as follows:

The typedef struct xTASK_STATUS {/ * task handle * / TaskHandle_t xHandle; / * pointer to the task name * / const signed char * pcTaskName; / * task ID is a unique number * / UBaseType_t xTaskNumber; / * when filling the structure, the task's current state (run, ready, pending, etc.) * / eTaskState eCurrentState; / * the priority of the task running (or inheriting) when filling the structure. * / UBaseType_t uxCurrentPriority; / * when the priority of a task is changed due to inheritance, this variable holds the original priority of the task. Valid only if configUSE_MUTEXES is defined as 1. The total elapsed time assigned to the task by * / UBaseType_t uxBasePriority; / *. Valid only when the macro configGENERATE_RUN_TIME_STATS is 1. * / unsigned long ulRunTimeCounter; / * the minimum number of stacks left since the task is created. The closer this value is to 0, the more likely the stack overflow is. * / unsigned short usStackHighWaterMark;} TaskStatus_t

Note that this function is for trial only, and calling this function suspends all tasks until the end of the function, so the task may be suspended for a long time. In the file FreeRTOSConfig.h, the macro configUSE _ TRACE_FACILITY must be set to 1 for this function to be valid.

1.2 Parameter description

PxTaskStatusArray: an array of structures pointing to the TaskStatus_t type. This array must contain at least 1 element. The number of tasks controlled by RTOS can be obtained using the API function uxTaskGetNumberOfTasks ().

UxArraySize: the size of the array that the parameter pxTaskStatusArray points to, that is, the number of indexes of the array.

PulTotalRunTime: if the macro configGENERATE _ RUN_TIME_STATS is set to 1 in the file FreeRTOSConfig.h, this function writes the total elapsed time to * pulTotalRunTime. PulTotalRunTime can be set to NULL, which means total elapsed time is ignored.

1.3 return value

The number of TaskStatus_t structures populated. This value should be equal to the value returned by calling the API function uxTaskGetNumberOfTasks (), but returns 0 if the value passed to the uxArraySize parameter is too small.

1.4 usage examples / * this example demonstrates how to use the uxTaskGetSystemState () function to obtain run-time information and convert it into a character format that is easier for programmers to recognize, and these converted characters are saved to pcWriteBuffer. * / void vTaskGetRunTimeStats (signed char * pcWriteBuffer) {TaskStatus_t*pxTaskStatusArray; volatileUBaseType_t uxArraySize, x; unsignedlong ulTotalRunTime, ulStatsAsPercentage; / * defensive code to ensure that the string has a reasonable end * / * pcWriteBuffer = 0x00; / * get the total number of tasks * / uxArraySize = uxTaskGetNumberOfTasks () / * allocate memory for the TaskStatus_t structure of each task, or statically allocate a sufficiently large array * / pxTaskStatusArray = pvPortMalloc (uxArraySize * sizeof (TaskStatus_t)); if (pxTaskStatusArray! = NULL) {/ * get the status information of each task * / uxArraySize = uxTaskGetSystemState (pxTaskStatusArray, uxArraySize,&ulTotalRunTime); / * percentage calculation * / ulTotalRunTime / = 100UL / * avoid zero division errors * / if (ulTotalRunTime > 0) {/ * convert each part of the task status information obtained into a string format easily recognized by the programmer * / for (x = 0; x

< uxArraySize; x++ ) { /* 计算任务运行时间与总运行时间的百分比。*/ ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter /ulTotalRunTime; if( ulStatsAsPercentage >

0UL) {sprintf (pcWriteBuffer, "% s\ t\ t%lu\ t\ t% Lu%\ r\ n", pxTaskStatusArray [x] .pcTaskName, pxTaskStatusArray [x] .ulRunTimeCounter, ulStatsAsPercentage) } else {/ * the task elapsed less than 1% of the total elapsed time (pcWriteBuffer, "% s\ t\ t%lu\ t\ t

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report