diff options
| author | heyuanjie87 <[email protected]> | 2015-09-06 15:05:47 +0800 |
|---|---|---|
| committer | heyuanjie87 <[email protected]> | 2015-09-06 15:05:47 +0800 |
| commit | d19f424909bbcaa22b222728aa94b65e4aa8a9ed (patch) | |
| tree | a6b86a535a94feb3ea074e93e24b363ea1875a97 /bsp | |
| parent | 47b3a4d3cc090dcf3a9abd554178acecc3c016cd (diff) | |
简化操作接口
Diffstat (limited to 'bsp')
| -rw-r--r-- | bsp/stm32f40x/drivers/drv_hwtimer.c | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/bsp/stm32f40x/drivers/drv_hwtimer.c b/bsp/stm32f40x/drivers/drv_hwtimer.c index ba6aed9dcb..8802021e18 100644 --- a/bsp/stm32f40x/drivers/drv_hwtimer.c +++ b/bsp/stm32f40x/drivers/drv_hwtimer.c @@ -1,5 +1,5 @@ /* - * File : gpio.c + * File : drv_hwtimer.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2015, RT-Thread Development Team * @@ -31,35 +31,34 @@ static void NVIC_Configuration(void) NVIC_Init(&NVIC_InitStructure); } -static void timer_init(rt_hwtimer_t *timer) +static void timer_init(rt_hwtimer_t *timer, rt_uint32_t state) { TIM_TypeDef *tim; tim = (TIM_TypeDef *)timer->parent.user_data; TIM_DeInit(tim); - NVIC_Configuration(); - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); - TIM_CounterModeConfig(tim, TIM_CounterMode_Up); -} - -static void timer_deinit(rt_hwtimer_t *timer) -{ - TIM_TypeDef *tim; - tim = (TIM_TypeDef *)timer->parent.user_data; - TIM_DeInit(tim); + if (state == 1) + { + NVIC_Configuration(); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + TIM_CounterModeConfig(tim, TIM_CounterMode_Up); + } } -static void timer_start(rt_hwtimer_t *timer, rt_hwtimer_mode_t opmode) +static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_t opmode) { TIM_TypeDef *tim; uint16_t m; tim = (TIM_TypeDef *)timer->parent.user_data; + TIM_SetAutoreload(tim, t); m = (opmode == HWTIMER_MODE_ONESHOT)? TIM_OPMode_Single : TIM_OPMode_Repetitive; TIM_SelectOnePulseMode(tim, m); TIM_Cmd(tim, ENABLE); + + return RT_EOK; } static void timer_stop(rt_hwtimer_t *timer) @@ -90,11 +89,11 @@ static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg) freq = *((rt_uint32_t*)arg); clk.PCLK1_Frequency *= 2; val = clk.PCLK1_Frequency/freq; - - TIM_ITConfig(tim, TIM_IT_Update, DISABLE); + + TIM_ITConfig(tim, TIM_IT_Update, DISABLE); TIM_PrescalerConfig(tim, val - 1, TIM_PSCReloadMode_Immediate); - TIM_ClearITPendingBit(TIM2, TIM_IT_Update); - TIM_ITConfig(tim, TIM_IT_Update, ENABLE); + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); + TIM_ITConfig(tim, TIM_IT_Update, ENABLE); } break; default: @@ -116,31 +115,19 @@ static rt_uint32_t timer_counter_get(rt_hwtimer_t *timer) return TIM_GetCounter(tim); } -static rt_err_t timer_timeout_set(rt_hwtimer_t *timer, rt_uint32_t t) -{ - TIM_TypeDef *tim; - - tim = (TIM_TypeDef *)timer->parent.user_data; - TIM_SetAutoreload(tim, t); - - return RT_EOK; -} - static const struct rt_hwtimer_info _info = { - 1000000, /* �����õ�������ʱ�� */ - 2000, /* �����õ���С����ʱ�� */ - 0xFFFF, /* ���ʱֵ */ - HWTIMER_CNTMODE_UP,/* ����������ʽ */ + 1000000, /* the maximum count frequency can be set */ + 2000, /* the minimum count frequency can be set */ + 0xFFFF, /* the maximum counter value */ + HWTIMER_CNTMODE_UP,/* Increment or Decreasing count mode */ }; static const struct rt_hwtimer_ops _ops = { timer_init, - timer_deinit, timer_start, timer_stop, - timer_timeout_set, timer_counter_get, timer_ctrl, }; |
