/*
 * Copyright (c) 2023, Erich Styger
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "platform.h"
#include "application.h"
#include "McuLED.h"
#include "McuGPIO.h"
#include "McuWait.h"
#include "McuRTOS.h"
#include "leds.h"

#if McuLib_CONFIG_SDK_USE_FREERTOS
static void blinky(void *pv) {
  for(;;) {
     LEDS_On(LEDS_GREEN);
     vTaskDelay(pdMS_TO_TICKS(50));
     LEDS_Off(LEDS_GREEN);
     LEDS_On(LEDS_RED);
     vTaskDelay(pdMS_TO_TICKS(50));
     LEDS_Off(LEDS_RED);
     vTaskDelay(pdMS_TO_TICKS(500));
  }
}
#endif

void APP_Run(void) {
  PL_Init();
#if McuLib_CONFIG_SDK_USE_FREERTOS
  if (xTaskCreate(blinky, "blinky", 300/sizeof(StackType_t), NULL, tskIDLE_PRIORITY+1, NULL)!=pdPASS) {
    for(;;) {}
  }
  vTaskStartScheduler();
#else
  for(;;) {
    LEDS_On(LEDS_GREEN);
    McuWait_Waitms(50);
    LEDS_Off(LEDS_GREEN);
    LEDS_On(LEDS_RED);
    McuWait_Waitms(50);
    LEDS_Off(LEDS_RED);
    McuWait_Waitms(500);
  }
#endif
}
