#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
/*
* Videos 4, 5, 6, 7 and 8
* Video 4: Task create and delete
* Video 5: Task Input Parameter
* Video 6: Task Priority
*/
// Video 5--------------
int testNum[] = {6,7,8};
// What about a structure type?
typedef struct{
int iMem1;
int iMem2;
}xStruct;
xStruct xStrTest = {6, 9};
// End of Video 5-----------
void myTask(void *pvParam){
//int* intPtr;
//intPtr = (int*)pvParam;
xStruct* structPtr;
structPtr = (xStruct*)pvParam;
Serial.print("I got the number: ");
Serial.println(structPtr->iMem1);
//Serial.println(intPtr[1]);
//Serial.println(*(intPtr + 2));
for(;;){
Serial.println("Hello world!");
vTaskDelay(1000/portTICK_PERIOD_MS);
}
// You can delete the Task directly within the function.
// vTaskDelete(NULL);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
vTaskSuspendAll(); // Video 6: it seems is a good practice
// Let's define our TaskHandle
TaskHandle_t myHandle = NULL;
xTaskCreate(myTask, "myTask", 1024, (void *)&xStrTest, 1, &myHandle);
xTaskResumeAll(); // Video 6: After the creation of tasks, we resume the suspended tasks
// Video 5: pvParameter -> receive any type bc is 'pointer to void'
// Video 4: The TaskHandle_t is very useful in cases where:
// * Delete task
// * Change priority of the task
// * Take the task name, etc
vTaskDelay(5000/portTICK_PERIOD_MS);
if(myHandle!=NULL){
vTaskPrioritySet(myHandle, 2); // Video 6: Redefine the priority
UBaseType_t myPriority = uxTaskPriorityGet(myHandle);
Serial.print("Your new priority is: ");
Serial.println(myPriority);
vTaskDelete(myHandle); //Use the handle to reference the subject task
}
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}