/* --------------------------------------------------------------
Application: 01 - Rev1
Release Type: Baseline Multitask Skeleton Starter Code
Class: Real Time Systems - Sp 2026
AI Use: Commented inline
---------------------------------------------------------------*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED_PIN GPIO_NUM_2 // Using GPIO2 for the LED
// Task to blink an LED at 2 Hz (500 ms period: 250 ms ON, 250 ms OFF)
void blink_task(void *pvParameters) {
bool led_on = false;
while (1) {
// TODO: Set LED pin high or low based on led_on flag; right now it's always on... boring; hint in the commented out print statement
gpio_set_level(LED_PIN, led_on);
if (led_on == true)
printf("LED ON\n");
else
printf("LED OFF\n");
led_on = !led_on; // toggle state for next time
vTaskDelay(pdMS_TO_TICKS(250)); // Delay for using MS to Ticks Function vs alternative which is MS / ticks per ms
}
vTaskDelete(NULL); // We'll never get here; tasks run forever
}
// Task to print a message every 10000 ms (10 seconds)
void print_task(void *pvParameters) {
int counter = 0;
while (1) {
// TODO: Print a periodic message based on thematic area. Could be a counter or timestamp.
printf("Telemtry OK. %d s\n", counter);
vTaskDelay(pdMS_TO_TICKS(10000)); // Delay for 10000 ms
counter += 10;
}
vTaskDelete(NULL); // We'll never get here; tasks run forever
}
void app_main() {
// Initialize LED GPIO
gpio_reset_pin(LED_PIN);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
// Instantiate/ Create tasks:
// . pointer to task function,
// . descriptive name, [has a max length; located in the FREERTOS_CONFIG.H]
// . stack depth,
// . parameters [optional] = NULL
// . priority [0 = low],
// . pointer referencing this created task [optional] = NULL
// Learn more here https://www.freertos.org/Documentation/02-Kernel/04-API-references/01-Task-creation/01-xTaskCreate
xTaskCreate(blink_task, "Blink Task", 2048, NULL, 1, NULL);
xTaskCreate(print_task, "Print Task", 2048, NULL, 1, NULL);
}