mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
Add runtime support for the nRF52
This commit is contained in:
@@ -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
|
||||
Submodule
+1
Submodule lib/CMSIS added at 9fe411cef1
Submodule
+1
Submodule lib/nrfx added at c6ba99f45b
@@ -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{}) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,3 +9,5 @@ typedef struct {
|
||||
} string_t;
|
||||
|
||||
typedef int32_t intgo_t; // may be 64-bit
|
||||
|
||||
int main();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void uart_init(uint32_t pin_tx);
|
||||
void uart_send(uint8_t c);
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user