runtime: update to avoid //go:volatile
There was exactly one change in the output of the smoke tests: examples/test. However, it still runs just fine on a PCA10040.
Этот коммит содержится в:
родитель
9673ad3774
коммит
c84c625585
5 изменённых файлов: 23 добавлений и 33 удалений
|
@ -6,6 +6,7 @@ import (
|
||||||
"device/arm"
|
"device/arm"
|
||||||
"device/sam"
|
"device/sam"
|
||||||
"machine"
|
"machine"
|
||||||
|
"runtime/volatile"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -230,10 +231,7 @@ var (
|
||||||
timerLastCounter uint64
|
timerLastCounter uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:volatile
|
var timerWakeup volatile.Register8
|
||||||
type isrFlag bool
|
|
||||||
|
|
||||||
var timerWakeup isrFlag
|
|
||||||
|
|
||||||
const asyncScheduler = false
|
const asyncScheduler = false
|
||||||
|
|
||||||
|
@ -262,7 +260,7 @@ func ticks() timeUnit {
|
||||||
|
|
||||||
// ticks are in microseconds
|
// ticks are in microseconds
|
||||||
func timerSleep(ticks uint32) {
|
func timerSleep(ticks uint32) {
|
||||||
timerWakeup = false
|
timerWakeup.Set(0)
|
||||||
if ticks < 30 {
|
if ticks < 30 {
|
||||||
// have to have at least one clock count
|
// have to have at least one clock count
|
||||||
ticks = 30
|
ticks = 30
|
||||||
|
@ -280,7 +278,7 @@ func timerSleep(ticks uint32) {
|
||||||
// enable IRQ for CMP0 compare
|
// enable IRQ for CMP0 compare
|
||||||
sam.RTC_MODE0.INTENSET.SetBits(sam.RTC_MODE0_INTENSET_CMP0)
|
sam.RTC_MODE0.INTENSET.SetBits(sam.RTC_MODE0_INTENSET_CMP0)
|
||||||
|
|
||||||
for !timerWakeup {
|
for timerWakeup.Get() == 0 {
|
||||||
arm.Asm("wfi")
|
arm.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,7 +288,7 @@ func handleRTC() {
|
||||||
// disable IRQ for CMP0 compare
|
// disable IRQ for CMP0 compare
|
||||||
sam.RTC_MODE0.INTFLAG.Set(sam.RTC_MODE0_INTENSET_CMP0)
|
sam.RTC_MODE0.INTFLAG.Set(sam.RTC_MODE0_INTENSET_CMP0)
|
||||||
|
|
||||||
timerWakeup = true
|
timerWakeup.Set(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initUSBClock() {
|
func initUSBClock() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"device/arm"
|
"device/arm"
|
||||||
"device/nrf"
|
"device/nrf"
|
||||||
"machine"
|
"machine"
|
||||||
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
@ -79,14 +80,11 @@ func ticks() timeUnit {
|
||||||
return timestamp
|
return timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:volatile
|
var rtc_wakeup volatile.Register8
|
||||||
type isrFlag bool
|
|
||||||
|
|
||||||
var rtc_wakeup isrFlag
|
|
||||||
|
|
||||||
func rtc_sleep(ticks uint32) {
|
func rtc_sleep(ticks uint32) {
|
||||||
nrf.RTC1.INTENSET.Set(nrf.RTC_INTENSET_COMPARE0)
|
nrf.RTC1.INTENSET.Set(nrf.RTC_INTENSET_COMPARE0)
|
||||||
rtc_wakeup = false
|
rtc_wakeup.Set(0)
|
||||||
if ticks == 1 {
|
if ticks == 1 {
|
||||||
// Race condition (even in hardware) at ticks == 1.
|
// Race condition (even in hardware) at ticks == 1.
|
||||||
// TODO: fix this in a better way by detecting it, like the manual
|
// TODO: fix this in a better way by detecting it, like the manual
|
||||||
|
@ -94,7 +92,7 @@ func rtc_sleep(ticks uint32) {
|
||||||
ticks = 2
|
ticks = 2
|
||||||
}
|
}
|
||||||
nrf.RTC1.CC[0].Set((nrf.RTC1.COUNTER.Get() + ticks) & 0x00ffffff)
|
nrf.RTC1.CC[0].Set((nrf.RTC1.COUNTER.Get() + ticks) & 0x00ffffff)
|
||||||
for !rtc_wakeup {
|
for rtc_wakeup.Get() == 0 {
|
||||||
arm.Asm("wfi")
|
arm.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,5 +101,5 @@ func rtc_sleep(ticks uint32) {
|
||||||
func handleRTC1() {
|
func handleRTC1() {
|
||||||
nrf.RTC1.INTENCLR.Set(nrf.RTC_INTENSET_COMPARE0)
|
nrf.RTC1.INTENCLR.Set(nrf.RTC_INTENSET_COMPARE0)
|
||||||
nrf.RTC1.EVENTS_COMPARE[0].Set(0)
|
nrf.RTC1.EVENTS_COMPARE[0].Set(0)
|
||||||
rtc_wakeup = true
|
rtc_wakeup.Set(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device/arm"
|
"device/arm"
|
||||||
|
"runtime/volatile"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,12 +37,9 @@ func ticks() timeUnit {
|
||||||
return timestamp
|
return timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:volatile
|
|
||||||
type regValue uint32
|
|
||||||
|
|
||||||
// UART0 output register.
|
// UART0 output register.
|
||||||
var stdoutWrite *regValue = (*regValue)(unsafe.Pointer(uintptr(0x4000c000)))
|
var stdoutWrite = (*volatile.Register8)(unsafe.Pointer(uintptr(0x4000c000)))
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
*stdoutWrite = regValue(c)
|
stdoutWrite.Set(uint8(c))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"device/arm"
|
"device/arm"
|
||||||
"device/stm32"
|
"device/stm32"
|
||||||
"machine"
|
"machine"
|
||||||
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -58,10 +59,7 @@ var (
|
||||||
timerLastCounter uint64
|
timerLastCounter uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:volatile
|
var timerWakeup volatile.Register8
|
||||||
type isrFlag bool
|
|
||||||
|
|
||||||
var timerWakeup isrFlag
|
|
||||||
|
|
||||||
func initRTC() {
|
func initRTC() {
|
||||||
// Enable the PWR and BKP.
|
// Enable the PWR and BKP.
|
||||||
|
@ -136,7 +134,7 @@ func ticks() timeUnit {
|
||||||
|
|
||||||
// ticks are in microseconds
|
// ticks are in microseconds
|
||||||
func timerSleep(ticks uint32) {
|
func timerSleep(ticks uint32) {
|
||||||
timerWakeup = false
|
timerWakeup.Set(0)
|
||||||
|
|
||||||
// STM32 timer update event period is calculated as follows:
|
// STM32 timer update event period is calculated as follows:
|
||||||
//
|
//
|
||||||
|
@ -177,7 +175,7 @@ func timerSleep(ticks uint32) {
|
||||||
stm32.TIM3.CR1.SetBits(stm32.TIM_CR1_CEN)
|
stm32.TIM3.CR1.SetBits(stm32.TIM_CR1_CEN)
|
||||||
|
|
||||||
// wait till timer wakes up
|
// wait till timer wakes up
|
||||||
for !timerWakeup {
|
for timerWakeup.Get() == 0 {
|
||||||
arm.Asm("wfi")
|
arm.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,6 +190,6 @@ func handleTIM3() {
|
||||||
stm32.TIM3.SR.ClearBits(stm32.TIM_SR_UIF)
|
stm32.TIM3.SR.ClearBits(stm32.TIM_SR_UIF)
|
||||||
|
|
||||||
// timer was triggered
|
// timer was triggered
|
||||||
timerWakeup = true
|
timerWakeup.Set(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"device/arm"
|
"device/arm"
|
||||||
"device/stm32"
|
"device/stm32"
|
||||||
"machine"
|
"machine"
|
||||||
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -114,10 +115,7 @@ var (
|
||||||
tickCount timeUnit
|
tickCount timeUnit
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:volatile
|
var timerWakeup volatile.Register8
|
||||||
type isrFlag bool
|
|
||||||
|
|
||||||
var timerWakeup isrFlag
|
|
||||||
|
|
||||||
// Enable the TIM3 clock.(sleep count)
|
// Enable the TIM3 clock.(sleep count)
|
||||||
func initTIM3() {
|
func initTIM3() {
|
||||||
|
@ -160,7 +158,7 @@ func ticks() timeUnit {
|
||||||
|
|
||||||
// ticks are in microseconds
|
// ticks are in microseconds
|
||||||
func timerSleep(ticks uint32) {
|
func timerSleep(ticks uint32) {
|
||||||
timerWakeup = false
|
timerWakeup.Set(0)
|
||||||
|
|
||||||
// CK_INT = APB1 x2 = 84mhz
|
// CK_INT = APB1 x2 = 84mhz
|
||||||
// prescale counter down from 84mhz to 10khz aka 0.1 ms frequency.
|
// prescale counter down from 84mhz to 10khz aka 0.1 ms frequency.
|
||||||
|
@ -180,7 +178,7 @@ func timerSleep(ticks uint32) {
|
||||||
stm32.TIM3.CR1.SetBits(stm32.TIM_CR1_CEN)
|
stm32.TIM3.CR1.SetBits(stm32.TIM_CR1_CEN)
|
||||||
|
|
||||||
// wait till timer wakes up
|
// wait till timer wakes up
|
||||||
for !timerWakeup {
|
for timerWakeup.Get() == 0 {
|
||||||
arm.Asm("wfi")
|
arm.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +193,7 @@ func handleTIM3() {
|
||||||
stm32.TIM3.SR.ClearBits(stm32.TIM_SR_UIF)
|
stm32.TIM3.SR.ClearBits(stm32.TIM_SR_UIF)
|
||||||
|
|
||||||
// timer was triggered
|
// timer was triggered
|
||||||
timerWakeup = true
|
timerWakeup.Set(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче