rp2040: add version check for RP2040-E5

This commit is contained in:
sago35
2022-12-20 09:28:45 +09:00
committed by Ron Evans
parent 762a6f1256
commit 70c94c6d01
2 changed files with 31 additions and 2 deletions
+18
View File
@@ -4,6 +4,7 @@ package machine
import (
"device/rp"
"unsafe"
)
const deviceName = rp.Device
@@ -96,3 +97,20 @@ func CurrentCore() int {
// NumCores returns number of cores available on the device.
func NumCores() int { return 2 }
// ChipVersion returns the version of the chip. 1 is returned for B0 and B1
// chip.
func ChipVersion() uint8 {
const (
SYSINFO_BASE = 0x40000000
SYSINFO_CHIP_ID_OFFSET = 0x00000000
SYSINFO_CHIP_ID_REVISION_BITS = 0xf0000000
SYSINFO_CHIP_ID_REVISION_LSB = 28
)
// First register of sysinfo is chip id
chipID := *(*uint32)(unsafe.Pointer(uintptr(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET)))
// Version 1 == B0/B1
version := (chipID & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB
return uint8(version)
}