You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

82 lines
2.0 KiB

#include <stddef.h>
#include <stdio.h>
//
#include "appdep.hpp"
#include "apppublic/boardid.hpp"
//
#include "app/main_controler/main_controler.hpp"
#include "app/valvecontroler/valvecontroler.hpp"
#define TAG "main"
extern void umain();
extern "C" {
void StartDefaultTask(void const *argument) { umain(); }
}
/*******************************************************************************
* MAIN *
*******************************************************************************/
using namespace iflytop;
/* IWDG init function */
void MX_IWDG_Init(void) {
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
hiwdg.Init.Reload = 501;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
Error_Handler();
}
}
static ZGPIO debuglight0;
static ZGPIO debuglight1;
static bool errorFlag;
static inline void debugLightLoop() {
static bool light = false;
static uint32_t lastcall = 0;
if (errorFlag) {
if (zos_haspassedms(lastcall) > 30) {
light = !light;
debuglight0.write(light);
debuglight1.write(light);
lastcall = zos_get_tick();
}
} else {
if (zos_haspassedms(lastcall) > 300) {
light = !light;
debuglight0.write(light);
debuglight1.write(light);
lastcall = zos_get_tick();
}
}
}
int32_t getDeviceIdFromFlash() {
int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD;
if (*deviceId <= 0) {
return 0;
}
return *deviceId;
}
void umain() {
MX_IWDG_Init();
debuglight0.initAsOutput(DEBUG_LIGHT_IO0, kxs_gpio_nopull, false, false);
debuglight1.initAsOutput(DEBUG_LIGHT_IO1, kxs_gpio_nopull, false, false);
int32_t id = getDeviceIdFromFlash();
if (id == boardid::kbmainboard) {
MainControler::ins()->init();
} else if (id == boardid::kvalveboard) {
ValvaControler::ins()->init();
} else {
errorFlag = true;
}
while (true) {
osDelay(30);
debugLightLoop();
HAL_IWDG_Refresh(&hiwdg);
}
}