/* --------------------------------------------------------------
Application: 01 - Rev1
Release Type: Baseline Multitask Skeleton Starter Code
Class: Real Time Systems - Su 2025
Modifications: Added timing verification, test cases, and healthcare theme
---------------------------------------------------------------*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED_PIN GPIO_NUM_2
// [MODIFIED BY AI] - Added timestamp logging
void blink_task(void *pvParameters) {
bool led_on = false;
while (1) {
gpio_set_level(LED_PIN, led_on ? 1 : 0);
// [ADDED BY AI] - Timing verification and healthcare theme
printf("HEARTBEAT %s at %lums\n", // [ADDED BY AI] - Medical context
led_on ? "ON" : "OFF",
(unsigned long)(xTaskGetTickCount() * portTICK_PERIOD_MS));
led_on = !led_on;
vTaskDelay(pdMS_TO_TICKS(250));
}
vTaskDelete(NULL);
}
// [MODIFIED BY AI] - Added healthcare context and timing info
void print_task(void *pvParameters) {
while (1) {
// [ADDED BY AI] - Healthcare-themed message with timestamp
printf("PATIENT STATUS: HR=72bpm, BP=120/80 (System Time: %lums)\n",
xTaskGetTickCount()*portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(10000));
// [ADDED BY AI] - Test case (uncomment to simulate priority inversion)
// vTaskDelay(pdMS_TO_TICKS(5000)); // Extra delay test
}
vTaskDelete(NULL);
}
void app_main() {
gpio_reset_pin(LED_PIN);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
// [MODIFIED BY AI] - Added priority test case (try priority=2 for print task)
xTaskCreate(blink_task, "Heartbeat Monitor", 2048, NULL, 1, NULL); // [ADDED BY AI] - Renamed for theme
xTaskCreate(print_task, "Vitals Logger", 2048, NULL, 1, NULL); // [ADDED BY AI] - Renamed for theme
}
/* [ADDED BY AI] ************************************************
Superloop Test Implementation (for comparison)
Uncomment to demonstrate timing failures:
#include "esp_timer.h"
void app_main() {
bool led_on = false;
uint64_t last_blink = 0;
uint64_t last_print = 0;
gpio_reset_pin(LED_PIN);
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
while(1) {
uint64_t now = esp_timer_get_time() / 1000;
if(now - last_blink >= 250) {
gpio_set_level(LED_PIN, led_on ? 1 : 0);
led_on = !led_on;
last_blink = now;
}
if(now - last_print >= 10000) {
printf("Patient vitals...\n");
// for(int i=0; i<1e6; i++) {} // [ADDED BY AI] - Uncomment to break timing
last_print = now;
}
}
}
*****************************************************************/