mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
targets: add implementation for Tillitis TKey device (#4631)
* initial implementation for Tillitis TKey device * add UART implementation for TKey * add Pin interface implementation for TKey touch sensor * add RNG interface implementation for TKey * add helpful machine package functions to return identifiers such as name and version for TKey * use built-in timer for sleep timing on TKey * modify UART implementation for TKey to implement Serialer interface * implement BLAKE2s ROM function call for TKey device * handle abort by triggering TKey device fault using illegal instruction to halt CPU * simplify TKey implementation by inheriting from existing riscv32 target * return error for trying to configure invalid baudrates on UART * add tkey to builder test * be very specific for features passed to LLVM for specific config in use for TKey * handle feedback items from TKey device code review Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3)
|
||||
//go:build baremetal && (nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey)
|
||||
|
||||
// If you update the above build constraint, you'll probably also need to update
|
||||
// src/crypto/rand/rand_baremetal.go.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3)
|
||||
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey)
|
||||
|
||||
package runtime
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//go:build tkey
|
||||
|
||||
// This file implements target-specific things for the TKey.
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"device/tkey"
|
||||
"machine"
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export main
|
||||
func main() {
|
||||
preinit()
|
||||
initPeripherals()
|
||||
run()
|
||||
exit(0)
|
||||
}
|
||||
|
||||
// initPeripherals configures peripherals the way the runtime expects them.
|
||||
func initPeripherals() {
|
||||
// prescaler value that results in 0.00001-second timer-ticks.
|
||||
// given an 18 MHz processor, a millisecond is about 18,000 cycles.
|
||||
tkey.TIMER.PRESCALER.Set(18 * machine.MHz / 100000)
|
||||
|
||||
machine.InitSerial()
|
||||
}
|
||||
|
||||
func putchar(c byte) {
|
||||
machine.Serial.WriteByte(c)
|
||||
}
|
||||
|
||||
func getchar() byte {
|
||||
for machine.Serial.Buffered() == 0 {
|
||||
Gosched()
|
||||
}
|
||||
v, _ := machine.Serial.ReadByte()
|
||||
return v
|
||||
}
|
||||
|
||||
func buffered() int {
|
||||
return machine.Serial.Buffered()
|
||||
}
|
||||
|
||||
var timestamp volatile.Register32
|
||||
|
||||
// ticks returns the current value of the timer in ticks.
|
||||
func ticks() timeUnit {
|
||||
return timeUnit(timestamp.Get())
|
||||
}
|
||||
|
||||
// sleepTicks sleeps for at least the duration d.
|
||||
func sleepTicks(d timeUnit) {
|
||||
target := uint32(ticks() + d)
|
||||
|
||||
tkey.TIMER.TIMER.Set(uint32(d))
|
||||
tkey.TIMER.CTRL.SetBits(tkey.TK1_MMIO_TIMER_CTRL_START)
|
||||
for tkey.TIMER.STATUS.Get() != 0 {
|
||||
}
|
||||
timestamp.Set(target)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//go:build tkey && !qemu
|
||||
|
||||
package runtime
|
||||
|
||||
import "device/riscv"
|
||||
|
||||
// ticksToNanoseconds converts ticks (at 18MHz) to 10 µs.
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
return int64(ticks) * 10000
|
||||
}
|
||||
|
||||
// nanosecondsToTicks converts 10 µs to ticks (at 18MHz).
|
||||
func nanosecondsToTicks(ns int64) timeUnit {
|
||||
return timeUnit(ns / 10000)
|
||||
}
|
||||
|
||||
func exit(code int) {
|
||||
abort()
|
||||
}
|
||||
|
||||
func abort() {
|
||||
// Force illegal instruction to halt CPU
|
||||
riscv.Asm("unimp")
|
||||
}
|
||||
Reference in New Issue
Block a user