Skip to content

Commit afd2d11

Browse files
committed
按照GitHub AI 的PR建议
1. 增加关闭定时器实现 2. 去掉多余的break入口 3. KConfig缩进保持与当前已有的一致
1 parent 8dcf011 commit afd2d11

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

  • bsp/novosns/ns800

bsp/novosns/ns800/libraries/HAL_Drivers/drivers/drv_timer.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,26 @@ void TIM2_IRQHandler(void) { ns800_clock_timer_isr(&ns800_timers[TIM2_INDEX]); }
8484
static void ns800_clock_timer_init(rt_clock_timer_t *timer, rt_uint32_t state)
8585
{
8686
struct ns800_clock_timer *tim = (struct ns800_clock_timer *)timer->parent.user_data;
87+
TIM_TypeDef *htim = (TIM_TypeDef *)tim->instance;
8788

88-
__IO uint32_t cfg =
89-
TIM_PWMMODE_ONEPOINT |
90-
TIM_CLOCKDIVISION_DIV1 |
91-
TIM_AUTORELOADPRELOAD_ENABLE |
92-
TIM_COUNTERMODE_UP |
93-
TIM_ONEPULSEMODE_REPETITIVE;
94-
95-
TIM_configTimeBase((TIM_TypeDef *)tim->instance, 200-1, 100-1, cfg);
96-
TIM_clearFlags((TIM_TypeDef *)tim->instance, TIM_FLAG_UPDATE);
97-
TIM_enableInterruptSource((TIM_TypeDef *)tim->instance, TIM_IT_UPDATE);
89+
if(state)
90+
{
91+
__IO uint32_t cfg =
92+
TIM_PWMMODE_ONEPOINT |
93+
TIM_CLOCKDIVISION_DIV1 |
94+
TIM_AUTORELOADPRELOAD_ENABLE |
95+
TIM_COUNTERMODE_UP |
96+
TIM_ONEPULSEMODE_REPETITIVE;
97+
98+
TIM_configTimeBase(htim, 200-1, 100-1, cfg);
99+
TIM_clearFlags(htim, TIM_FLAG_UPDATE);
100+
TIM_enableInterruptSource(htim, TIM_IT_UPDATE);
101+
}
102+
else
103+
{
104+
TIM_disableInterruptSource(htim, TIM_IT_UPDATE);
105+
TIM_disableCounter(htim, TIM_FLAG_UPDATE);
106+
}
98107
}
99108

100109
static rt_err_t ns800_clock_timer_start(rt_clock_timer_t *timer, rt_uint32_t cnt, rt_clock_timer_mode_t mode)
@@ -146,7 +155,6 @@ static rt_err_t ns800_clock_timer_control(rt_clock_timer_t *timer, rt_uint32_t c
146155
case CLOCK_TIMER_CTRL_FREQ_SET:
147156
freq = *(rt_uint32_t *)args;
148157
__set_timerx_freq(timer, freq);
149-
break;
150158
break;
151159
case CLOCK_TIMER_CTRL_INFO_GET:
152160
*(struct rt_clock_timer_info*)args = *timer->info;

bsp/novosns/ns800/ns800rt7p65-nssinepad/board/Kconfig

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ menu "On-chip Peripheral Drivers"
105105

106106
endif
107107

108-
menuconfig BSP_USING_TIM
109-
bool "Enable TIM (Hardware Timer)"
110-
select RT_USING_CLOCK_TIME
111-
default n
112-
help
113-
Enable hardware timer TIM driver
114-
115-
if BSP_USING_TIM
116-
menu "TIM Timer Configuration"
117-
config BSP_USING_TIM1
118-
bool "Enable TIM1"
119-
default n
120-
config BSP_USING_TIM2
121-
bool "Enable TIM2"
122-
default n
123-
endmenu
124-
125-
endif
108+
menuconfig BSP_USING_TIM
109+
bool "Enable TIM (Hardware Timer)"
110+
select RT_USING_CLOCK_TIME
111+
default n
112+
help
113+
Enable hardware timer TIM driver
114+
115+
if BSP_USING_TIM
116+
menu "TIM Timer Configuration"
117+
config BSP_USING_TIM1
118+
bool "Enable TIM1"
119+
default n
120+
config BSP_USING_TIM2
121+
bool "Enable TIM2"
122+
default n
123+
endmenu
124+
125+
endif
126126

127127
endmenu

0 commit comments

Comments
 (0)