|
@@ -4,38 +4,33 @@
|
|
|
#include "port.h"
|
|
|
#include "mb.h"
|
|
|
#include "mbport.h"
|
|
|
+#include <stdbool.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);
|
|
|
+ nvic_irq_disable(TMR7_GLOBAL_IRQn);
|
|
|
|
|
|
- tmr_interrupt_enable(TMR7, TMR_OVF_INT, TRUE);
|
|
|
+ crm_periph_clock_enable(CRM_TMR7_PERIPH_CLOCK, TRUE);
|
|
|
+
|
|
|
+ tmr_base_init(TMR7, (usTim1Timerout50us * 50) - 1, (crm_clocks_freq_struct.ahb_freq / 1000000) - 1);
|
|
|
+ tmr_cnt_dir_set(TMR7, TMR_COUNT_UP);
|
|
|
|
|
|
+ NVIC_ClearPendingIRQ(TMR7_GLOBAL_IRQn);
|
|
|
+ nvic_irq_enable(TMR7_GLOBAL_IRQn, 5, 0);
|
|
|
+
|
|
|
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.
|
|
@@ -45,49 +40,44 @@ 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);
|
|
|
- }
|
|
|
+ tmr_flag_clear(TMR7, TMR_OVF_FLAG);
|
|
|
+
|
|
|
+ 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_flag_clear(TMR7, TMR_OVF_FLAG);
|
|
|
tmr_interrupt_enable(TMR7, TMR_OVF_INT, TRUE);
|
|
|
-#if 0
|
|
|
- downcounter = timeout;
|
|
|
- HAL_TIM_Base_Start_IT(&htim);
|
|
|
-#endif
|
|
|
+ tmr_counter_value_set(TMR7, 0);
|
|
|
+ tmr_counter_enable(TMR7, TRUE);
|
|
|
}
|
|
|
|
|
|
//
|
|
|
void vMBPortTimersDisable()
|
|
|
{
|
|
|
+ tmr_flag_clear(TMR7, TMR_OVF_FLAG);
|
|
|
tmr_interrupt_enable(TMR7, TMR_OVF_INT, FALSE);
|
|
|
-// HAL_TIM_Base_Stop_IT(&htim);
|
|
|
+ tmr_counter_value_set(TMR7, 0);
|
|
|
+ tmr_counter_enable(TMR7, FALSE);
|
|
|
}
|
|
|
|
|
|
//
|