2020-06-28 14:22:46 +02:00
|
|
|
#include "init.h"
|
2020-07-09 19:58:20 +02:00
|
|
|
#include "iwdg.h"
|
2020-06-29 00:33:14 +02:00
|
|
|
#include "terminal.hpp"
|
|
|
|
#include "uart.hpp"
|
2020-06-28 16:23:20 +02:00
|
|
|
|
2020-07-03 17:43:52 +02:00
|
|
|
using serial_t = uart::Vcp<>;
|
2020-07-03 18:45:04 +02:00
|
|
|
using terminal_t = Terminal<serial_t>;
|
2020-07-03 17:43:52 +02:00
|
|
|
|
2020-07-03 18:14:46 +02:00
|
|
|
static volatile bool g_error = false;
|
|
|
|
|
|
|
|
extern "C" void Error_Handler(void)
|
|
|
|
{
|
|
|
|
g_error = true;
|
|
|
|
}
|
|
|
|
|
2020-07-03 17:43:52 +02:00
|
|
|
static inline void initializeHardware()
|
2020-06-28 14:22:46 +02:00
|
|
|
{
|
2020-07-09 20:08:20 +02:00
|
|
|
const auto resetByWatchdog = (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) ? true : false;
|
|
|
|
|
2020-07-03 18:45:04 +02:00
|
|
|
terminal_t terminal;
|
2020-06-28 14:22:46 +02:00
|
|
|
|
2020-07-03 18:14:46 +02:00
|
|
|
do {
|
|
|
|
g_error = false;
|
|
|
|
init();
|
2020-07-03 18:45:04 +02:00
|
|
|
terminal.init();
|
|
|
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, g_error ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
2020-07-03 18:14:46 +02:00
|
|
|
} while(g_error);
|
2020-07-03 17:43:52 +02:00
|
|
|
|
2020-07-09 20:08:20 +02:00
|
|
|
if(resetByWatchdog) {
|
|
|
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_RESET);
|
|
|
|
}
|
2020-07-03 22:53:35 +02:00
|
|
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
|
|
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_RESET);
|
|
|
|
|
2020-06-28 14:26:34 +02:00
|
|
|
HAL_Delay(1000);
|
2020-07-03 22:23:06 +02:00
|
|
|
|
2020-06-28 14:26:34 +02:00
|
|
|
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
|
|
|
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
|
|
|
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
2020-07-03 22:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
initializeHardware();
|
2020-07-09 19:58:20 +02:00
|
|
|
MX_IWDG_Init();
|
2020-06-28 14:26:34 +02:00
|
|
|
|
2020-07-03 18:45:04 +02:00
|
|
|
terminal_t terminal;
|
2020-06-28 21:22:17 +02:00
|
|
|
|
2020-06-28 14:22:46 +02:00
|
|
|
while(true) {
|
2020-07-03 18:45:04 +02:00
|
|
|
terminal.callback();
|
2020-07-09 19:58:20 +02:00
|
|
|
HAL_IWDG_Refresh(&hiwdg);
|
2020-06-28 14:22:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|