18
18
#include "PeripheralNames.h"
19
19
#include "hal_tick.h"
20
20
21
- // A 16-bit timer is used
22
21
#if TIM_MST_16BIT
22
+ #define TIMER_TICKER_BIT_WIDTH 16
23
+ #else
24
+ #define TIMER_TICKER_BIT_WIDTH 32
25
+ #endif
23
26
24
27
TIM_HandleTypeDef TimMasterHandle ;
25
28
26
- // Declare ticker as 16 bits - mbed layer takes care of mapping to 32 or 64
27
- // bits
28
29
const ticker_info_t * us_ticker_get_info ()
29
30
{
30
31
static const ticker_info_t info = {
31
32
1000000 ,
32
- 16
33
+ TIMER_TICKER_BIT_WIDTH
33
34
};
34
35
return & info ;
35
36
}
36
37
37
38
void us_ticker_init (void )
38
39
{
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 );
41
42
}
42
43
43
44
uint32_t us_ticker_read ()
@@ -50,7 +51,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
50
51
// NOTE: This function must be called with interrupts disabled to keep our
51
52
// timer interrupt setup atomic
52
53
// 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 );
54
55
// Ensure the compare event starts clear
55
56
__HAL_TIM_CLEAR_FLAG (& TimMasterHandle , TIM_FLAG_CC1 );
56
57
// Enable IT
@@ -59,12 +60,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
59
60
60
61
void us_ticker_fire_interrupt (void )
61
62
{
62
- // Ensure the compare event starts clear
63
63
__HAL_TIM_CLEAR_FLAG (& TimMasterHandle , TIM_FLAG_CC1 );
64
64
LL_TIM_GenerateEvent_CC1 (TimMasterHandle .Instance );
65
65
// Enable IT
66
66
__HAL_TIM_ENABLE_IT (& TimMasterHandle , TIM_IT_CC1 );
67
-
68
67
}
69
68
70
69
/* NOTE: must be called with interrupts disabled! */
@@ -79,4 +78,3 @@ void us_ticker_clear_interrupt(void)
79
78
__HAL_TIM_CLEAR_FLAG (& TimMasterHandle , TIM_FLAG_CC1 );
80
79
}
81
80
82
- #endif // TIM_MST_16BIT
0 commit comments