aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitmodules6
m---------lib/CMSIS0
m---------lib/nrfx0
-rw-r--r--src/runtime/nrfx_config.h0
-rw-r--r--src/runtime/nrfx_glue.h0
-rw-r--r--src/runtime/print.go16
-rw-r--r--src/runtime/runtime.go7
-rw-r--r--src/runtime/runtime.h2
-rw-r--r--src/runtime/runtime_nrf.c41
-rw-r--r--src/runtime/runtime_nrf.go23
-rw-r--r--src/runtime/runtime_nrf.h7
-rw-r--r--src/runtime/runtime_unix.go23
-rw-r--r--src/runtime/time.go8
13 files changed, 111 insertions, 22 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..87c3f3a93
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "lib/nrfx"]
+ path = lib/nrfx
+ url = https://github.com/NordicSemiconductor/nrfx.git
+[submodule "lib/CMSIS"]
+ path = lib/CMSIS
+ url = https://github.com/ARM-software/CMSIS.git
diff --git a/lib/CMSIS b/lib/CMSIS
new file mode 160000
+Subproject 9fe411cef1cef5de58e5957b89760759de44e39
diff --git a/lib/nrfx b/lib/nrfx
new file mode 160000
+Subproject c6ba99f45bc24e15bd2198137d2eb8a8fdef250
diff --git a/src/runtime/nrfx_config.h b/src/runtime/nrfx_config.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/runtime/nrfx_config.h
diff --git a/src/runtime/nrfx_glue.h b/src/runtime/nrfx_glue.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/runtime/nrfx_glue.h
diff --git a/src/runtime/print.go b/src/runtime/print.go
index dd60cdef3..75b652923 100644
--- a/src/runtime/print.go
+++ b/src/runtime/print.go
@@ -1,12 +1,9 @@
package runtime
-// #include <stdio.h>
-import "C"
-
func printstring(s string) {
for i := 0; i < len(s); i++ {
- C.putchar(C.int(s[i]))
+ putchar(s[i])
}
}
@@ -17,29 +14,30 @@ func printuint(n uint) {
if prevdigits != 0 {
printuint(prevdigits)
}
- C.putchar(C.int((n % 10) + '0'))
+ putchar(byte((n % 10) + '0'))
}
func printint(n int) {
// Print integer in signed big-endian base-10 notation, for humans to
// read.
if n < 0 {
- C.putchar('-')
+ putchar('-')
n = -n
}
printuint(uint(n))
}
func printbyte(c uint8) {
- C.putchar(C.int(c))
+ putchar(c)
}
func printspace() {
- C.putchar(' ')
+ putchar(' ')
}
func printnl() {
- C.putchar('\n')
+ putchar('\r')
+ putchar('\n')
}
func printitf(msg interface{}) {
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go
index 122ba837b..92d1a2edf 100644
--- a/src/runtime/runtime.go
+++ b/src/runtime/runtime.go
@@ -1,16 +1,13 @@
package runtime
-// #include <stdlib.h>
-import "C"
-
const Compiler = "tgo"
func _panic(message interface{}) {
printstring("panic: ")
printitf(message)
printnl()
- C.exit(1)
+ abort()
}
func boundsCheck(outOfRange bool) {
@@ -18,6 +15,6 @@ func boundsCheck(outOfRange bool) {
// printstring() here is safe as this function is excluded from bounds
// checking.
printstring("panic: runtime error: index out of range\n")
- C.exit(1)
+ abort()
}
}
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index 1f70d6ae4..21ea1ce7b 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -9,3 +9,5 @@ typedef struct {
} string_t;
typedef int32_t intgo_t; // may be 64-bit
+
+int main();
diff --git a/src/runtime/runtime_nrf.c b/src/runtime/runtime_nrf.c
new file mode 100644
index 000000000..7668a0a47
--- /dev/null
+++ b/src/runtime/runtime_nrf.c
@@ -0,0 +1,41 @@
+
+#include "hal/nrf_uart.h"
+#include "nrf.h"
+#include "runtime.h"
+
+void uart_init(uint32_t pin_tx) {
+ NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
+ NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud115200;
+ NRF_UART0->TASKS_STARTTX = 1;
+ NRF_UART0->PSELTXD = 6;
+}
+
+void uart_send(uint8_t c) {
+ NRF_UART0->TXD = c;
+ while (NRF_UART0->EVENTS_TXDRDY != 1) {}
+ NRF_UART0->EVENTS_TXDRDY = 0;
+}
+
+void _start() {
+ uart_init(6); // pin_tx = 6, for NRF52840-DK
+ main();
+}
+
+__attribute__((weak))
+void __aeabi_unwind_cpp_pr0() {
+ // dummy, not actually used
+}
+
+__attribute__((weak))
+void __aeabi_memclr(uint8_t *dest, size_t n) {
+ // TODO: link with compiler-rt for a better implementation.
+ // For now, use a simple memory zeroer.
+ for (size_t i = 0; i < n; i++) {
+ dest[i] = 0;
+ }
+}
+
+__attribute__((weak))
+void __aeabi_memclr4(uint8_t *dest, size_t n) {
+ __aeabi_memclr(dest, n);
+}
diff --git a/src/runtime/runtime_nrf.go b/src/runtime/runtime_nrf.go
new file mode 100644
index 000000000..93d966116
--- /dev/null
+++ b/src/runtime/runtime_nrf.go
@@ -0,0 +1,23 @@
+
+// +build nrf
+
+package runtime
+
+// #include "runtime_nrf.h"
+import "C"
+
+const Microsecond = 1
+
+func putchar(c byte) {
+ C.uart_send(C.uint8_t(c))
+}
+
+func Sleep(d Duration) {
+ // TODO
+}
+
+func abort() {
+ // TODO: wfi
+ for {
+ }
+}
diff --git a/src/runtime/runtime_nrf.h b/src/runtime/runtime_nrf.h
new file mode 100644
index 000000000..79c25806d
--- /dev/null
+++ b/src/runtime/runtime_nrf.h
@@ -0,0 +1,7 @@
+
+#pragma once
+
+#include <stdint.h>
+
+void uart_init(uint32_t pin_tx);
+void uart_send(uint8_t c);
diff --git a/src/runtime/runtime_unix.go b/src/runtime/runtime_unix.go
new file mode 100644
index 000000000..9f9fe9db3
--- /dev/null
+++ b/src/runtime/runtime_unix.go
@@ -0,0 +1,23 @@
+
+// +build linux
+
+package runtime
+
+// #include <stdio.h>
+// #include <stdlib.h>
+// #include <unistd.h>
+import "C"
+
+const Microsecond = 1
+
+func putchar(c byte) {
+ C.putchar(C.int(c))
+}
+
+func Sleep(d Duration) {
+ C.usleep(C.useconds_t(d))
+}
+
+func abort() {
+ C.abort()
+}
diff --git a/src/runtime/time.go b/src/runtime/time.go
index 1043e3f10..86475de7a 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -3,18 +3,10 @@ package runtime
// TODO: use the time package for this.
-// #include <unistd.h>
-import "C"
-
type Duration uint64
// Use microseconds as the smallest time unit
const (
- Microsecond = 1
Millisecond = Microsecond * 1000
Second = Millisecond * 1000
)
-
-func Sleep(d Duration) {
- C.usleep(C.useconds_t(d))
-}