diff --git a/CHIRP/board/timer.c b/CHIRP/board/timer.c new file mode 100644 index 0000000..5c6fc27 --- /dev/null +++ b/CHIRP/board/timer.c @@ -0,0 +1,38 @@ +#include +#include +#include "gd32e23x.h" +#include "timer.h" +#include "gd32e23x.h" +#include "chirp_board_config.h" +#include "board_init.h" + +void timer_config(void) +{ + timer_oc_parameter_struct timer_ocinitpara; + timer_parameter_struct timer_initpara; + + rcu_periph_clock_enable(RCU_TIMER2); + timer_deinit(TIMER2); + timer_struct_para_init(&timer_initpara); + timer_initpara.prescaler = (80) - 1; + timer_initpara.alignedmode = TIMER_COUNTER_EDGE; + timer_initpara.counterdirection = TIMER_COUNTER_UP; + timer_initpara.period = 19999; + timer_initpara.clockdivision = TIMER_CKDIV_DIV1; + timer_initpara.repetitioncounter = 0; + timer_init(TIMER2, &timer_initpara); + timer_initpara.period = 9999; + timer_init(TIMER2, &timer_initpara); + + timer_channel_output_struct_para_init(&timer_ocinitpara); + timer_ocinitpara.outputstate = TIMER_CCX_ENABLE; + timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH; + timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; + timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocinitpara); + + timer_auto_reload_shadow_enable(TIMER2); + timer_interrupt_enable(TIMER2, TIMER_INT_CH0); + timer_enable(TIMER2); + + nvic_irq_enable(TIMER2_IRQn, 2); +} \ No newline at end of file diff --git a/CHIRP/board/timer.h b/CHIRP/board/timer.h new file mode 100644 index 0000000..a03cd3a --- /dev/null +++ b/CHIRP/board/timer.h @@ -0,0 +1,8 @@ +#ifndef TIMER_H +#define TIMER_H + +void timer_config(void); + + + +#endif /* TIMER_H */ \ No newline at end of file diff --git a/XLSW_SONIC/Keil_project/Project.uvoptx b/XLSW_SONIC/Keil_project/Project.uvoptx index 0bd7bab..b05d307 100644 --- a/XLSW_SONIC/Keil_project/Project.uvoptx +++ b/XLSW_SONIC/Keil_project/Project.uvoptx @@ -648,6 +648,18 @@ 0 0 + + 6 + 30 + 1 + 0 + 0 + 0 + ..\..\CHIRP\board\timer.c + timer.c + 0 + 0 + @@ -658,7 +670,7 @@ 0 7 - 30 + 31 1 0 0 @@ -670,7 +682,7 @@ 7 - 31 + 32 1 0 0 @@ -682,7 +694,7 @@ 7 - 32 + 33 1 0 0 @@ -694,7 +706,7 @@ 7 - 33 + 34 1 0 0 @@ -706,7 +718,7 @@ 7 - 34 + 35 1 0 0 @@ -718,7 +730,7 @@ 7 - 35 + 36 1 0 0 @@ -730,7 +742,7 @@ 7 - 36 + 37 1 0 0 @@ -750,7 +762,7 @@ 0 8 - 37 + 38 1 1 0 diff --git a/XLSW_SONIC/Keil_project/Project.uvprojx b/XLSW_SONIC/Keil_project/Project.uvprojx index cf192fc..e665939 100644 --- a/XLSW_SONIC/Keil_project/Project.uvprojx +++ b/XLSW_SONIC/Keil_project/Project.uvprojx @@ -553,6 +553,11 @@ 1 ..\..\CHIRP\board\i2c.c + + timer.c + 1 + ..\..\CHIRP\board\timer.c + diff --git a/XLSW_SONIC/gd32e23x_it.c b/XLSW_SONIC/gd32e23x_it.c index de1be6d..8dab929 100644 --- a/XLSW_SONIC/gd32e23x_it.c +++ b/XLSW_SONIC/gd32e23x_it.c @@ -35,6 +35,7 @@ OF SUCH DAMAGE. #include "gd32e23x_it.h" #include "main.h" #include "systick.h" +#include "chirp_bsp.h" /*! \brief this function handles NMI exception @@ -104,4 +105,18 @@ void EXTI4_15_IRQHandler(void){ exti_interrupt_flag_clear(EXTI_7); } +} + +/** + * @brief This function handles TIMER2 interrupt request. + * @param None + * @retval None + */ +void TIMER2_IRQHandler(void) +{ + if (SET == timer_interrupt_flag_get(TIMER2, TIMER_INT_FLAG_CH0)) + { + chbsp_led_toggle(0); + timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_CH0); + } } \ No newline at end of file diff --git a/XLSW_SONIC/main.c b/XLSW_SONIC/main.c index ef9c1d6..c9174ca 100644 --- a/XLSW_SONIC/main.c +++ b/XLSW_SONIC/main.c @@ -37,6 +37,7 @@ OF SUCH DAMAGE. #include #include "main.h" // #include "gd32e230c_eval.h" +#include "timer.h" #include "board_init.h" #include "chirp_board_config.h" #include "chirp_bsp.h" @@ -277,10 +278,12 @@ int main(void) } printf("Starting measurements\n"); + timer_config(); + while (1) { handle_data_ready(grp_ptr); - chbsp_led_toggle(dev_num); + // chbsp_led_toggle(dev_num); delay_ms(MEASUREMENT_INTERVAL_MS); } }