Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9dfb520

Browse files
committed
refactor(HardwareTimer): error handler usage
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent7b96cbd commit9dfb520

File tree

1 file changed

+13
-55
lines changed

1 file changed

+13
-55
lines changed

‎libraries/SrcWrapper/src/HardwareTimer.cpp

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ HardwareTimer::HardwareTimer(TIM_TypeDef *instance)
7575
voidHardwareTimer::setup(TIM_TypeDef *instance)
7676
{
7777
uint32_t index =get_timer_index(instance);
78-
if (index == UNKNOWN_TIMER) {
79-
Error_Handler();
80-
}
8178

8279
// Already initialized?
8380
if (_timerObj.handle.Instance) {
@@ -174,14 +171,7 @@ void HardwareTimer::pauseChannel(uint32_t channel)
174171

175172
int timAssociatedInputChannel;
176173
int LLChannel =getLLChannel(channel);
177-
if (LLChannel == -1) {
178-
Error_Handler();
179-
}
180-
181174
int interrupt =getIT(channel);
182-
if (interrupt == -1) {
183-
Error_Handler();
184-
}
185175

186176
// Disable channel and corresponding interrupt
187177
__HAL_TIM_DISABLE_IT(&(_timerObj.handle), interrupt);
@@ -234,11 +224,11 @@ void HardwareTimer::resume(void)
234224
/**
235225
* @brief Convert arduino channel into HAL channel
236226
* @param Arduino channel [1..4]
237-
* @retval HAL channel.return -1 if arduino channel is invalid
227+
* @retval HAL channel.Error handler called if arduino channel is invalid
238228
*/
239229
intHardwareTimer::getChannel(uint32_t channel)
240230
{
241-
uint32_t return_value;
231+
int return_value = -1;
242232

243233
switch (channel) {
244234
case1:
@@ -254,15 +244,15 @@ int HardwareTimer::getChannel(uint32_t channel)
254244
return_value = TIM_CHANNEL_4;
255245
break;
256246
default:
257-
return_value = -1;
247+
Error_Handler();
258248
}
259249
return return_value;
260250
}
261251

262252
/**
263253
* @brief Convert arduino channel into LL channels used (regular and/or complementary)
264254
* @param Arduino channel [1..4]
265-
* @retval LL channel.return -1 if arduino channel is invalid
255+
* @retval LL channel.Error handler called if arduino channel is invalid
266256
*/
267257
intHardwareTimer::getLLChannel(uint32_t channel)
268258
{
@@ -310,17 +300,20 @@ int HardwareTimer::getLLChannel(uint32_t channel)
310300
return_value = -1;
311301
}
312302
}
303+
if (return_value == -1) {
304+
Error_Handler();
305+
}
313306
return return_value;
314307
}
315308

316309
/**
317310
* @brief Convert arduino channel into HAL Interrupt ID
318311
* @param Arduino channel [1..4]
319-
* @retval HAL channel.return -1 if arduino channel is invalid
312+
* @retval HAL channel.Error handler called if arduino channel is invalid
320313
*/
321314
intHardwareTimer::getIT(uint32_t channel)
322315
{
323-
uint32_t return_value;
316+
int return_value = -1;
324317

325318
switch (channel) {
326319
case1:
@@ -336,7 +329,7 @@ int HardwareTimer::getIT(uint32_t channel)
336329
return_value = TIM_IT_CC4;
337330
break;
338331
default:
339-
return_value = -1;
332+
Error_Handler();
340333
}
341334
return return_value;
342335
}
@@ -378,19 +371,7 @@ void HardwareTimer::resumeChannel(uint32_t channel)
378371
{
379372
int timChannel =getChannel(channel);
380373
int timAssociatedInputChannel;
381-
if (timChannel == -1) {
382-
Error_Handler();
383-
}
384-
385374
int interrupt =getIT(channel);
386-
if (interrupt == -1) {
387-
Error_Handler();
388-
}
389-
390-
int LLChannel =getLLChannel(channel);
391-
if (LLChannel == -1) {
392-
Error_Handler();
393-
}
394375

395376
// Clear flag and enable IT
396377
if (callbacks[channel]) {
@@ -643,10 +624,6 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, Ch
643624
TIM_OC_InitTypeDef channelOC;
644625
TIM_IC_InitTypeDef channelIC;
645626

646-
if (timChannel == -1) {
647-
Error_Handler();
648-
}
649-
650627
/* Configure some default values. Maybe overwritten later*/
651628
channelOC.OCMode = TIMER_NOT_USED;
652629
channelOC.Pulse =__HAL_TIM_GET_COMPARE(&(_timerObj.handle), timChannel);// keep same value already written in hardware register
@@ -822,10 +799,6 @@ void HardwareTimer::setCaptureCompare(uint32_t channel, uint32_t compare, TimerC
822799
uint32_t Prescalerfactor =LL_TIM_GetPrescaler(_timerObj.handle.Instance) +1;
823800
uint32_t CCR_RegisterValue;
824801

825-
if (timChannel == -1) {
826-
Error_Handler();
827-
}
828-
829802
switch (format) {
830803
case MICROSEC_COMPARE_FORMAT:
831804
CCR_RegisterValue = ((compare * (getTimerClkFreq() /1000000)) / Prescalerfactor);
@@ -889,10 +862,6 @@ uint32_t HardwareTimer::getCaptureCompare(uint32_t channel, TimerCompareFormat_
889862
uint32_t Prescalerfactor =LL_TIM_GetPrescaler(_timerObj.handle.Instance) +1;
890863
uint32_t return_value;
891864

892-
if (timChannel == -1) {
893-
Error_Handler();
894-
}
895-
896865
switch (format) {
897866
case MICROSEC_COMPARE_FORMAT:
898867
return_value = (uint32_t)((CCR_RegisterValue * Prescalerfactor *1000000.0) /getTimerClkFreq());
@@ -1030,9 +999,6 @@ void HardwareTimer::detachInterrupt()
1030999
voidHardwareTimer::attachInterrupt(uint32_t channel,callback_function_t callback)
10311000
{
10321001
int interrupt =getIT(channel);
1033-
if (interrupt == -1) {
1034-
Error_Handler();
1035-
}
10361002

10371003
if ((channel ==0) || (channel > (TIMER_CHANNELS +1))) {
10381004
Error_Handler();// only channel 1..4 have an interrupt
@@ -1059,9 +1025,6 @@ void HardwareTimer::attachInterrupt(uint32_t channel, callback_function_t callba
10591025
voidHardwareTimer::detachInterrupt(uint32_t channel)
10601026
{
10611027
int interrupt =getIT(channel);
1062-
if (interrupt == -1) {
1063-
Error_Handler();
1064-
}
10651028

10661029
if ((channel ==0) || (channel > (TIMER_CHANNELS +1))) {
10671030
Error_Handler();// only channel 1..4 have an interrupt
@@ -1198,14 +1161,6 @@ bool HardwareTimer::isRunningChannel(uint32_t channel)
11981161
int interrupt =getIT(channel);
11991162
bool ret;
12001163

1201-
if (LLChannel == -1) {
1202-
Error_Handler();
1203-
}
1204-
1205-
if (interrupt == -1) {
1206-
Error_Handler();
1207-
}
1208-
12091164
// channel is running if: timer is running, and either output channel is
12101165
// enabled or interrupt is set
12111166
ret =LL_TIM_CC_IsEnabledChannel(_timerObj.handle.Instance, LLChannel)
@@ -1365,6 +1320,9 @@ timer_index_t get_timer_index(TIM_TypeDef *instance)
13651320
index = TIMER22_INDEX;
13661321
}
13671322
#endif
1323+
if (index == UNKNOWN_TIMER) {
1324+
Error_Handler();
1325+
}
13681326
return index;
13691327
}
13701328

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp