device/arm: add system timer registers (#654)

* device/arm: add system timer registers
Add SYST registers and bit definitions to device/arm.
Add a setup function.
Add an example that uses it to blink an LED.
This commit is contained in:
Infinoid
2019-10-24 15:17:06 -04:00
committed by Ron Evans
parent 2c15f36702
commit 6b1faeb882
3 changed files with 114 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
# TinyGo ARM SysTick example
This example uses the ARM System Timer to blink an LED. The timer fires
an interrupt 10 times per second. The interrupt handler toggles the LED on
and off.
Many ARM-based chips have this timer feature. If you run the example and the
LED blinks, then you have one.
The System Timer runs from a cycle counter. The more cycles, the slower the
LED will blink. This counter is 24 bits wide, which places an upper bound on
the number of cycles, and the slowness of the blinking.
+28
View File
@@ -0,0 +1,28 @@
package main
import (
"device/arm"
"machine"
)
func main() {
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
// timer fires 10 times per second
arm.SetupSystemTimer(machine.CPU_FREQUENCY / 10)
for {
}
}
var led_state bool
//go:export SysTick_Handler
func timer_isr() {
if led_state {
machine.LED.Low()
} else {
machine.LED.High()
}
led_state = !led_state
}