void timer0_config(void)
{
timer_ic_parameter_struct timer_icinitpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER0);
rcu_periph_clock_enable(RCU_SYSCFG);
timer_deinit(TIMER0);
/* TIMER0 configuration */
timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 299;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 65535;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0, &timer_initpara);
/* TIMER0 configuration */
/* TIMER0 CH1 input capture configuration */
timer_channel_input_struct_para_init(&timer_icinitpara);
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;
timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
timer_icinitpara.icfilter = 0x0;
timer_input_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_1, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_2, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_3, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_0, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_1, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_2, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_3, &timer_icinitpara);
timer_master_slave_mode_config(TIMER0 , TIMER_MASTER_SLAVE_MODE_ENABLE);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_0,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_1,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_2,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_3,TIMER_MCH_MODE_INDEPENDENTLY);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI0FEM0);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI1FEM1);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI2FEM2);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI3FEM3);
timer_slave_mode_select(TIMER0 , TIMER_SLAVE_MODE_EVENT);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
/* clear channel 0 interrupt bit */
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH1);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH2);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH0);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH1);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH2);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH3);
/* channel 0 interrupt enable */
timer_interrupt_enable(TIMER0, TIMER_INT_CH0);
timer_interrupt_enable(TIMER0, TIMER_INT_CH1);
timer_interrupt_enable(TIMER0, TIMER_INT_CH2);
timer_interrupt_enable(TIMER0, TIMER_INT_CH3);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH0);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH1);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH2);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH3);
/* TIMER0 counter enable */
timer_enable(TIMER0);
}