// Create a task that contains a recursive function inside it.
// Create a mechanism by which you are able to transfer how much stack is remaining
// (number of bytes) while that task is operating, over a specific UART channel.
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <Arduino.h>
// Recursive factorial function
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n - 1);
}
// Task function
void taskFunction(void *pvParameters) {
int n = 5; // Calculate factorial of 5 as an example
while(1){
int result = factorial(n);
Serial.print("Factorial of ");
Serial.print(n);
Serial.print(" is ");
Serial.println(result);
// Get remaining stack size
uint32_t stackSize = uxTaskGetStackHighWaterMark(NULL);
Serial.print("Remaining stack size: ");
Serial.println(stackSize);
}
vTaskDelete(NULL); // Delete the task once done
}
void setup() {
Serial.begin(9600);
xTaskCreate(taskFunction, "Task", 1000, NULL, 1, NULL); // Create the task
}
void loop() {
// Nothing to do here, everything is handled in the task
}