FreeRTOS With Arduino 09 : Read Task Info : VTaskList()

Introduction: FreeRTOS With Arduino 09 : Read Task Info : VTaskList()

In earlier tutorials, we have seen how to create, delete, suspend and resume the tasks. In this tutorial, we will see how to read the Task info(state, Stack size, priority).

Step 1: API Details :

Here we will discuss some of the most frequently used API's related to tasks.

xTaskCreate(): This interface is used to create a new Task, if the task is successfully created then it returns pdPass(1) or else errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY(-1). Check this link for more details.

vTaskDelay(): This function is used to delay/block the task for specified delay time(ticks). INCLUDE_vTaskDelay needs to be set to 1 in FreeRtosConfig.h file for using this function. Check this link for more details.

vTaskSuspend(): This function is used to Suspend a task, the suspended remains in the same state util it is resumed.For this, we need to pass the handle of the tasks that needs to be suspended. Passing NULL will suspend own task. Check this link for more details.

vTaskResume(): This function is used to resume a suspended task. If the Resumed task has higher priority than the running task then it will preempt the running task or else stays in ready stateFor this, we need to pass the handle of the task to be resumed. Check this link for more details.

vTaskList(): This function is used to read the task details(name, state, priority, num). We need to pass a string pointer(buffer) to which it copies the above task details. The buffer size should be minimum 40 bytes per task. Check this link for more details.

Step 2: Example1 :

In this example, we will be creating 3-tasks which run for some time and enter the blocked state allowing other tasks to run. We will include INT0 falling edge interrupt to read and display the current task list with all the task info. Every time interrupt is generated it will take the snapshot of tasks(name, state, priority, num) and sends on Serial port.

This code has been developed and tested on ExploreEmbedded boards.
We strongly believe that the library works on any of development boards for respective controllers.
Check this link http://www.exploreembedded.com/wiki for awesome tutorials on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT.
ExploreEmbedded invests substantial time and effort developing open source HW and SW tools, to support consider
buying the ExploreEmbedded boards.
The ExploreEmbedded libraries and examples are licensed under the terms of the new-bsd license(two-clause bsd license).
See also: http://www.opensource.org/licenses/bsd-license.php

EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF USAGE OF LIBRARIES, DIRECTLY OR
INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE REVISION HISTORY CONTAINS THE INFORMATION
RELATED TO UPDATES.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose
and without fee is hereby granted, provided that this copyright notices appear in all copies
and that both those copyright notices and this permission notice appear in supporting documentation.
**************************************************************************************************/
#include

/*
* Task info(state, Priority, Stack available) is read immediately the switch is pressed and sent on Serial Port
* Serial data is printed in ISR for demonstarting the control flow. This should not be done as it takes long time to send data on Serial port.
* Taking to much ISR time will starve the other tasks or User application. *
*/
static void ExternalInterrupt()
{
vTaskList(ptrTaskList);
Serial.println(F("**********************************"));
Serial.println(F("Task State Prio Stack Num"));
Serial.println(F("**********************************"));
Serial.print(ptrTaskList);
Serial.println(F("**********************************"));
}

Step 3: Output1 :

All the tasks will be running for some time and enter the blocked state allowing other tasks to run. Task3 suspends and resumes the Task1 alternatively. Whenever INT0 interrupt is generated, ISR will take the snapshot of all the task and sends it on the serial port.