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.
186 lines
4.7 KiB
186 lines
4.7 KiB
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
//
|
|
#include "base_service/base_service.h"
|
|
#include "base_service/fpga_if.h"
|
|
#include "base_service/light_ctrl_service.h"
|
|
#include "service/device_info.hpp"
|
|
#include "service/extern_if_service.h"
|
|
#include "service/network_service.h"
|
|
#include "service/reg_manager.h"
|
|
//
|
|
#define TAG "main"
|
|
using namespace std;
|
|
|
|
extern void umain();
|
|
extern "C" {
|
|
extern void MX_LWIP_Init(void);
|
|
void StartDefaultTask(void const* argument) { umain(); }
|
|
}
|
|
/*******************************************************************************
|
|
* MAIN *
|
|
*******************************************************************************/
|
|
|
|
/**
|
|
* @brief
|
|
* | extern_if_service |
|
|
* ========================================
|
|
* | reg_manager | device_info |
|
|
* ========================================
|
|
* | fpage_if |
|
|
* =========================
|
|
*
|
|
*/
|
|
|
|
zaf_gpio_t m_debug_led;
|
|
zaf_gpio_t m_factory_reset_key;
|
|
|
|
zaf_gpio_t m_fan0_power;
|
|
zaf_gpio_t m_fan1_power;
|
|
|
|
zaf_gpio_t m_fan0_state;
|
|
zaf_gpio_t m_fan1_state;
|
|
|
|
static uint32_t m_fan0_cnt;
|
|
static uint32_t m_fan1_cnt;
|
|
|
|
extern "C" {
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
|
if (GPIO_Pin == m_fan0_state.pin) {
|
|
m_fan0_cnt++;
|
|
}
|
|
|
|
else if (GPIO_Pin == m_fan1_state.pin) {
|
|
m_fan1_cnt++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void debug_light_ctrl() {
|
|
static uint32_t lastcall = 0;
|
|
static bool light_status = false;
|
|
if (zaf_has_passedms(lastcall) > 100) {
|
|
light_status = !light_status;
|
|
zaf_gpio_write(&m_debug_led, light_status);
|
|
lastcall = zaf_get_ticket();
|
|
}
|
|
}
|
|
|
|
void factory_reset_key_detect() {
|
|
static uint32_t reset_key_trigger_tp = 0;
|
|
static bool reset_key_triggered = false;
|
|
if (!reset_key_triggered) {
|
|
if (zaf_gpio_read(&m_factory_reset_key)) {
|
|
reset_key_trigger_tp = zaf_get_ticket();
|
|
reset_key_triggered = true;
|
|
}
|
|
}
|
|
|
|
if (reset_key_triggered) {
|
|
if (!zaf_gpio_read(&m_factory_reset_key)) {
|
|
reset_key_triggered = false;
|
|
} else {
|
|
if (zaf_has_passedms(reset_key_trigger_tp) > 3000) {
|
|
ZLOGI(TAG, "factory reset key triggered");
|
|
config_factory_reset();
|
|
|
|
// m_power_led
|
|
while (zaf_gpio_read(&m_factory_reset_key)) {
|
|
LightCtrlService_GreenLight_setState(false);
|
|
osDelay(100);
|
|
LightCtrlService_GreenLight_setState(true);
|
|
osDelay(100);
|
|
}
|
|
ZLOGI(TAG, "system reset");
|
|
NVIC_SystemReset();
|
|
}
|
|
}
|
|
//
|
|
}
|
|
}
|
|
|
|
void umain() {
|
|
/**
|
|
* @brief device_info init
|
|
*/
|
|
sn_t sn;
|
|
device_info_init();
|
|
device_info_get_sn(&sn);
|
|
ZLOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
|
|
ZLOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
|
|
|
|
LightCtrlService_init();
|
|
LightCtrlService_GreenLight_setState(true);
|
|
|
|
/**
|
|
* @brief
|
|
* 1. 初始化调试指示灯
|
|
* 2. 初始化电源指示灯
|
|
* 3. 初始化工厂复位按键
|
|
*/
|
|
zaf_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
|
|
|
|
if (FACTORY_RESET_KEY != PinNull) {
|
|
zaf_gpio_init_as_input(&m_factory_reset_key, FACTORY_RESET_KEY, kxs_gpio_nopull, kxs_gpio_no_irq, true);
|
|
}
|
|
|
|
// m_power_led
|
|
/**
|
|
* @brief 配置初始化
|
|
*/
|
|
config_init();
|
|
/**
|
|
* @brief 初始化网络服务
|
|
*/
|
|
network_service_init();
|
|
/**
|
|
* @brief fpga_interface init
|
|
*/
|
|
fpga_if_init();
|
|
/**
|
|
* @brief reg_manager init
|
|
*/
|
|
reg_manager_init();
|
|
/**
|
|
* @brief extern_if_service init
|
|
*
|
|
* 解析并处理外部指令
|
|
*/
|
|
osDelay(10);
|
|
|
|
config_t* config = config_get();
|
|
for (uint32_t i = 0; i < ZARRAY_SIZE(config->reg_config_storage); i++) {
|
|
if (config->reg_config_storage[i].add == 0) {
|
|
break;
|
|
}
|
|
ZLOGI(TAG, "init reg [0x%x] [0x%x]", config->reg_config_storage[i].add, config->reg_config_storage[i].val);
|
|
fpga_if_spi_write_data(config->reg_config_storage[i].add, config->reg_config_storage[i].val, NULL);
|
|
}
|
|
|
|
extern_if_service_init();
|
|
|
|
zaf_gpio_init_as_output(&m_fan0_power, PD0, kxs_gpio_pullup, false, true);
|
|
zaf_gpio_init_as_output(&m_fan1_power, PD1, kxs_gpio_pullup, false, true);
|
|
|
|
zaf_gpio_init_as_input(&m_fan0_state, PD5, kxs_gpio_pullup, kxs_gpio_rising_irq, false);
|
|
zaf_gpio_init_as_input(&m_fan1_state, PD6, kxs_gpio_pullup, kxs_gpio_rising_irq, false);
|
|
|
|
ZLOGI(TAG, "system init done");
|
|
int32_t count = 0;
|
|
|
|
|
|
|
|
while (true) {
|
|
osDelay(10);
|
|
count++;
|
|
debug_light_ctrl();
|
|
if (FACTORY_RESET_KEY != PinNull) {
|
|
factory_reset_key_detect();
|
|
}
|
|
|
|
if (count % 100 == 0) {
|
|
ZLOGI(TAG, "fan0:%d, fan1:%d", m_fan0_cnt, m_fan1_cnt);
|
|
}
|
|
}
|
|
}
|