| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "bsp/bsp_driver.h"
- #include "libs/utils.h"
- #include "libs/logger.h"
- #include "hall_tmr.h"
- void hall_tmr_init(void) {
- gpio_init_type gpio_init_struct = {0};
- tmr_input_config_type tmr_input_config_struct;
-
- crm_periph_clock_enable(HALL_TIMER_RCU, TRUE);
- crm_periph_clock_enable(HALL_A_RCU, TRUE);
- crm_periph_clock_enable(HALL_B_RCU, TRUE);
- crm_periph_clock_enable(HALL_C_RCU, TRUE);
-
- /* timer hall sensor pin Configuration */
- gpio_default_para_init(&gpio_init_struct);
- gpio_init_struct.gpio_pins = HALL_A_PIN;
- gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
- gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
- gpio_init(HALL_A_GROUP, &gpio_init_struct);
-
- gpio_init_struct.gpio_pins = HALL_B_PIN;
- gpio_init(HALL_B_GROUP, &gpio_init_struct);
-
- gpio_init_struct.gpio_pins = HALL_C_PIN;
- gpio_init(HALL_C_GROUP, &gpio_init_struct);
-
- /* remap hall timer input pins */
- gpio_pin_remap_config(HALL_CAPTURE_IOMUX, TRUE);
-
- /* timer hall interface configuration */
- tmr_base_init(HALL_TIMER, 0xFFFF, 0);
- tmr_cnt_dir_set(HALL_TIMER, TMR_COUNT_UP);
-
- /* config ti1 trc as input source */
- tmr_input_default_para_init(&tmr_input_config_struct);
- tmr_input_config_struct.input_channel_select = TMR_SELECT_CHANNEL_1;
- tmr_input_config_struct.input_mapped_select = TMR_CC_CHANNEL_MAPPED_STI;
- tmr_input_config_struct.input_polarity_select = TMR_INPUT_RISING_EDGE;
- tmr_input_config_struct.input_filter_value = 0xF;
- tmr_input_channel_init(HALL_TIMER, &tmr_input_config_struct, TMR_CHANNEL_INPUT_DIV_1);
-
- /* xor funtion enable */
- tmr_channel1_input_select(HALL_TIMER, TMR_CHANEL1_2_3_CONNECTED_C1IRAW_XOR);
-
- /* select the tmr input trigger: C1INC */
- tmr_trigger_input_select(HALL_TIMER, TMR_SUB_INPUT_SEL_C1INC);
-
- /* select the slave mode: reset mode */
- tmr_sub_mode_select(HALL_TIMER, TMR_SUB_RESET_MODE);
-
- /* clear interrupt flag of hall timer */
- tmr_flag_clear(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_OVF_FLAG);
-
- /* enable overflow flag of hall timer */
- tmr_interrupt_enable(HALL_TIMER, TMR_TRIGGER_INT, TRUE);
-
- /* enable hall timer */
- tmr_counter_enable(HALL_TIMER, TRUE);
- nvic_irq_enable(HALL_TMR_IRQn, HALL_IRQ_PRIORITY, 0);
- }
- __weak void HALL_IRQHandler(void) {
- }
- void HALL_TMR_IRQHandler(void) {
- if (tmr_flag_get(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_C1_FLAG) != RESET) {
- tmr_flag_clear(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_C1_FLAG | TMR_OVF_FLAG);
- HALL_IRQHandler();
- }
- }
|