123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #include "at32f403a_407.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "port.h"
- #include "mb.h"
- #include "mbport.h"
- static void prvvTIMERExpiredISR( void );
- static uint16_t timeout = 0;
- static uint16_t downcounter = 0;
- BOOL xMBPortTimersInit( USHORT usTim1Timerout50us )
- {
- #if 1
- crm_clocks_freq_type crm_clocks_freq_struct = {0};
-
- crm_periph_clock_enable(CRM_TMR7_PERIPH_CLOCK, TRUE);
- crm_clocks_freq_get(&crm_clocks_freq_struct);
- tmr_base_init(TMR7, 1, 5999);
- tmr_cnt_dir_set(TMR7, TMR_COUNT_UP);
-
- tmr_flag_clear(TMR7, TMR_OVF_FLAG);
- nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
- nvic_irq_enable(TMR7_GLOBAL_IRQn, 5, 0);
-
- timeout = usTim1Timerout50us;
-
- tmr_counter_enable(TMR7, FALSE);
-
- tmr_interrupt_enable(TMR7, TMR_OVF_INT, TRUE);
-
- return TRUE;
- #endif
- #if 0
- __HAL_RCC_TIM6_CLK_ENABLE();
- __HAL_RCC_TIM6_FORCE_RESET();
- __HAL_RCC_TIM6_RELEASE_RESET();
-
- htim.Instance = TIM6;
- htim.Init.Prescaler = (HAL_RCC_GetPCLK1Freq() / 1000000) - 1;
- htim.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim.Init.Period = 50 - 1;
- htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim.Init.RepetitionCounter = 0;
- htim.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
- timeout = usTim1Timerout50us;
- HAL_TIM_Base_Init(&htim);
- HAL_NVIC_SetPriority(TIM6_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(TIM6_IRQn);
- return TRUE;
- #endif
- }
- /* Create an ISR which is called whenever the timer has expired. This function
- * must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that
- * the timer has expired.
- */
- static void prvvTIMERExpiredISR( void )
- {
- ( void )pxMBPortCBTimerExpired( );
- }
- void TMR7_GLOBAL_IRQHandler(void)
- {
- if(tmr_flag_get(TMR7, TMR_OVF_FLAG) != RESET)
- {
- tmr_flag_clear(TMR7, TMR_OVF_FLAG);
- if (!--downcounter)
- prvvTIMERExpiredISR();
- }
- }
- #if 0
- void TIM6_IRQHandler(void)
- {
- if(__HAL_TIM_GET_FLAG(&htim, TIM_FLAG_UPDATE) != RESET && __HAL_TIM_GET_IT_SOURCE(&htim, TIM_IT_UPDATE) != RESET)
- {
- __HAL_TIM_CLEAR_IT(&htim, TIM_IT_UPDATE);
-
-
- if (!--downcounter)
- prvvTIMERExpiredISR();
-
- }
- }
- #endif
- void
- vMBPortTimerClose( void )
- {
- tmr_interrupt_enable(TMR7, TMR_OVF_INT, FALSE);
- tmr_counter_enable(TMR7, FALSE);
-
- #if 0
- HAL_NVIC_DisableIRQ(TIM6_IRQn);
- __HAL_RCC_TIM6_CLK_DISABLE();
- #endif
- }
- void
- vMBPortTimersEnable( )
- {
- downcounter = timeout;
- tmr_counter_enable(TMR7, TRUE);
- #if 0
- downcounter = timeout;
- HAL_TIM_Base_Start_IT(&htim);
- #endif
- }
- void
- vMBPortTimersDisable( )
- {
- tmr_interrupt_enable(TMR7, TMR_OVF_INT, FALSE);
- // HAL_TIM_Base_Stop_IT(&htim);
- }
- void
- vMBPortTimersDelay( USHORT usTimeOutMS )
- {
- vTaskDelay( usTimeOutMS / portTICK_RATE_MS );
- }
|