mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
maixbit: support both GPIO and GPIOHS controllers
This commit is contained in:
@@ -99,8 +99,11 @@ func handleInterrupt() {
|
||||
|
||||
// initPeripherals configures periperhals the way the runtime expects them.
|
||||
func initPeripherals() {
|
||||
// Enable APB0 clock.
|
||||
kendryte.SYSCTL.CLK_EN_CENT.SetBits(kendryte.SYSCTL_CLK_EN_CENT_APB0_CLK_EN)
|
||||
|
||||
machine.FPIOA0.Init()
|
||||
// Enable FPIOA peripheral.
|
||||
kendryte.SYSCTL.CLK_EN_PERI.SetBits(kendryte.SYSCTL_CLK_EN_PERI_FPIOA_CLK_EN)
|
||||
|
||||
machine.UART0.Configure(machine.UARTConfig{})
|
||||
}
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"device/kendryte"
|
||||
"device/riscv"
|
||||
)
|
||||
|
||||
var clockFrequency int64 = int64(kendryte.SYSCTL.CLK_FREQ.Get())
|
||||
|
||||
// ticksToNanoseconds converts RTC ticks to nanoseconds.
|
||||
// ticksToNanoseconds converts CPU ticks to nanoseconds.
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
return int64(ticks) * 1e9 / clockFrequency
|
||||
// The following calculation is actually the following, but with both sides
|
||||
// reduced to reduce the risk of overflow:
|
||||
// ticks * 1e9 / (390000000 / 50)
|
||||
// 50 is the CLINT divider and 390000000 is the CPU frequency.
|
||||
return int64(ticks) * 5000 / 39
|
||||
}
|
||||
|
||||
// nanosecondsToTicks converts nanoseconds to RTC ticks.
|
||||
// nanosecondsToTicks converts nanoseconds to CPU ticks.
|
||||
func nanosecondsToTicks(ns int64) timeUnit {
|
||||
return timeUnit(ns * 64 / 1953125)
|
||||
return timeUnit(ns * 39 / 5000)
|
||||
}
|
||||
|
||||
func abort() {
|
||||
|
||||
Reference in New Issue
Block a user