Skip to content

Commit 4b24e88

Browse files
pabigotcarlescufi
authored andcommitted
drivers: timer: nrf: use irq_lock instead of spinlock
spinlock gains us nothing on an architecture that doesn't support SMP. Use the standard irq_lock() API so when we search for conditions that may decrease ISR responsiveness we can find them. Signed-off-by: Peter A. Bigot <[email protected]>
1 parent b4ece0a commit 4b24e88

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/timer/nrf_rtc_timer.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#define MIN_DELAY 32
2424

25-
static struct k_spinlock lock;
26-
2725
static u32_t last_count;
2826

2927
static u32_t counter_sub(u32_t a, u32_t b)
@@ -54,7 +52,7 @@ void rtc1_nrf_isr(void *arg)
5452
ARG_UNUSED(arg);
5553
RTC->EVENTS_COMPARE[0] = 0;
5654

57-
k_spinlock_key_t key = k_spin_lock(&lock);
55+
u32_t key = irq_lock();
5856
u32_t t = counter();
5957
u32_t dticks = counter_sub(t, last_count) / CYC_PER_TICK;
6058

@@ -69,7 +67,7 @@ void rtc1_nrf_isr(void *arg)
6967
set_comparator(next);
7068
}
7169

72-
k_spin_unlock(&lock, key);
70+
irq_unlock(key);
7371
z_clock_announce(dticks);
7472
}
7573

@@ -117,7 +115,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle)
117115
ticks = (ticks == K_FOREVER) ? MAX_TICKS : ticks;
118116
ticks = max(min(ticks - 1, (s32_t)MAX_TICKS), 0);
119117

120-
k_spinlock_key_t key = k_spin_lock(&lock);
118+
u32_t key = irq_lock();
121119
u32_t cyc, t = counter();
122120

123121
/* Round up to next tick boundary */
@@ -131,7 +129,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle)
131129
}
132130

133131
set_comparator(cyc);
134-
k_spin_unlock(&lock, key);
132+
irq_unlock(key);
135133
#endif
136134
}
137135

@@ -141,18 +139,18 @@ u32_t z_clock_elapsed(void)
141139
return 0;
142140
}
143141

144-
k_spinlock_key_t key = k_spin_lock(&lock);
142+
u32_t key = irq_lock();
145143
u32_t ret = counter_sub(counter(), last_count) / CYC_PER_TICK;
146144

147-
k_spin_unlock(&lock, key);
145+
irq_unlock(key);
148146
return ret;
149147
}
150148

151149
u32_t _timer_cycle_get_32(void)
152150
{
153-
k_spinlock_key_t key = k_spin_lock(&lock);
151+
u32_t key = irq_lock();
154152
u32_t ret = counter_sub(counter(), last_count) + last_count;
155153

156-
k_spin_unlock(&lock, key);
154+
irq_unlock(key);
157155
return ret;
158156
}

0 commit comments

Comments
 (0)