This commit is contained in:
Ayke van Laethem
2018-08-17 23:21:47 +02:00
parent 574c7ec047
commit 62c4c5e90b
19 changed files with 28 additions and 45 deletions
+1
View File
@@ -33,6 +33,7 @@ type __reg uint32
type RegValue = __reg
type __asm string
func Asm(s __asm)
const (
-1
View File
@@ -1,4 +1,3 @@
package main
import (
+1 -2
View File
@@ -1,4 +1,3 @@
package main
type Thing struct {
@@ -84,7 +83,7 @@ func fib(n int) int {
if n <= 2 {
return 1
}
return fib(n - 1) + fib(n - 2)
return fib(n-1) + fib(n-2)
}
func sumrange(n int) int {
-1
View File
@@ -1,4 +1,3 @@
package machine
type GPIOConfig struct {
+1 -2
View File
@@ -1,4 +1,3 @@
// +build avr
package machine
@@ -10,7 +9,7 @@ import (
type GPIOMode uint8
const (
GPIO_INPUT = iota
GPIO_INPUT = iota
GPIO_OUTPUT
)
+1 -2
View File
@@ -1,4 +1,3 @@
// +build !avr,!nrf
package machine
@@ -8,7 +7,7 @@ package machine
type GPIOMode uint8
const (
GPIO_INPUT = iota
GPIO_INPUT = iota
GPIO_OUTPUT
)
-1
View File
@@ -1,4 +1,3 @@
// +build nrf
package machine
-1
View File
@@ -1,4 +1,3 @@
// +build !linux
package runtime
+2 -3
View File
@@ -1,4 +1,3 @@
package runtime
import (
@@ -96,8 +95,8 @@ func printitf(msg interface{}) {
func printptr(ptr uintptr) {
putchar('0')
putchar('x')
for i := 0; i < int(unsafe.Sizeof(ptr)) * 2; i++ {
nibble := byte(ptr >> (unsafe.Sizeof(ptr) * 8 - 4))
for i := 0; i < int(unsafe.Sizeof(ptr))*2; i++ {
nibble := byte(ptr >> (unsafe.Sizeof(ptr)*8 - 4))
if nibble < 10 {
putchar(nibble + '0')
} else {
-1
View File
@@ -1,4 +1,3 @@
package runtime
const Compiler = "tgo"
-1
View File
@@ -1,4 +1,3 @@
// +build avr
package runtime
+9 -8
View File
@@ -1,4 +1,3 @@
// +build nrf
package runtime
@@ -20,16 +19,17 @@ func init() {
}
func initUART() {
nrf.UART0.ENABLE = nrf.UART0_ENABLE_ENABLE_Enabled
nrf.UART0.BAUDRATE = nrf.UART0_BAUDRATE_BAUDRATE_Baud115200
nrf.UART0.ENABLE = nrf.UART0_ENABLE_ENABLE_Enabled
nrf.UART0.BAUDRATE = nrf.UART0_BAUDRATE_BAUDRATE_Baud115200
nrf.UART0.TASKS_STARTTX = 1
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
}
func initLFCLK() {
nrf.CLOCK.LFCLKSRC = nrf.CLOCK_LFCLKSTAT_SRC_Xtal
nrf.CLOCK.TASKS_LFCLKSTART = 1
for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {}
for nrf.CLOCK.EVENTS_LFCLKSTARTED == 0 {
}
nrf.CLOCK.EVENTS_LFCLKSTARTED = 0
}
@@ -41,16 +41,17 @@ func initRTC() {
func putchar(c byte) {
nrf.UART0.TXD = nrf.RegValue(c)
for nrf.UART0.EVENTS_TXDRDY == 0 {}
for nrf.UART0.EVENTS_TXDRDY == 0 {
}
nrf.UART0.EVENTS_TXDRDY = 0
}
func sleep(d Duration) {
ticks64 := d / 32
for ticks64 != 0 {
monotime() // update timestamp
monotime() // update timestamp
ticks := uint32(ticks64) & 0x7fffff // 23 bits (to be on the safe side)
C.rtc_sleep(C.uint32_t(ticks)) // TODO: not accurate (must be d / 30.5175...)
C.rtc_sleep(C.uint32_t(ticks)) // TODO: not accurate (must be d / 30.5175...)
ticks64 -= Duration(ticks)
}
}
+1 -2
View File
@@ -1,4 +1,3 @@
// +build linux
package runtime
@@ -30,7 +29,7 @@ func sleep(d Duration) {
func monotime() uint64 {
var ts C.struct_timespec
C.clock_gettime(C.CLOCK_MONOTONIC, &ts)
return uint64(ts.tv_sec) * 1000 * 1000 + uint64(ts.tv_nsec) / 1000
return uint64(ts.tv_sec)*1000*1000 + uint64(ts.tv_nsec)/1000
}
func abort() {
+1 -2
View File
@@ -1,4 +1,3 @@
package runtime
// This file implements the Go scheduler using coroutines.
@@ -212,7 +211,7 @@ func scheduler(main taskInstance) {
// Add tasks that are done sleeping to the end of the runqueue so they
// will be executed soon.
if sleepQueue != nil && now - sleepQueueBaseTime >= uint64(taskPromise(sleepQueue).data) {
if sleepQueue != nil && now-sleepQueueBaseTime >= uint64(taskPromise(sleepQueue).data) {
scheduleLog(" run <- sleep")
t := sleepQueue
promise := taskPromise(t)
-1
View File
@@ -1,4 +1,3 @@
package runtime
// TODO: use the time package for this.
-1
View File
@@ -1,4 +1,3 @@
package syscall
// dummy
-1
View File
@@ -1,4 +1,3 @@
package unsafe
// dummy