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.
144 lines
3.8 KiB
144 lines
3.8 KiB
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
//
|
|
#include "base_service/base_service.h"
|
|
#include "base_service/fpga_if.h"
|
|
#include "service/device_info.hpp"
|
|
#include "service/extern_if_service.h"
|
|
#include "service/network_service.h"
|
|
#include "service/reg_manager.h"
|
|
#include "service/report_generator_service.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 |
|
|
* config_service ========================================
|
|
* | report_generator | device_info |
|
|
* =================== ==============
|
|
* | fpage_if |
|
|
* ========================================
|
|
*
|
|
*/
|
|
|
|
xs_gpio_t m_debug_led;
|
|
xs_gpio_t m_factory_reset_key;
|
|
xs_gpio_t m_power_led;
|
|
extern "C" {
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { report_generator_service_irq_trigger(GPIO_Pin); }
|
|
}
|
|
|
|
void debug_light_ctrl() {
|
|
static uint32_t lastcall = 0;
|
|
static bool light_status = false;
|
|
if (xs_has_passedms(lastcall) > 100) {
|
|
light_status = !light_status;
|
|
xs_gpio_write(&m_debug_led, light_status);
|
|
lastcall = xs_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 (xs_gpio_read(&m_factory_reset_key)) {
|
|
reset_key_trigger_tp = xs_get_ticket();
|
|
reset_key_triggered = true;
|
|
}
|
|
}
|
|
|
|
if (reset_key_triggered) {
|
|
if (!xs_gpio_read(&m_factory_reset_key)) {
|
|
reset_key_triggered = false;
|
|
} else {
|
|
if (xs_has_passedms(reset_key_trigger_tp) > 3000) {
|
|
ZLOGI(TAG, "factory reset key triggered");
|
|
config_factory_reset();
|
|
|
|
// m_power_led
|
|
while (xs_gpio_read(&m_factory_reset_key)) {
|
|
xs_gpio_write(&m_power_led, false);
|
|
osDelay(100);
|
|
xs_gpio_write(&m_power_led, 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);
|
|
XS_LOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
|
|
XS_LOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
|
|
|
|
/**
|
|
* @brief
|
|
* 1. 初始化调试指示灯
|
|
* 2. 初始化电源指示灯
|
|
* 3. 初始化工厂复位按键
|
|
*/
|
|
xs_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
|
|
xs_gpio_init_as_output(&m_power_led, POWER_LED_PIN, kxs_gpio_nopull, false, true);
|
|
xs_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 report_generator init
|
|
*/
|
|
report_generator_service_init(fpga_if_get_instance()->timecode_irq_pin, fpga_if_get_instance()->camera_sync_code_irq_pin);
|
|
|
|
/**
|
|
* @brief reg_manager init
|
|
*/
|
|
reg_manager_init();
|
|
/**
|
|
* @brief extern_if_service init
|
|
*
|
|
* 解析并处理外部指令
|
|
*/
|
|
osDelay(1000);
|
|
extern_if_service_init();
|
|
|
|
ZLOGI(TAG, "system init done");
|
|
|
|
while (true) {
|
|
osDelay(10);
|
|
debug_light_ctrl();
|
|
// factory_reset_key_detect();
|
|
}
|
|
}
|