File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -58,21 +58,24 @@ void tick_init() {
58
58
59
59
void tick_delay (uint32_t us ) {
60
60
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency () / 1000 / 1000 ;
61
- uint32_t us_between_ticks = SysTick -> VAL / ticks_per_us ;
61
+ uint32_t us_until_next_tick = SysTick -> VAL / ticks_per_us ;
62
62
uint32_t start_tick ;
63
63
while (us > 1000 ) {
64
+ // check if interrupts are disabled
65
+ if (__get_PRIMASK ())
66
+ return ; // if not just return
64
67
start_tick = SysTick -> VAL ; // wait for SysTick->VAL to RESET
65
68
while (SysTick -> VAL < start_tick ) {}
66
- us -= us_between_ticks ;
67
- us_between_ticks = 1000 ;
69
+ us -= us_until_next_tick ;
70
+ us_until_next_tick = 1000 ;
68
71
}
69
- if (us && (us < us_between_ticks )){
70
- while (SysTick -> VAL > ((us_between_ticks - us ) * ticks_per_us )) {}
72
+ if (us && (us < us_until_next_tick )){
73
+ while (SysTick -> VAL > ((us_until_next_tick - us ) * ticks_per_us )) {}
71
74
}
72
75
else {
73
76
start_tick = SysTick -> VAL ; // wait for SysTick->VAL to RESET
74
77
while (SysTick -> VAL < start_tick ) {}
75
- us -= us_between_ticks ;
78
+ us -= us_until_next_tick ;
76
79
if (us ){
77
80
while (SysTick -> VAL > ((1000 - us ) * ticks_per_us )) {}
78
81
}
You can’t perform that action at this time.
0 commit comments