all: use less magic in memory-mapped IO

Don't store addresses in the values of registers, this leads to problems
with char arrays (among others). Instead, do it like it's done in C with
raw addresses cast to struct pointers.

This commit also splits gen-device.py, as AVR and ARM have very
different ideas of what a register is. It's easier to just keep them
separate.
This commit is contained in:
Ayke van Laethem
2018-09-05 11:29:15 +02:00
parent 93248c93ed
commit 17b5b6ec5b
7 changed files with 296 additions and 209 deletions
+8 -13
View File
@@ -29,6 +29,10 @@
// POSSIBILITY OF SUCH DAMAGE.
package arm
import (
"unsafe"
)
type __reg uint32
type RegValue = __reg
@@ -42,22 +46,13 @@ const (
)
// Nested Vectored Interrupt Controller (NVIC).
var NVIC = struct {
type NVIC_Type struct {
ISER [8]__reg
}{
ISER: [8]__reg{
NVIC_BASE + 0x000,
NVIC_BASE + 0x004,
NVIC_BASE + 0x008,
NVIC_BASE + 0x00C,
NVIC_BASE + 0x010,
NVIC_BASE + 0x014,
NVIC_BASE + 0x018,
NVIC_BASE + 0x01C,
},
}
var NVIC = (*NVIC_Type)(unsafe.Pointer(uintptr(NVIC_BASE)))
// Enable the given interrupt number.
func EnableIRQ(irq uint32) {
NVIC.ISER[irq >> 5] = 1 << (irq & 0x1F)
NVIC.ISER[irq>>5] = 1 << (irq & 0x1F)
}