File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 19
19
20
20
#include "hal/us_ticker_api.h"
21
21
#include "us_ticker_defines.h"
22
+ #include "mbed_critical.h"
22
23
23
24
// This variable is set to 1 at the of mbed_sdk_init function.
24
25
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
@@ -50,6 +51,9 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
50
51
51
52
uint32_t HAL_GetTick ()
52
53
{
54
+ // Prevent a task switch causing errors since this function isn't re-entrant
55
+ core_util_critical_section_enter ();
56
+
53
57
uint32_t new_time = us_ticker_read ();
54
58
uint32_t elapsed_time = (((new_time - prev_time ) & US_TICKER_MASK ) + prev_tick_remainder );
55
59
prev_time = new_time ;
@@ -67,6 +71,8 @@ uint32_t HAL_GetTick()
67
71
prev_tick_remainder = elapsed_time % 1000 ;
68
72
}
69
73
total_ticks += elapsed_ticks ;
74
+
75
+ core_util_critical_section_exit ();
70
76
return total_ticks ;
71
77
}
72
78
You can’t perform that action at this time.
0 commit comments