Skip to content

Commit 16bb40b

Browse files
committed
modify tic.c to chec if interrupts are enabled, rename us_between_ticks to us until_next_tick
1 parent 3399d54 commit 16bb40b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ports/atmel-samd/tick.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,24 @@ void tick_init() {
5858

5959
void tick_delay(uint32_t us) {
6060
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;
6262
uint32_t start_tick;
6363
while (us > 1000) {
64+
// check if interrupts are disabled
65+
if(__get_PRIMASK())
66+
return; // if not just return
6467
start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET
6568
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;
6871
}
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)) {}
7174
}
7275
else {
7376
start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET
7477
while (SysTick->VAL < start_tick) {}
75-
us -= us_between_ticks;
78+
us -= us_until_next_tick;
7679
if(us){
7780
while (SysTick->VAL > ((1000 - us) * ticks_per_us)) {}
7881
}

0 commit comments

Comments
 (0)