summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Needell <jerryneedell@gmail.com>2018-04-19 22:25:48 -0400
committerJerry Needell <jerryneedell@gmail.com>2018-04-19 22:25:48 -0400
commit16bb40b1102016cd483915ab517d43f6ce074f13 (patch)
treed9bea90e58e399ef82c1a8b6ce6b73a10de580db
parent3399d541c3c40b0dbe211b0507ae19b19d539ec5 (diff)
modify tic.c to chec if interrupts are enabled, rename us_between_ticks to us until_next_tick
-rw-r--r--ports/atmel-samd/tick.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c
index 9000be474..8a927785f 100644
--- a/ports/atmel-samd/tick.c
+++ b/ports/atmel-samd/tick.c
@@ -58,21 +58,24 @@ void tick_init() {
void tick_delay(uint32_t us) {
uint32_t ticks_per_us = common_hal_mcu_processor_get_frequency() / 1000 / 1000;
- uint32_t us_between_ticks = SysTick->VAL / ticks_per_us;
+ uint32_t us_until_next_tick = SysTick->VAL / ticks_per_us;
uint32_t start_tick;
while (us > 1000) {
+ // check if interrupts are disabled
+ if(__get_PRIMASK())
+ return; // if not just return
start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET
while (SysTick->VAL < start_tick) {}
- us -= us_between_ticks;
- us_between_ticks = 1000;
+ us -= us_until_next_tick;
+ us_until_next_tick = 1000;
}
- if(us&&(us < us_between_ticks)){
- while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {}
+ if(us&&(us < us_until_next_tick)){
+ while (SysTick->VAL > ((us_until_next_tick - us) * ticks_per_us)) {}
}
else {
start_tick=SysTick->VAL; // wait for SysTick->VAL to RESET
while (SysTick->VAL < start_tick) {}
- us -= us_between_ticks;
+ us -= us_until_next_tick;
if(us){
while (SysTick->VAL > ((1000 - us) * ticks_per_us)) {}
}