23 changed files with 862 additions and 1517 deletions
-
23APP/board.h
-
38APP/irqhandler.c
-
30APP/irqhandler.h
-
31APP/light.h
-
30APP/main.c
-
47APP/main.h
-
26APP/ozone_pwm_control.h
-
1APP/port.c
-
167APP/pwm.c
-
19APP/pwm.h
-
327APP/service/light_control_service.c
-
0APP/service/light_control_service.h
-
162APP/service/ozone_control_service.c
-
0APP/service/ozone_control_service.h
-
218MDK_StartUp/startup_ES8P5066.s
-
1068project_ozone/Listings/project_o.map
-
46project_ozone/project_o.uvgui.zel
-
100project_ozone/project_o.uvopt
-
42project_ozone/project_o.uvproj
@ -1,19 +1,19 @@ |
|||
#include "irqhandler.h" |
|||
|
|||
void NMI_IRQHandler(void) {} |
|||
|
|||
void HardFault_IRQHandler(void) { |
|||
while (1) { |
|||
} |
|||
} |
|||
|
|||
void SVC_IRQHandler(void) {} |
|||
|
|||
void PendSV_IRQHandler(void) {} |
|||
|
|||
|
|||
// uint32_t g_sys_sick = 0; |
|||
// void SysTick_IRQHandler(void) { |
|||
// g_sys_sick++; |
|||
// } |
|||
|
|||
#include "irqhandler.h" |
|||
|
|||
void NMI_IRQHandler(void) {} |
|||
|
|||
void HardFault_IRQHandler(void) { |
|||
while (1) { |
|||
} |
|||
} |
|||
|
|||
void SVC_IRQHandler(void) {} |
|||
|
|||
void PendSV_IRQHandler(void) {} |
|||
|
|||
|
|||
// uint32_t g_sys_sick = 0; |
|||
// void SysTick_IRQHandler(void) { |
|||
// g_sys_sick++; |
|||
// } |
|||
|
@ -1,15 +1,15 @@ |
|||
#ifndef __IRQHANDLER_H__ |
|||
#define __IRQHANDLER_H__ |
|||
|
|||
#include "ES8P5066.h" |
|||
//#include "light.h" |
|||
//#include "gpio.h" |
|||
|
|||
/************中断函数声明***********/ |
|||
void NMI_IRQHandler(void); |
|||
void HardFault_IRQHandler(void); |
|||
void SVC_IRQHandler(void); |
|||
void PendSV_IRQHandler(void); |
|||
void SysTick_IRQHandler(void); |
|||
|
|||
#endif |
|||
#ifndef __IRQHANDLER_H__ |
|||
#define __IRQHANDLER_H__ |
|||
|
|||
#include "ES8P5066.h" |
|||
//#include "light.h" |
|||
//#include "gpio.h" |
|||
|
|||
/************中断函数声明***********/ |
|||
void NMI_IRQHandler(void); |
|||
void HardFault_IRQHandler(void); |
|||
void SVC_IRQHandler(void); |
|||
void PendSV_IRQHandler(void); |
|||
void SysTick_IRQHandler(void); |
|||
|
|||
#endif |
@ -1,31 +0,0 @@ |
|||
#ifndef _LIGHT_H_ |
|||
#define _LIGHT_H_ |
|||
|
|||
// #include "board.h" |
|||
// #include "lib_config.h" |
|||
// #include "port.h" |
|||
// #include "system_ES8P5066.h" |
|||
// #include "systick.h" |
|||
|
|||
// typedef enum { |
|||
// krgb_close = 0, /*关闭灯*/ |
|||
// krgb_color_green = 1, /*打开绿灯*/ |
|||
// krgb_color_blue = 2, /*打开蓝灯*/ |
|||
// krgb_color_red = 3, /*打开红灯*/ |
|||
|
|||
// } rgb_light_mode_t; |
|||
|
|||
// void light_module_set_rgb_mode(rgb_light_mode_t mode); |
|||
// void light_module_set_error_light_mode(bool open, uint8_t error_mode); |
|||
// void light_module_set_autoshutdown_indicator_light(bool light); |
|||
// void light_module_set_rgb_in_interval_working_mode(bool state); |
|||
// void light_module_close_all_light(void); |
|||
|
|||
// void light_module_schedule(void); |
|||
|
|||
// //外部实现 |
|||
// int hook_get_autoshutdown_timecount(); |
|||
// //臭氧发生器是否工作 |
|||
// bool hook_get_ozone_generator_working_flag(); |
|||
|
|||
#endif |
@ -1,47 +0,0 @@ |
|||
#ifndef __MAIN_H__ |
|||
#define __MAIN_H__ |
|||
#if 0 |
|||
#include "irqhandler.h" |
|||
#include "lib_config.h" |
|||
#include "light.h" |
|||
#include "ozone_pwm_control.h" |
|||
#include "port.h" |
|||
#include "pwm.h" |
|||
#include "system_ES8P5066.h" |
|||
#include "systick.h" |
|||
#include "uart0.h" |
|||
typedef enum { |
|||
kwork_level_close = 0, /*关闭PWM输出,关闭RGB*/ |
|||
kwork_level_low = 1, /*低档*/ |
|||
kwork_level_hight = 2, /*高档*/ |
|||
} work_level_t; |
|||
|
|||
typedef struct { |
|||
bool fan_error_status; /*风扇电压异常*/ |
|||
bool way_circuit_error_status; /*总电压异常*/ |
|||
} error_state_t; |
|||
|
|||
// void Uart0Init(void); |
|||
// void Uart0SendBuff(uint8_t *buff); |
|||
// void port_do_debug_light_state(void); |
|||
// void LedInit(void); |
|||
|
|||
void process_intervalkey_press_even(void); |
|||
void update_interval_period_duty(uint8_t interval_duty); |
|||
void restore_the_mode_before_intermittent_work(void); |
|||
void process_rgb_flicker(void); |
|||
void power_on_ozone_working_status(void); |
|||
void update_ozone_work_level(work_level_t level); |
|||
void process_levelkey_press_even(void); |
|||
void shutdown(void); |
|||
void starting_up(void); |
|||
void process_powerkey(void); |
|||
void updae_timing_light_state(void); |
|||
void update_timing_time(void); |
|||
void try_shutdown(void); |
|||
bool timing_function_is_enable(void); |
|||
void iwdt_init(void); |
|||
void feed_iwdt(void); |
|||
void process_error_even(void); |
|||
#endif |
|||
#endif |
@ -1,26 +0,0 @@ |
|||
#if 0 |
|||
#ifndef _OZONE_PWM_CONTROL_H_ |
|||
#define _OZONE_PWM_CONTROL_H_ |
|||
|
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
|
|||
#include "lib_config.h" |
|||
#include "light.h" |
|||
#include "port.h" |
|||
#include "system_ES8P5066.h" |
|||
|
|||
void ozone_pwm_control_module_set_pwm_output_1(uint32_t hardware_period, uint8_t hardware_duty); |
|||
void ozone_pwm_control_module_set_pwm_output_2(uint32_t hardware_period, uint8_t hardware_duty, uint32_t large_period, uint8_t large_duty); |
|||
|
|||
void ozone_pwm_control_module_stop_pwm(void); |
|||
void ozone_pwm_control_module_loop(void); |
|||
|
|||
void ozone_pwm_control_enable(void); |
|||
void ozone_pwm_control_disable(void); |
|||
bool ozone_pwm_control_is_enable(void); |
|||
|
|||
bool ozone_pwm_control_hardware_is_enable(void); |
|||
|
|||
#endif |
|||
#endif |
@ -1,167 +0,0 @@ |
|||
#if 1 |
|||
#include "pwm.h" |
|||
|
|||
#include "board.h" |
|||
#define CLCK 48.0 |
|||
#define PRE_CLK 1.0 |
|||
uint32_t target_frequencyhz; |
|||
uint32_t target_duty; |
|||
|
|||
static uint32_t s_mat2; |
|||
static uint32_t s_top; |
|||
|
|||
static double calculate_top(double target_frequency_hz) { |
|||
int clck = 0; |
|||
int top = 0; |
|||
clck = CLCK * 1000 * 1000 / PRE_CLK; |
|||
top = clck / target_frequency_hz; |
|||
return top; |
|||
} |
|||
|
|||
void t16_pa4_init(void) { |
|||
T16Nx_Disable(T16N0); |
|||
// PA4 T16N0_1 |
|||
T16Nx_BaseInitStruType x; |
|||
T16Nx_PWMInitStruType y; |
|||
/* 初始化T16Nx定时器*/ |
|||
x.T16Nx_ClkS = T16Nx_ClkS_PCLK; //时钟源48M |
|||
x.T16Nx_SYNC = Disable; //不同步 |
|||
x.T16Nx_EDGE = T16Nx_EDGE_Rise; //上升沿触发 |
|||
x.T16Nx_Mode = T16Nx_Mode_PWM; // 选用PWM模式 |
|||
x.T16Nx_PREMAT = PRE_CLK; /* 预分频比1:1 */ |
|||
T16Nx_BaseInit(T16N0, &x); |
|||
/* 配置T16N0通道1输出 */ |
|||
y.T16Nx_MOE0 = Disable; |
|||
y.T16Nx_MOE1 = Enable; |
|||
y.T16Nx_POL0 = POSITIVE; //在串口发送的时候,正极性代表发送的数据与接受的数据相同,负极性代表与发送的数据相反,在这么不知道有没有作用 |
|||
y.T16Nx_POL1 = POSITIVE; |
|||
y.T16Nx_PWMMODE = T16Nx_PWMMode_INDEP; //选择独立模式 |
|||
y.PWMDZE = Disable; // PWM互补模式死区使能 |
|||
y.REGBUFEN = Enable; //缓冲寄存器使能 (REGBUFEN目前不知道干什么用的) |
|||
T16Nx_PMWOutInit(T16N0, &y); |
|||
/* 配置T16N0 通道1输出 */ |
|||
/*MAT2 MAT3 通道的中断配置*/ |
|||
//匹配寄存器值匹配后的工作模式,计数到以后: 继续计数不产生中断 |
|||
T16Nx_MAT2ITConfig(T16N0, T16Nx_Go_No); |
|||
//匹配寄存器值匹配后的工作模式,清零并重新计数,产生中断 |
|||
T16Nx_MAT3ITConfig(T16N0, T16Nx_Clr_Int); |
|||
|
|||
/*MAT2 MAT3 匹配后的输出电平高低*/ |
|||
T16Nx_MAT2Out1Config(T16N0, |
|||
T16Nx_Out_Low); //匹配后输出端口的模式,输出高还是低 |
|||
T16Nx_MAT3Out1Config(T16N0, |
|||
T16Nx_Out_High); //匹配后输出端口的模式,输出高还是低 |
|||
//以上是设置模式,输出高低电平 |
|||
T16Nx_SetCNT1(T16N0, 0); //设定计数器的初始值 |
|||
T16Nx_SetMAT2(T16N0, 0); //设置匹配寄存器的数值 |
|||
T16Nx_SetMAT3(T16N0, 0); //设置匹配寄存器的数值 |
|||
//设置计数器峰值//根据这个得到定时的时钟48M/48000=1khZ(在独立模式下PWM的周期由TOP1决定为TOP+1,周期算出来是1ms) |
|||
T16Nx_SetTOP1(T16N0, 0); |
|||
//以上是设置占空比 |
|||
/* 配置输出管脚 */ |
|||
GPIO_InitSettingType initset; |
|||
|
|||
initset.Signal = GPIO_Pin_Signal_Digital; //数字 |
|||
initset.Dir = GPIO_Direction_Output; //输出模式 |
|||
initset.Func = GPIO_Reuse_Func2; //复用到T16N0_1功能 |
|||
initset.ODE = GPIO_ODE_Output_Disable; //开漏使能 |
|||
initset.DS = GPIO_DS_Output_Normal; //普通电流模式 |
|||
initset.PUE = GPIO_PUE_Input_Enable; //弱上拉使能 |
|||
initset.PDE = GPIO_PDE_Input_Disable; //弱下拉禁止 |
|||
/* 配置PA4为T16N0输出通道1 */ |
|||
GPIO_Init(GPIO_Pin_A4, &initset); |
|||
T16Nx_Enable(T16N0); |
|||
return; |
|||
} |
|||
|
|||
void set_pwm_t16_pa4_2(uint16_t mat2, uint16_t top) { |
|||
uint16_t Mat2 = mat2; |
|||
uint16_t Mat3 = top; |
|||
|
|||
s_mat2 = mat2; |
|||
s_top = top; |
|||
|
|||
// printf("set_pwm_t16_pa4 mat2:%d mat3:%d top:%d\n", mat2, Mat3, top); |
|||
T16Nx_SetCNT1(T16N0, 0); //设定计数器的初始值 |
|||
T16Nx_SetMAT2(T16N0, Mat2); //设置匹配寄存器的数值 |
|||
T16Nx_SetMAT3(T16N0, Mat3); //设置匹配寄存器的数值 |
|||
//设置计数器峰值//根据这个得到定时的时钟48M/48000=1khZ(在独立模式下PWM的周期由TOP1决定为TOP+1,周期算出来是1ms) |
|||
T16Nx_SetTOP1(T16N0, top); |
|||
//以上是设置占空比 |
|||
} |
|||
|
|||
uint32_t getCNT() { return T16Nx_GetCNT1(T16N0); } |
|||
uint32_t getTOP() { return T16Nx_GetTOP1(T16N0); } |
|||
|
|||
void set_pwm_mat2(uint16_t mat2) { set_pwm_t16_pa4_2(mat2, s_top); } |
|||
|
|||
void set_pwm_t16_pa4(uint32_t freqhz, double duty) { |
|||
// printf("set_pwm_t16_pa4 %d %f\n", freqhz, duty); |
|||
double top_double = calculate_top(freqhz); //根据需要的频率计算出TOP(自动重装载值) |
|||
uint16_t top = (uint16_t)top_double; |
|||
uint16_t Mat2 = (uint16_t)top_double * (duty / 100.0); |
|||
if (Mat2 >= top) Mat2 = top - 1; |
|||
set_pwm_t16_pa4_2(Mat2, top); |
|||
} |
|||
|
|||
//###################################################### |
|||
/** |
|||
* @brief 设置pwm的周期占空比 |
|||
* |
|||
* @param frequency |
|||
* @param duty |
|||
*/ |
|||
|
|||
/** |
|||
* |
|||
* 频率变化: |
|||
* |
|||
* |
|||
* |
|||
* 占空比变化: |
|||
* 20->0 |
|||
* 0->20 |
|||
* 0->10 |
|||
* |
|||
* 有效时间逐渐增加,周期最大,有效时间不变,周期变小,频率变大 |
|||
* |
|||
* |
|||
* |
|||
* 周期变大,有效时间不变,周期变到最大,有效时间逐渐减小 |
|||
* |
|||
* |
|||
* 1. 先变化到周期,如果周期时间大于占空比,则先变化到占空比 |
|||
* 2. 再变化频率 |
|||
* |
|||
*/ |
|||
|
|||
uint32_t s_target_frequencyhz; |
|||
uint32_t s_now_frequencyhz; |
|||
|
|||
uint32_t s_target_duty; |
|||
uint32_t s_now_duty; |
|||
|
|||
void set_pwm_modbul_freq_duty(uint32_t frequencyhz, uint32_t duty) { |
|||
// s_target_frequencyhz = frequencyhz; |
|||
|
|||
// if (s_target_frequencyhz <= MIN_PWM_FREQ) { |
|||
// s_target_frequencyhz = MIN_PWM_FREQ; |
|||
// } |
|||
// s_target_duty = duty; |
|||
if (frequencyhz < 50) frequencyhz = 50; |
|||
set_pwm_t16_pa4(frequencyhz, duty); |
|||
} |
|||
|
|||
void set_pwm_modbul_freq_duty2(uint32_t frequencyhz, double duty) { |
|||
// s_target_frequencyhz = frequencyhz; |
|||
|
|||
// if (s_target_frequencyhz <= MIN_PWM_FREQ) { |
|||
// s_target_frequencyhz = MIN_PWM_FREQ; |
|||
// } |
|||
// s_target_duty = duty; |
|||
if (frequencyhz < 50) frequencyhz = 50; |
|||
set_pwm_t16_pa4(frequencyhz, duty); |
|||
} |
|||
|
|||
void stop_pwm_output() { T16Nx_Disable(T16N0); } |
|||
#endif |
@ -1,19 +0,0 @@ |
|||
#ifndef _PWM_MODULE_H_ |
|||
#define _PWM_MODULE_H_ |
|||
|
|||
#include "lib_config.h" |
|||
#include "light.h" |
|||
#include "port.h" |
|||
#include "system_ES8P5066.h" |
|||
|
|||
void set_pwm_modbul_freq_duty(uint32_t frequencyhz, uint32_t duty); |
|||
void set_pwm_mat2(uint16_t mat2); |
|||
void set_pwm_modbul_freq_duty2(uint32_t frequencyhz, double duty); |
|||
|
|||
void stop_pwm_output(); |
|||
|
|||
void t16_pa4_init(void); |
|||
|
|||
|
|||
|
|||
#endif |
@ -1,164 +1,165 @@ |
|||
#include "light.h" |
|||
#if 0 |
|||
static bool s_interval_working_mode; |
|||
static rgb_light_mode_t s_rgb_now_state; |
|||
static rgb_light_mode_t s_rgb_light_mode_config; |
|||
static int s_errornum = 0; |
|||
static bool s_errorlight_display_state; |
|||
static bool s_autoshutdown_light_state; |
|||
/** |
|||
* @brief 设置灯的模式,高低中分别亮不同颜色的灯 |
|||
* 高档红色,中档蓝色,低档绿色 |
|||
*/ |
|||
static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) { |
|||
if (mode == krgb_color_red) { |
|||
port_led_r_set(true); |
|||
port_led_g_set(false); |
|||
port_led_b_set(false); |
|||
} else if (mode == krgb_color_blue) { |
|||
port_led_r_set(false); |
|||
port_led_g_set(false); |
|||
port_led_b_set(true); |
|||
} else if (mode == krgb_color_green) { |
|||
port_led_r_set(false); |
|||
port_led_b_set(false); |
|||
port_led_g_set(true); |
|||
} else if (mode == krgb_close) { |
|||
port_led_r_set(false); |
|||
port_led_g_set(false); |
|||
port_led_b_set(false); |
|||
} |
|||
s_rgb_now_state = mode; |
|||
} |
|||
|
|||
static void prv_set_timing_light_mode(int mode) { |
|||
if (mode == 1) { |
|||
port_led0_set(true); |
|||
port_led1_set(false); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} else if (mode == 2) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} else if (mode == 3) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(true); |
|||
port_led3_set(false); |
|||
} else if (mode == 4) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(true); |
|||
port_led3_set(true); |
|||
} else if (mode == 0) { |
|||
port_led0_set(false); |
|||
port_led1_set(false); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} |
|||
} |
|||
|
|||
void prv_light_module_rgb_light_control_schedule() { |
|||
if (s_rgb_light_mode_config == krgb_close) { |
|||
prv_light_module_set_rgb_mode(krgb_close); |
|||
return; |
|||
} |
|||
if (!s_interval_working_mode) { |
|||
prv_light_module_set_rgb_mode(s_rgb_light_mode_config); |
|||
return; |
|||
} |
|||
|
|||
/** |
|||
* @brief 是否处于间歇模式 |
|||
*/ |
|||
if (s_interval_working_mode) { |
|||
if (hook_get_ozone_generator_working_flag()) { |
|||
static uint32_t rgb_flicker_ticket = 0; |
|||
static uint8_t rgb_ticket_count = 0; |
|||
if (port_haspassedms(rgb_flicker_ticket) > 1000) { |
|||
rgb_flicker_ticket = get_sys_ticket(); |
|||
if (s_rgb_now_state == krgb_close) { |
|||
prv_light_module_set_rgb_mode(s_rgb_light_mode_config); |
|||
} else { |
|||
prv_light_module_set_rgb_mode(krgb_close); |
|||
} |
|||
} |
|||
} else { |
|||
prv_light_module_set_rgb_mode(krgb_color_green); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @brief 倒计时指示灯状态控制 |
|||
*/ |
|||
static void prv_time_light_control_schedule() { |
|||
if (s_autoshutdown_light_state) { |
|||
/** |
|||
* @brief 显示自动关机倒计时指示灯 |
|||
*/ |
|||
int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; |
|||
int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; |
|||
if (lightnum_remainder != 0) { |
|||
lightnum += 1; |
|||
} |
|||
|
|||
prv_set_timing_light_mode(lightnum); |
|||
} else if (s_errorlight_display_state) { |
|||
/** |
|||
* @brief 显示异常指示灯 |
|||
*/ |
|||
static uint32_t ticket = 0; |
|||
static bool state; |
|||
if (port_haspassedms(ticket) > 300) { |
|||
ticket = get_sys_ticket(); |
|||
state = !state; |
|||
if (state) { |
|||
prv_set_timing_light_mode(s_errornum); |
|||
} else { |
|||
prv_set_timing_light_mode(0); |
|||
} |
|||
} |
|||
} else { |
|||
prv_set_timing_light_mode(0); |
|||
} |
|||
} |
|||
|
|||
/*********************************************************************************************************************** |
|||
* ======================================================Extern======================================================= * |
|||
***********************************************************************************************************************/ |
|||
|
|||
void light_module_set_rgb_mode(rgb_light_mode_t mode) { |
|||
printf("light_module_set_rgb_mode %d\n", mode); |
|||
s_rgb_light_mode_config = mode; |
|||
prv_light_module_set_rgb_mode(mode); |
|||
} |
|||
|
|||
void light_module_set_rgb_in_interval_working_mode(bool state) { |
|||
printf("light_module_set_rgb_in_interval_working_mode %d\n", state); |
|||
s_interval_working_mode = state; |
|||
} |
|||
void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; } |
|||
void light_module_set_error_light_mode(bool open, uint8_t error_mode) { |
|||
printf("light_module_set_error_light_mode %d\n", error_mode); |
|||
s_errorlight_display_state = open; |
|||
s_errornum = error_mode; |
|||
} |
|||
void light_module_close_all_light(void) { |
|||
printf("light_module_close_all_light\n"); |
|||
light_module_set_rgb_mode(krgb_close); |
|||
light_module_set_autoshutdown_indicator_light(false); |
|||
light_module_set_rgb_in_interval_working_mode(false); |
|||
prv_set_timing_light_mode(0); |
|||
s_errornum = 0; |
|||
s_interval_working_mode = false; |
|||
s_autoshutdown_light_state = false; |
|||
s_errorlight_display_state = false; |
|||
} |
|||
void light_module_schedule(void) { |
|||
prv_light_module_rgb_light_control_schedule(); |
|||
prv_time_light_control_schedule(); |
|||
} |
|||
|
|||
#if 0 |
|||
#include "light.h" |
|||
static bool s_interval_working_mode; |
|||
static rgb_light_mode_t s_rgb_now_state; |
|||
static rgb_light_mode_t s_rgb_light_mode_config; |
|||
static int s_errornum = 0; |
|||
static bool s_errorlight_display_state; |
|||
static bool s_autoshutdown_light_state; |
|||
/** |
|||
* @brief 设置灯的模式,高低中分别亮不同颜色的灯 |
|||
* 高档红色,中档蓝色,低档绿色 |
|||
*/ |
|||
static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) { |
|||
if (mode == krgb_color_red) { |
|||
port_led_r_set(true); |
|||
port_led_g_set(false); |
|||
port_led_b_set(false); |
|||
} else if (mode == krgb_color_blue) { |
|||
port_led_r_set(false); |
|||
port_led_g_set(false); |
|||
port_led_b_set(true); |
|||
} else if (mode == krgb_color_green) { |
|||
port_led_r_set(false); |
|||
port_led_b_set(false); |
|||
port_led_g_set(true); |
|||
} else if (mode == krgb_close) { |
|||
port_led_r_set(false); |
|||
port_led_g_set(false); |
|||
port_led_b_set(false); |
|||
} |
|||
s_rgb_now_state = mode; |
|||
} |
|||
|
|||
static void prv_set_timing_light_mode(int mode) { |
|||
if (mode == 1) { |
|||
port_led0_set(true); |
|||
port_led1_set(false); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} else if (mode == 2) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} else if (mode == 3) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(true); |
|||
port_led3_set(false); |
|||
} else if (mode == 4) { |
|||
port_led0_set(true); |
|||
port_led1_set(true); |
|||
port_led2_set(true); |
|||
port_led3_set(true); |
|||
} else if (mode == 0) { |
|||
port_led0_set(false); |
|||
port_led1_set(false); |
|||
port_led2_set(false); |
|||
port_led3_set(false); |
|||
} |
|||
} |
|||
|
|||
void prv_light_module_rgb_light_control_schedule() { |
|||
if (s_rgb_light_mode_config == krgb_close) { |
|||
prv_light_module_set_rgb_mode(krgb_close); |
|||
return; |
|||
} |
|||
if (!s_interval_working_mode) { |
|||
prv_light_module_set_rgb_mode(s_rgb_light_mode_config); |
|||
return; |
|||
} |
|||
|
|||
/** |
|||
* @brief 是否处于间歇模式 |
|||
*/ |
|||
if (s_interval_working_mode) { |
|||
if (hook_get_ozone_generator_working_flag()) { |
|||
static uint32_t rgb_flicker_ticket = 0; |
|||
static uint8_t rgb_ticket_count = 0; |
|||
if (port_haspassedms(rgb_flicker_ticket) > 1000) { |
|||
rgb_flicker_ticket = get_sys_ticket(); |
|||
if (s_rgb_now_state == krgb_close) { |
|||
prv_light_module_set_rgb_mode(s_rgb_light_mode_config); |
|||
} else { |
|||
prv_light_module_set_rgb_mode(krgb_close); |
|||
} |
|||
} |
|||
} else { |
|||
prv_light_module_set_rgb_mode(krgb_color_green); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @brief 倒计时指示灯状态控制 |
|||
*/ |
|||
static void prv_time_light_control_schedule() { |
|||
if (s_autoshutdown_light_state) { |
|||
/** |
|||
* @brief 显示自动关机倒计时指示灯 |
|||
*/ |
|||
int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; |
|||
int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; |
|||
if (lightnum_remainder != 0) { |
|||
lightnum += 1; |
|||
} |
|||
|
|||
prv_set_timing_light_mode(lightnum); |
|||
} else if (s_errorlight_display_state) { |
|||
/** |
|||
* @brief 显示异常指示灯 |
|||
*/ |
|||
static uint32_t ticket = 0; |
|||
static bool state; |
|||
if (port_haspassedms(ticket) > 300) { |
|||
ticket = get_sys_ticket(); |
|||
state = !state; |
|||
if (state) { |
|||
prv_set_timing_light_mode(s_errornum); |
|||
} else { |
|||
prv_set_timing_light_mode(0); |
|||
} |
|||
} |
|||
} else { |
|||
prv_set_timing_light_mode(0); |
|||
} |
|||
} |
|||
|
|||
/*********************************************************************************************************************** |
|||
* ======================================================Extern======================================================= * |
|||
***********************************************************************************************************************/ |
|||
|
|||
void light_module_set_rgb_mode(rgb_light_mode_t mode) { |
|||
printf("light_module_set_rgb_mode %d\n", mode); |
|||
s_rgb_light_mode_config = mode; |
|||
prv_light_module_set_rgb_mode(mode); |
|||
} |
|||
|
|||
void light_module_set_rgb_in_interval_working_mode(bool state) { |
|||
printf("light_module_set_rgb_in_interval_working_mode %d\n", state); |
|||
s_interval_working_mode = state; |
|||
} |
|||
void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; } |
|||
void light_module_set_error_light_mode(bool open, uint8_t error_mode) { |
|||
printf("light_module_set_error_light_mode %d\n", error_mode); |
|||
s_errorlight_display_state = open; |
|||
s_errornum = error_mode; |
|||
} |
|||
void light_module_close_all_light(void) { |
|||
printf("light_module_close_all_light\n"); |
|||
light_module_set_rgb_mode(krgb_close); |
|||
light_module_set_autoshutdown_indicator_light(false); |
|||
light_module_set_rgb_in_interval_working_mode(false); |
|||
prv_set_timing_light_mode(0); |
|||
s_errornum = 0; |
|||
s_interval_working_mode = false; |
|||
s_autoshutdown_light_state = false; |
|||
s_errorlight_display_state = false; |
|||
} |
|||
void light_module_schedule(void) { |
|||
prv_light_module_rgb_light_control_schedule(); |
|||
prv_time_light_control_schedule(); |
|||
} |
|||
#endif |
@ -1,82 +1,82 @@ |
|||
#if 0 |
|||
#include "ozone_pwm_control.h" |
|||
#include "pwm.h" |
|||
static bool s_ozone_pwm_control_enable_falg = false; |
|||
static bool s_pwm_modble_hardware_control_flag; //硬件pwm使能标志位 |
|||
|
|||
static uint32_t s_hardware_frequency; // hz |
|||
static uint32_t s_hardware_duty; //单位ms,保存现在的PWM占空比 |
|||
static uint32_t s_large_period; //单位ms,保存现在的定时周期 |
|||
static uint32_t s_large_duty = 100; //单位ms,保存现在的定时占空比 |
|||
static uint32_t begin_ticket; |
|||
|
|||
static void prv_pwm_module_set_pwm_duty(uint32_t frequencyhz, uint32_t duty) { |
|||
set_pwm_modbul_freq_duty(frequencyhz, duty); |
|||
s_pwm_modble_hardware_control_flag = true; |
|||
} |
|||
static void prv_pwm_stop(void) { |
|||
set_pwm_modbul_freq_duty(s_hardware_frequency, 0); //关闭PWM输出 |
|||
s_pwm_modble_hardware_control_flag = false; |
|||
} |
|||
static bool prv_pwm_is_enable(void) { return s_pwm_modble_hardware_control_flag; } |
|||
static void prv_update_begin_ticket(void) { |
|||
begin_ticket = get_sys_ticket(); //更新大周期的开始时间(间歇时间的开始的时间) |
|||
} |
|||
|
|||
|
|||
bool ozone_pwm_control_is_enable(void) { return s_ozone_pwm_control_enable_falg; } |
|||
bool ozone_pwm_control_hardware_is_enable(void) { return s_pwm_modble_hardware_control_flag; } |
|||
|
|||
/** |
|||
* @brief 一直工作的时间定时的占空比为100, |
|||
* 间歇时间设置300000 |
|||
* @param freq |
|||
* @param duty |
|||
*/ |
|||
void ozone_pwm_control_module_set_pwm_output_1(uint32_t freqhz, uint8_t hardware_duty) { |
|||
ozone_pwm_control_module_set_pwm_output_2(freqhz, hardware_duty, 100 * 1000, 100); |
|||
} |
|||
/** |
|||
* @brief 定时和PWM |
|||
* |
|||
* @param hardware_period pwm频率 |
|||
* @param hardware_duty pwm占空比 |
|||
* @param large_period 定时周期 |
|||
* @param large_duty 定时占空比 |
|||
*/ |
|||
void ozone_pwm_control_module_set_pwm_output_2(uint32_t freqhz, uint8_t hardware_duty, uint32_t large_period, uint8_t large_duty) { |
|||
s_hardware_frequency = freqhz; |
|||
s_hardware_duty = hardware_duty; |
|||
s_large_period = large_period; |
|||
s_large_duty = large_duty; |
|||
prv_update_begin_ticket(); |
|||
s_ozone_pwm_control_enable_falg = true; |
|||
prv_pwm_module_set_pwm_duty(freqhz, hardware_duty); |
|||
} |
|||
|
|||
void ozone_pwm_control_module_stop_pwm(void) { s_ozone_pwm_control_enable_falg = false; } |
|||
|
|||
void ozone_pwm_control_module_loop(void) { |
|||
static uint32_t hardware_frequency; |
|||
static uint32_t hardware_duty; |
|||
if (ozone_pwm_control_is_enable() == false) { //没有使能直接退出 |
|||
if (prv_pwm_is_enable()) { |
|||
prv_pwm_stop(); |
|||
} |
|||
return; |
|||
} |
|||
if (port_haspassedms(begin_ticket) % s_large_period <= s_large_period * s_large_duty / 100) { |
|||
if (!prv_pwm_is_enable()) { |
|||
printf("set work\r\n"); |
|||
prv_pwm_module_set_pwm_duty(hardware_frequency, hardware_duty); |
|||
} |
|||
} else { |
|||
if (prv_pwm_is_enable()) { |
|||
printf("set rest\r\n"); |
|||
hardware_frequency = s_hardware_frequency; //将关闭之前的频率进行保存 |
|||
hardware_duty = s_hardware_duty; //将关闭之前的占空比进行保存 |
|||
prv_pwm_stop(); |
|||
} |
|||
} |
|||
} |
|||
#if 0 |
|||
#include "ozone_pwm_control.h" |
|||
#include "pwm.h" |
|||
static bool s_ozone_pwm_control_enable_falg = false; |
|||
static bool s_pwm_modble_hardware_control_flag; //硬件pwm使能标志位 |
|||
|
|||
static uint32_t s_hardware_frequency; // hz |
|||
static uint32_t s_hardware_duty; //单位ms,保存现在的PWM占空比 |
|||
static uint32_t s_large_period; //单位ms,保存现在的定时周期 |
|||
static uint32_t s_large_duty = 100; //单位ms,保存现在的定时占空比 |
|||
static uint32_t begin_ticket; |
|||
|
|||
static void prv_pwm_module_set_pwm_duty(uint32_t frequencyhz, uint32_t duty) { |
|||
set_pwm_modbul_freq_duty(frequencyhz, duty); |
|||
s_pwm_modble_hardware_control_flag = true; |
|||
} |
|||
static void prv_pwm_stop(void) { |
|||
set_pwm_modbul_freq_duty(s_hardware_frequency, 0); //关闭PWM输出 |
|||
s_pwm_modble_hardware_control_flag = false; |
|||
} |
|||
static bool prv_pwm_is_enable(void) { return s_pwm_modble_hardware_control_flag; } |
|||
static void prv_update_begin_ticket(void) { |
|||
begin_ticket = get_sys_ticket(); //更新大周期的开始时间(间歇时间的开始的时间) |
|||
} |
|||
|
|||
|
|||
bool ozone_pwm_control_is_enable(void) { return s_ozone_pwm_control_enable_falg; } |
|||
bool ozone_pwm_control_hardware_is_enable(void) { return s_pwm_modble_hardware_control_flag; } |
|||
|
|||
/** |
|||
* @brief 一直工作的时间定时的占空比为100, |
|||
* 间歇时间设置300000 |
|||
* @param freq |
|||
* @param duty |
|||
*/ |
|||
void ozone_pwm_control_module_set_pwm_output_1(uint32_t freqhz, uint8_t hardware_duty) { |
|||
ozone_pwm_control_module_set_pwm_output_2(freqhz, hardware_duty, 100 * 1000, 100); |
|||
} |
|||
/** |
|||
* @brief 定时和PWM |
|||
* |
|||
* @param hardware_period pwm频率 |
|||
* @param hardware_duty pwm占空比 |
|||
* @param large_period 定时周期 |
|||
* @param large_duty 定时占空比 |
|||
*/ |
|||
void ozone_pwm_control_module_set_pwm_output_2(uint32_t freqhz, uint8_t hardware_duty, uint32_t large_period, uint8_t large_duty) { |
|||
s_hardware_frequency = freqhz; |
|||
s_hardware_duty = hardware_duty; |
|||
s_large_period = large_period; |
|||
s_large_duty = large_duty; |
|||
prv_update_begin_ticket(); |
|||
s_ozone_pwm_control_enable_falg = true; |
|||
prv_pwm_module_set_pwm_duty(freqhz, hardware_duty); |
|||
} |
|||
|
|||
void ozone_pwm_control_module_stop_pwm(void) { s_ozone_pwm_control_enable_falg = false; } |
|||
|
|||
void ozone_pwm_control_module_loop(void) { |
|||
static uint32_t hardware_frequency; |
|||
static uint32_t hardware_duty; |
|||
if (ozone_pwm_control_is_enable() == false) { //没有使能直接退出 |
|||
if (prv_pwm_is_enable()) { |
|||
prv_pwm_stop(); |
|||
} |
|||
return; |
|||
} |
|||
if (port_haspassedms(begin_ticket) % s_large_period <= s_large_period * s_large_duty / 100) { |
|||
if (!prv_pwm_is_enable()) { |
|||
printf("set work\r\n"); |
|||
prv_pwm_module_set_pwm_duty(hardware_frequency, hardware_duty); |
|||
} |
|||
} else { |
|||
if (prv_pwm_is_enable()) { |
|||
printf("set rest\r\n"); |
|||
hardware_frequency = s_hardware_frequency; //将关闭之前的频率进行保存 |
|||
hardware_duty = s_hardware_duty; //将关闭之前的占空比进行保存 |
|||
prv_pwm_stop(); |
|||
} |
|||
} |
|||
} |
|||
#endif |
@ -1,218 +0,0 @@ |
|||
;******************************************************************************* |
|||
|
|||
; *author : Eastsoft MCU Software Team |
|||
; *version : V0.01 |
|||
; *data : 5/28/2021 |
|||
; |
|||
; *Copyright (C) 2021 Shanghai Eastsoft Microelectronics Co., Ltd. |
|||
; * |
|||
; * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
|||
; * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
|||
; * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
|||
; * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR |
|||
; * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
|||
;******************************************************************************* |
|||
|
|||
|
|||
; <h> Stack Configuration |
|||
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> |
|||
; </h> |
|||
|
|||
Stack_Size EQU 0x00000400 |
|||
|
|||
AREA STACK, NOINIT, READWRITE, ALIGN=3 |
|||
Stack_Mem SPACE Stack_Size |
|||
__initial_sp |
|||
|
|||
|
|||
; <h> Heap Configuration |
|||
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> |
|||
; </h> |
|||
|
|||
Heap_Size EQU 0x00000000 |
|||
|
|||
AREA HEAP, NOINIT, READWRITE, ALIGN=3 |
|||
__heap_base |
|||
Heap_Mem SPACE Heap_Size |
|||
__heap_limit |
|||
|
|||
PRESERVE8 |
|||
THUMB |
|||
|
|||
; Vector Table Mapped to Address 0 at Reset |
|||
|
|||
AREA RESET, DATA, READONLY |
|||
EXPORT __Vectors |
|||
|
|||
__Vectors DCD __initial_sp ;0, Top of Stack |
|||
DCD Reset_IRQHandler ;1, Reset Handler |
|||
DCD NMI_IRQHandler ;2, NMI Handler |
|||
DCD HardFault_IRQHandler ;3, HardFault Handler |
|||
DCD 0 ;4, Reserved |
|||
DCD 0 ;5, Reserved |
|||
DCD 0 ;6, Reserved |
|||
DCD 0 ;7, Reserved |
|||
DCD 0 ;8, Reserved |
|||
DCD 0 ;9, Reserved |
|||
DCD 0 ;10, Reserved |
|||
DCD SVC_IRQHandler ;11, SVCall Handler |
|||
DCD 0 ;12, Reserved |
|||
DCD 0 ;13, Reserved |
|||
DCD PendSV_IRQHandler ;14, PendSV Handler |
|||
DCD SysTick_IRQHandler ;15, SysTick Handler |
|||
|
|||
; External Interrupts |
|||
DCD PINT0_IRQHandler ;16, PINT0 IRQHandler |
|||
DCD PINT1_IRQHandler ;17, PINT1 IRQHandler |
|||
DCD PINT2_IRQHandler ;18, PINT2 IRQHandler |
|||
DCD PINT3_IRQHandler ;19, PINT3 IRQHandler |
|||
DCD PINT4_IRQHandler ;20, PINT4 IRQHandler |
|||
DCD PINT5_IRQHandler ;21, PINT5 IRQHandler |
|||
DCD PINT6_IRQHandler ;22, PINT6 IRQHandler |
|||
DCD PINT7_IRQHandler ;23, PINT7 IRQHandler |
|||
DCD T16N0_IRQHandler ;24, T16N0 IRQHandler |
|||
DCD T16N1_IRQHandler ;25, T16N1 IRQHandler |
|||
DCD T16N2_IRQHandler ;26, T16N2 IRQHandler |
|||
DCD T16N3_IRQHandler ;27, T16N3 IRQHandler |
|||
DCD T32N0_IRQHandler ;28, T32N0 IRQHandler |
|||
DCD 0 ;29, Reserved |
|||
DCD 0 ;30, Reserved |
|||
DCD WWDT_IRQHandler ;31, WWDT IRQHandler |
|||
DCD IWDT_IRQHandler ;32, IWDT IRQHandler |
|||
DCD 0 ;33, Reserved |
|||
DCD KINT_IRQHandler ;34, KINT IRQHandler |
|||
DCD ADC_IRQHandler ;35, ADC IRQHandler |
|||
DCD 0 ;36, Reserved |
|||
DCD LVD_IRQHandler ;37, LVD IRQHandler |
|||
DCD 0 ;38, Reserved |
|||
DCD UART0_IRQHandler ;39, UART0 IRQHandler |
|||
DCD UART1_IRQHandler ;40, UART1 IRQHandler |
|||
DCD UART2_IRQHandler ;41, UART2 IRQHandler |
|||
DCD 0 ;42, Reserved |
|||
DCD 0 ;43, Reserved |
|||
DCD SPI1_IRQHandler ;44, SPI1 IRQHandler |
|||
DCD I2C0_IRQHandler ;45, I2C0 IRQHandler |
|||
DCD 0 ;46, Reserved |
|||
DCD CCM_IRQHandler ;47, CCM IRQHandler |
|||
|
|||
AREA |.text|, CODE, READONLY |
|||
|
|||
; Reset Handler |
|||
|
|||
Reset_IRQHandler PROC |
|||
EXPORT Reset_IRQHandler [WEAK] |
|||
IMPORT __main |
|||
IMPORT SystemInit |
|||
LDR R0, =SystemInit |
|||
BLX R0 |
|||
LDR R0, =__main |
|||
BX R0 |
|||
ENDP |
|||
|
|||
; Dummy Exception IRQHandlers (infinite loops which can be modified) |
|||
|
|||
NMI_IRQHandler PROC |
|||
EXPORT NMI_IRQHandler [WEAK] |
|||
B . |
|||
ENDP |
|||
HardFault_IRQHandler PROC |
|||
EXPORT HardFault_IRQHandler [WEAK] |
|||
B . |
|||
ENDP |
|||
SVC_IRQHandler PROC |
|||
EXPORT SVC_IRQHandler [WEAK] |
|||
B . |
|||
ENDP |
|||
PendSV_IRQHandler PROC |
|||
EXPORT PendSV_IRQHandler [WEAK] |
|||
B . |
|||
ENDP |
|||
SysTick_IRQHandler PROC |
|||
EXPORT SysTick_IRQHandler [WEAK] |
|||
B . |
|||
ENDP |
|||
|
|||
Default_IRQHandler PROC |
|||
EXPORT PINT0_IRQHandler [WEAK] |
|||
EXPORT PINT1_IRQHandler [WEAK] |
|||
EXPORT PINT2_IRQHandler [WEAK] |
|||
EXPORT PINT3_IRQHandler [WEAK] |
|||
EXPORT PINT4_IRQHandler [WEAK] |
|||
EXPORT PINT5_IRQHandler [WEAK] |
|||
EXPORT PINT6_IRQHandler [WEAK] |
|||
EXPORT PINT7_IRQHandler [WEAK] |
|||
EXPORT T16N0_IRQHandler [WEAK] |
|||
EXPORT T16N1_IRQHandler [WEAK] |
|||
EXPORT T16N2_IRQHandler [WEAK] |
|||
EXPORT T16N3_IRQHandler [WEAK] |
|||
EXPORT T32N0_IRQHandler [WEAK] |
|||
EXPORT WWDT_IRQHandler [WEAK] |
|||
EXPORT IWDT_IRQHandler [WEAK] |
|||
EXPORT RTC_IRQHandler [WEAK] |
|||
EXPORT KINT_IRQHandler [WEAK] |
|||
EXPORT ADC_IRQHandler [WEAK] |
|||
EXPORT LVD_IRQHandler [WEAK] |
|||
EXPORT UART0_IRQHandler [WEAK] |
|||
EXPORT UART1_IRQHandler [WEAK] |
|||
EXPORT UART2_IRQHandler [WEAK] |
|||
EXPORT SPI1_IRQHandler [WEAK] |
|||
EXPORT I2C0_IRQHandler [WEAK] |
|||
EXPORT CCM_IRQHandler [WEAK] |
|||
|
|||
PINT0_IRQHandler |
|||
PINT1_IRQHandler |
|||
PINT2_IRQHandler |
|||
PINT3_IRQHandler |
|||
PINT4_IRQHandler |
|||
PINT5_IRQHandler |
|||
PINT6_IRQHandler |
|||
PINT7_IRQHandler |
|||
T16N0_IRQHandler |
|||
T16N1_IRQHandler |
|||
T16N2_IRQHandler |
|||
T16N3_IRQHandler |
|||
T32N0_IRQHandler |
|||
WWDT_IRQHandler |
|||
IWDT_IRQHandler |
|||
RTC_IRQHandler |
|||
KINT_IRQHandler |
|||
ADC_IRQHandler |
|||
LVD_IRQHandler |
|||
UART0_IRQHandler |
|||
UART1_IRQHandler |
|||
UART2_IRQHandler |
|||
SPI1_IRQHandler |
|||
I2C0_IRQHandler |
|||
CCM_IRQHandler |
|||
|
|||
B . |
|||
|
|||
ENDP |
|||
|
|||
ALIGN |
|||
|
|||
; User Initial Stack & Heap |
|||
|
|||
IF :DEF:__MICROLIB |
|||
|
|||
EXPORT __initial_sp |
|||
EXPORT __heap_base |
|||
EXPORT __heap_limit |
|||
|
|||
ELSE |
|||
|
|||
IMPORT __use_two_region_memory |
|||
EXPORT __user_initial_stackheap |
|||
__user_initial_stackheap |
|||
|
|||
LDR R0, = Heap_Mem |
|||
LDR R1, =(Stack_Mem + Stack_Size) |
|||
LDR R2, = (Heap_Mem + Heap_Size) |
|||
LDR R3, = Stack_Mem |
|||
BX LR |
|||
|
|||
ALIGN |
|||
|
|||
ENDIF |
|||
|
|||
END |
1068
project_ozone/Listings/project_o.map
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
46
project_ozone/project_o.uvgui.zel
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue