This repository has been archived on 2025-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hd/User/app.c

137 lines
3.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file app.c
* @author xxx
* @date 2023-08-30 08:58:43
* @brief app初始化和app启动
* @copyright Copyright (c) 2023 by xxx, All Rights Reserved.
*/
#include "app.h"
#include "adcs.h"
#include "test_bsp.h"
#include "bootload.h"
__IO calib_param_t calib_param[CALIBPARA_NUM]; // 校准参数
device_typedef udevice; // 设备参数
real_time_data_t rt_data; // 实时参数
pid_t _pid; // pid参数
driver_icon_enable_u driver_icon_enable; // 驱动使能图标
uint32_t mode_default_autoload; // 默认自动加载
// 模拟量
__IO uint16_t adc_raw[ADC1_MAX]; // ADC原始值
// 数字量
__IO float32 pid_target = 0; // pid控制目标
__IO float32 pid_actual = 0; // pid控制实际
__IO float32 show_loop = 0; // 显示电流
__IO float32 show_target = 0; // 显示目标
__IO float32 show_actual = 0; // 显示实际
__IO float32 range_percentage; // 量程百分比
__IO const static uint32_t cupid_encrypt = 0xFFFFFFFF;
#ifndef BOOTLOAD // 非bootload模式
static void app_preload(void)
{
mode_default_autoload = LL_TIM_GetAutoReload(TIM7);
if (app_preload_flag != 0xa5)
{
app_preload_flag = 0xa5;
udevice.display_language = CHINESE;
app_preload_language_flag = udevice.display_language;
app_preload_cupid_encrypt = 0xFFFFFFFF;
}
else
{
udevice.display_language = app_preload_language_flag;
}
set_app_preload_bootload_flag(FALSE);
}
/**
* @brief BOOTLOAD传输数据
* @param {uint8_t} *data
* @param {uint16_t} len
* @return {*}
* @note
*/
static void bootload_transmit(const uint8_t data_src, const uint8_t *data, const uint16_t len)
{
extern uart_t *uarts[APP_UART_MAX];
uart_send_data(uarts[data_src], (uint8_t *)data, len);
}
/**
* @brief BOOTLOAD更新完成处理
* @return {*}
* @note BOOTLOAD更新完成恢复业务流程这个时候不要重启
*/
static void bootload_end(BOOL bootload_write_flag)
{
set_app_preload_bootload_flag(FALSE); // 更新完成恢复业务流程
if (bootload_write_flag == TRUE)
{
set_app_preload_bootload_jump_flag(APP_PRELOAD_BOOTLOAD_JUMP_WAIT); // 更新完成等待用户通知跳转到bootload
}
else
{
set_app_preload_bootload_jump_flag(APP_PRELOAD_BOOTLOAD_JUMP_NONE);
// 更新失败 通知用户
}
}
#endif
/**
* @brief app初始化
* @return {*}
* @note
*/
void app_init(void)
{
leds_on_all(); // 打开所有LED
#ifndef BOOTLOAD // 非bootload模式
app_preload(); // 预加载
{
system_clock_config_set_flag(TRUE);
system_clock_config_hight(); // 切换高频
fal_execution_init(); // fal初始化
params_init(); // 参数初始化
system_clock_config_low(); // 切换低频
app_hart_init(); // HART初始化
mode_init(); // 工作模式初始化
flow_init(); // 流程初始化
bootload_init(bootload_transmit, bootload_end); // 在用户代码中接受更新文件需要初始化bootload
}
// TIM6 is placed after app_init to wait for the completion of fal_execution initialization.
ENABLE_TIM(TIM6); // Enable TIM6
#if LCD_DESIGN == TRUE
ENABLE_TIM(TIM7); // Enable TIM7
#endif
#else // bootload模式
// 在BOOTLOAD模式下需要关闭所有外设且不需要接受用户代码所以不需要初始化
board_dinit();
#endif
leds_off_all(); // 关闭所有LED
}
/**
* @brief app反初始化
* @return {*}
* @note
*/
void app_dinit(void)
{
}
/**
* @brief 业务流程启动
* @return {*}
* @note
*/
void app_start(void)
{
flow_start();
}