12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #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 )
- {
- 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;
- }
- /* 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) {
- vMBPortSetWithinException(TRUE);
- prvvTIMERExpiredISR();
- vMBPortSetWithinException(FALSE);
- }
- }
- }
- //
- 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);
- tmr_interrupt_enable(TMR7, TMR_OVF_INT, 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 );
- }
|