/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile flag_t Flag = {0};

/* Private function prototypes -----------------------------------------------*/
/* Private user code ---------------------------------------------------------*/

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* Initialize onBoard Hardware */
  Board_Init();

  /* Initialize Scheduler */
  RTOS_Init();
  /* tdelay_ms() work now, I2C can work too */

  /* Initialize Event State Machine */
  ES_Init(stShowTime);

  /* Init devices at I2C bus */
  RTC_Init();
  //sensor_Init();

  /* Init Clock module */
  Clock_Init();

  /** Set tasks for Sheduler */
  RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);

  /* Infinite loop */
  while (1)
  {
    /* new second interrupt from RTC */
    if (Flag.RTC_IRQ != 0) {
      Flag.RTC_IRQ = 0;
      new_Second();
    } /* end of New second */

    es_event_t event = ES_GetEvent();
    if (event) {
      ES_Dispatch(event);
    }

    RTOS_DispatchTask();

    __WFI();
  }
} /* End of mine() */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
