How can I access memory-mapped GPIO registers with golang on Windows?

129 views Asked by At

I am working with a piece of harware, that addresses LEDs through GPIOs accessible only through memory-mapped IO (mmio registers). On Linux, I managed to set the values pretty simple, by opening the documented address through /dev/mem:

var err error
mem, err = os.OpenFile("/dev/mem", os.O_RDWR|os.O_SYNC, 0644)
if err != nil {
    log.Fatalf("could not initialize GPIO memory mapping")
}
_, err := mem.WriteAt(colorMap[ledColor], gpioPadBar + ledMap[pow])
if err != nil {
    log.Fatal(err)
}

This works pretty well on linux, but as there is no /dev/mem available on Windows to open, I am currently stuck on approaching the same results.

As I could not find anything on the internet (it does not help that MMIO is always pointing to File-MMIO in Windows context and the Windows-API bindings are only little documented), I tried to access the memory area directly:

func mmioWrite(offset int64, val byte) {
    *((*byte)(unsafe.Pointer(uintptr(gpioPadBar + offset)))) = val
}
...
mmioWrite(colorMap[ledColor], ledMap[pow])

I executed it as administrator (as I am clearly requesting a kernel-managed resource), but it crashed showing this error.

The "error address" (0xD0C506A0) is the correctly calculated MMIO GPIO address I wanted to access.

My questions are:

  • Is there a low-level possibility to get MMIO-Register access on Windows?
  • If not: Is there a Windows API to perform this task?

Thank you very much, Mathias

0

There are 0 answers