| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- /*********************************************************************************************************
- * Module : Timer.c
- * Abstract : Timer modules, this module is used to improve Timing service!
- * Version : 1.0.0
- * Author : Leopul(COPYRIGHT 2025 - 2027 Leopul. All rights reserved.)
- * Complete : 2025-02-16
- * Content : None
- * Note : None
- *********************************************************************************************************/
- #include "Timer.h"
- #include "gd32f30x_libopt.h"
- #include "main.h"
- static unsigned char s_i100msFlag = 0;
- static unsigned char s_i2msFlag = 0;
- static unsigned char s_i1secFlag = 0;
- volatile unsigned long int g_del_ms =0;
- static void ConfigTimer14(unsigned short arr, unsigned short psc);
- static void ConfigTimer15(unsigned short arr, unsigned short psc);
- static void ConfigTimer16(unsigned short arr, unsigned short psc);
- static sts_data_t *data = 0;
- static void ConfigTimer14(unsigned short arr, unsigned short psc)
- {
- timer_parameter_struct timer_initpara;
- rcu_periph_clock_enable(RCU_TIMER2);
- timer_deinit(TIMER2);
- timer_struct_para_init(&timer_initpara);
- timer_initpara.prescaler = psc;
- timer_initpara.counterdirection = TIMER_COUNTER_UP;
- timer_initpara.period = arr;
- timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
- timer_init(TIMER2, &timer_initpara);
- timer_interrupt_enable(TIMER2, TIMER_INT_UP);
- nvic_irq_enable(TIMER2_IRQn,0,3);
- timer_enable(TIMER2);
- }
- static uint8_t cnt_1 = 0;
- static uint8_t cnt_2 = 0;
- static uint8_t level_cnt1 = 0;
- static uint8_t level_cnt2 = 0;
- static uint32_t beep_cnt = 0;
- void TIMER2_IRQHandler(void)
- {
- //static unsigned short s_iCnt2 = 0;
- static uint16_t cnt_1000 = 0;
- static uint16_t cnt_100 = 0;
-
- if(timer_interrupt_flag_get(TIMER2, TIMER_INT_FLAG_UP) == SET)
- {
- timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
- }
- if(data->beep_flag || data->i_beep_flag[0].beep_waning || data->i_beep_flag[1].beep_waning || data->o_beep_flag.beep_waning)
- {
- beep_cnt++;
- if(beep_cnt >= data->beep_count)
- {
- beep_cnt = 0;
- data->beep();
- }
- }else
- {
- beep_cnt = 0;
- }
-
-
- #if 0
- if(data->input_1_up_flag)
- {
- level_cnt1 = 0;
- if(!data->input_1_down_flag)
- {
- cnt_1++;
- if(cnt_1 >= 3)
- {
- cnt_1 = data->input_1_up_flag = data->input_1_down_flag = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_1] = 0;
- if(data->m_data.input_status.input_status[INPUT_CHANNEL_2]) data->choise_input(INPUT_CHANNEL_2);
- }
- }else
- {
- cnt_1 = data->input_1_up_flag = data->input_1_down_flag = 0;
- }
- }
- #endif
- if(data->exit_init_flag)
- {
- if(data->get_input1_level()==0)
- {
- level_cnt1++;
- if(level_cnt1 >= 3)
- {
- level_cnt1 = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_1] = 0;
- if(data->m_data.input_status.input_status[INPUT_CHANNEL_2])
- {
- if(data->m_data.md_choise.choise_ch != INPUT_CHANNEL_2)
- {
- data->choise_input(INPUT_CHANNEL_2);
- }
- }
- }
- }else
- {
- level_cnt1 = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_1] = 1;
- }
- }
-
-
- #if 0
- if(data->input_2_up_flag)
- {
- if(!data->input_2_down_flag)
- {
- cnt_2++;
- if(cnt_2 >= 3)
- {
- cnt_2 = data->input_2_up_flag = data->input_2_down_flag = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_2] = 0;
- if(data->m_data.input_status.input_status[INPUT_CHANNEL_1]) data->choise_input(INPUT_CHANNEL_1);
- }
- }else
- {
- cnt_2 = data->input_2_up_flag = data->input_2_down_flag = 0;
- }
- }
- #endif
- if(data->exit_init_flag)
- {
- if(data->get_input2_level()==0)
- {
- level_cnt2++;
- if(level_cnt2 >= 2)
- {
- level_cnt2 = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_2] = 0;
- if(data->m_data.input_status.input_status[INPUT_CHANNEL_1])
- {
- if(data->m_data.md_choise.choise_ch != INPUT_CHANNEL_1)
- {
- data->choise_input(INPUT_CHANNEL_1);
- }
- }
- }
- }else
- {
- level_cnt2 = 0;
- data->m_data.input_status.input_status[INPUT_CHANNEL_2] = 1;
- }
- }
- cnt_1000++;
- cnt_100++;
- if(cnt_1000 >= 1000)
- {
- data->flag_1000ms = 1;
- cnt_1000 = 0;
- }
- if(cnt_100 >= 100)
- {
- data->flag_100ms = 1;
- cnt_100 = 0;
- }
- }
- void InitTimer(void)
- {
- data = get_sts();
- ConfigTimer14(999, 71); //72MHz/(71+1)=1MHz£¬ÓÉ0¼ÆÊýµ½999Ϊ1ms
- }
|