Skip to content

Commit bba366d

Browse files
LMESTM0xc0170
authored andcommitted
Make us_ticker common between 16 and 32 bits counters
1 parent ee596cf commit bba366d

File tree

2 files changed

+8
-76
lines changed

2 files changed

+8
-76
lines changed

targets/TARGET_STM/us_ticker_16b.c renamed to targets/TARGET_STM/us_ticker.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,27 @@
1818
#include "PeripheralNames.h"
1919
#include "hal_tick.h"
2020

21-
// A 16-bit timer is used
2221
#if TIM_MST_16BIT
22+
#define TIMER_TICKER_BIT_WIDTH 16
23+
#else
24+
#define TIMER_TICKER_BIT_WIDTH 32
25+
#endif
2326

2427
TIM_HandleTypeDef TimMasterHandle;
2528

26-
// Declare ticker as 16 bits - mbed layer takes care of mapping to 32 or 64
27-
// bits
2829
const ticker_info_t* us_ticker_get_info()
2930
{
3031
static const ticker_info_t info = {
3132
1000000,
32-
16
33+
TIMER_TICKER_BIT_WIDTH
3334
};
3435
return &info;
3536
}
3637

3738
void us_ticker_init(void)
3839
{
39-
/* NOTE: assuming thaiHAL tick has already been initialized! */
40-
us_ticker_disable_interrupt();
40+
/* NOTE: assuming that HAL tick has already been initialized! */
41+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
4142
}
4243

4344
uint32_t us_ticker_read()
@@ -50,7 +51,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
5051
// NOTE: This function must be called with interrupts disabled to keep our
5152
// timer interrupt setup atomic
5253
// Set new output compare value
53-
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, timestamp & 0xFFFF);
54+
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
5455
// Ensure the compare event starts clear
5556
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
5657
// Enable IT
@@ -59,12 +60,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
5960

6061
void us_ticker_fire_interrupt(void)
6162
{
62-
// Ensure the compare event starts clear
6363
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
6464
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
6565
// Enable IT
6666
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
67-
6867
}
6968

7069
/* NOTE: must be called with interrupts disabled! */
@@ -79,4 +78,3 @@ void us_ticker_clear_interrupt(void)
7978
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
8079
}
8180

82-
#endif // TIM_MST_16BIT

targets/TARGET_STM/us_ticker_32b.c

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)