void shrtimer_config1(void)
{
/* -----------------------------------------------------------------------
fSHRTIMER_CK:120MHz, from CK_SYS
ST2_CHO_O: set request at Slave_TIMER2 compare 0 event, reset request at Slave_TIMER2 compare 1 event
ST2_CH1_O: the waveform is complementary to channel 0
----------------------------------------------------------------------- */
shrtimer_baseinit_parameter_struct baseinit_para;
shrtimer_timerinit_parameter_struct timerinit_para;
shrtimer_timercfg_parameter_struct timercfg_para;
shrtimer_comparecfg_parameter_struct comparecfg_para;
shrtimer_channel_outputcfg_parameter_struct outcfg_para;
shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;
shrtimer_synccfg_parameter_struct synccfg_para;
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
gpio_afio_port_config(AFIO_PB12_SHRTIMER_CFG, ENABLE);
gpio_afio_port_config(AFIO_PB13_SHRTIMER_CFG, ENABLE);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_13);
gpio_afio_port_config(AFIO_PB14_SHRTIMER_CFG, ENABLE);
gpio_afio_port_config(AFIO_PB15_SHRTIMER_CFG, ENABLE);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_14);
gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_15);
/* clock config */
rcu_periph_clock_enable(RCU_SHRTIMER);
rcu_shrtimer_clock_config(RCU_SHRTIMERSRC_CKSYS);
/* periodic DLL calibration */
shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);
while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));
/* Slave_TIMER2,3 time base clock config */
shrtimer_baseinit_struct_para_init(&baseinit_para);
baseinit_para.period = LLCFPWMMAX; //
baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL16;
baseinit_para.repetitioncounter = 0;
baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;
shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &baseinit_para);
shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &baseinit_para);
// shrtimer_synccfg_struct_para_init(&synccfg_para);
// synccfg_para.input_source = SHRTIMER_SYNCINPUTSOURCE_INTERNAL;
// shrtimer_synchronization_config(SHRTIMER0, &synccfg_para);
/* initialize Slave_TIMER2,3 to work in waveform mode */
shrtimer_timerinit_struct_para_init(&timerinit_para);
timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;
timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;
shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timerinit_para);
shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timerinit_para);
/* configure the general behavior of a Slave_TIMER2,3 which work in waveform mode */
shrtimer_timercfg_struct_para_init(&timercfg_para);
timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;
timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;
timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_ENABLED;
timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;
timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;
timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timercfg_para);
shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &timercfg_para);
shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
deadtimecfg_para.fallingsign_protect = SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;
deadtimecfg_para.falling_protect = SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;
deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;
deadtimecfg_para.falling_value = 200;
deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL16;
deadtimecfg_para.risingsign_protect = SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;
deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;
deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;
deadtimecfg_para.rising_value = 200;
shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &deadtimecfg_para);
shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, &deadtimecfg_para);
/* configures the compare unit of a Slave_TIMER2,3 which work in waveform mode */
shrtimer_comparecfg_struct_para_init(&comparecfg_para);
comparecfg_para.compare_value = 100;
shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE0, &comparecfg_para);
comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE1, &comparecfg_para);
comparecfg_para.compare_value = 100;
shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE0, &comparecfg_para);
comparecfg_para.compare_value = 100 + ((LLCFPWMMAX)/2);
shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_COMPARE1, &comparecfg_para);
/* configures the ST2_CH0_O/ST2_CH1_O output of a Slave_TIMER2 work in waveform mode */
/* configures the ST3_CH0_O/ST3_CH1_O output of a Slave_TIMER3 work in waveform mode */
shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_NONE;
outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP1;
outcfg_para.set_request = SHRTIMER_CHANNEL_SET_PER;
shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH0, &outcfg_para);
shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH1, &outcfg_para);
shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH0, &outcfg_para);
shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER3, SHRTIMER_ST3_CH1, &outcfg_para);
/* enable output channel */
shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH0);
shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH1);
shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH0);
shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST3_CH1);
/* enable a counter */
shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST2_COUNTER);
shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST3_COUNTER);
}