machine/nrf: refactor to use volatile package/API

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2019-05-20 10:42:50 +02:00
committed by Ayke
parent 0f6873cf02
commit 9f8340a970
6 changed files with 151 additions and 151 deletions
+10 -10
View File
@@ -32,16 +32,16 @@ func init() {
func initLFCLK() {
if machine.HasLowFrequencyCrystal {
nrf.CLOCK.LFCLKSRC = nrf.CLOCK_LFCLKSTAT_SRC_Xtal
nrf.CLOCK.LFCLKSRC.Set(nrf.CLOCK_LFCLKSTAT_SRC_Xtal)
}
nrf.CLOCK.TASKS_LFCLKSTART = 1
for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {
nrf.CLOCK.TASKS_LFCLKSTART.Set(1)
for nrf.CLOCK.EVENTS_LFCLKSTARTED.Get() == 0 {
}
nrf.CLOCK.EVENTS_LFCLKSTARTED = 0
nrf.CLOCK.EVENTS_LFCLKSTARTED.Set(0)
}
func initRTC() {
nrf.RTC1.TASKS_START = 1
nrf.RTC1.TASKS_START.Set(1)
arm.SetPriority(nrf.IRQ_RTC1, 0xc0) // low priority
arm.EnableIRQ(nrf.IRQ_RTC1)
}
@@ -72,7 +72,7 @@ var (
// overflow the counter, leading to incorrect results. This might be fixed by
// handling the overflow event.
func ticks() timeUnit {
rtcCounter := uint32(nrf.RTC1.COUNTER)
rtcCounter := uint32(nrf.RTC1.COUNTER.Get())
offset := (rtcCounter - rtcLastCounter) & 0xffffff // change since last measurement
rtcLastCounter = rtcCounter
timestamp += timeUnit(offset) // TODO: not precise
@@ -85,7 +85,7 @@ type isrFlag bool
var rtc_wakeup isrFlag
func rtc_sleep(ticks uint32) {
nrf.RTC1.INTENSET = nrf.RTC_INTENSET_COMPARE0
nrf.RTC1.INTENSET.Set(nrf.RTC_INTENSET_COMPARE0)
rtc_wakeup = false
if ticks == 1 {
// Race condition (even in hardware) at ticks == 1.
@@ -93,7 +93,7 @@ func rtc_sleep(ticks uint32) {
// describes.
ticks = 2
}
nrf.RTC1.CC[0] = (nrf.RTC1.COUNTER + nrf.RegValue(ticks)) & 0x00ffffff
nrf.RTC1.CC[0].Set((nrf.RTC1.COUNTER.Get() + ticks) & 0x00ffffff)
for !rtc_wakeup {
arm.Asm("wfi")
}
@@ -101,7 +101,7 @@ func rtc_sleep(ticks uint32) {
//go:export RTC1_IRQHandler
func handleRTC1() {
nrf.RTC1.INTENCLR = nrf.RTC_INTENSET_COMPARE0
nrf.RTC1.EVENTS_COMPARE[0] = 0
nrf.RTC1.INTENCLR.Set(nrf.RTC_INTENSET_COMPARE0)
nrf.RTC1.EVENTS_COMPARE[0].Set(0)
rtc_wakeup = true
}