maixbit: support both GPIO and GPIOHS controllers

This commit is contained in:
Yannis Huber
2020-06-19 17:35:36 +02:00
committed by Ron Evans
parent 804dc8b1f9
commit 53c83fa445
4 changed files with 104 additions and 290 deletions
+4 -1
View File
@@ -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{})
}
+8 -7
View File
@@ -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() {