// You'll likely need this in vanilla FreeRTOS
//#include timers.h


// only use core 1 for this demo
#if CONFIG_FREERTOS_UNICORE
 static const BaseType_t app_cpu = 0;
#else
 static const BaseType_t app_cpu = 1;
#endif



// Globals
static TimerHandle_t one_shot_timer = NULL;
TaskHandle_t task_handler;

// Called when one of the timers expires
void myTimerCallback(TimerHandle_t xTimer)
{
 Serial.println("Timer called");
 Serial.println("Sending Task1 to suspend state");
 vTaskSuspend(task_handler);
 
}


void printMessage(void *params)
{
  while(1)
  {
    Serial.println("Hello there!");
    vTaskDelay(pdMS_TO_TICKS(500));
  }

}


void setup()
{

  // Configure Serial
  Serial.begin(9600);
  vTaskDelay(pdMS_TO_TICKS(1000));

  BaseType_t status;

  //task1 (print messages to serial monitor)

  status = xTaskCreatePinnedToCore(printMessage,
                                      "Print Message",
                                      1024,  // This is stack size in words, in bytes for a 32bit miccrocontroller each word is 4 bytes. so 1024*4 = 4096 bytes
                                      NULL,  // No parameters passed
                                      1,     // Priority
                                      &task_handler,
                                      app_cpu
                                    );

  if (status != pdTRUE)
  {
    Serial.println("Error Task1 creation failed");     
  }




  one_shot_timer = xTimerCreate(
                           "One-shot timer",          // Name of timer
                           5000 / portTICK_PERIOD_MS,  // Period of timer (in ticks)
                           pdFALSE,                   // Auto-reload
                           (void *)0,                 // Timer ID
                           myTimerCallback);          // Callback function


  if (one_shot_timer == NULL)
  {
    Serial.println("Error timer creation failed");     
  }

  xTimerStart(one_shot_timer, portMAX_DELAY);
  Serial.println("Timer Called");

  // Delete self task to show the timers will work with no user tasks
  vTaskDelete(NULL);
}


void loop()
{
}