Add runtime support for the nRF52

Этот коммит содержится в:
Ayke van Laethem 2018-04-25 20:06:08 +02:00
родитель e80f06bc5e
коммит 04fef19753
13 изменённых файлов: 113 добавлений и 22 удалений

6
.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

1
lib/CMSIS Подмодуль

@ -0,0 +1 @@
Subproject commit 9fe411cef1cef5de58e5957b89760759de44e393

1
lib/nrfx Подмодуль

@ -0,0 +1 @@
Subproject commit c6ba99f45bc24e15bd2198137d2eb8a8fdef250c

0
src/runtime/nrfx_config.h Обычный файл
Просмотреть файл

0
src/runtime/nrfx_glue.h Обычный файл
Просмотреть файл

Просмотреть файл

@ -1,12 +1,9 @@
package runtime package runtime
// #include <stdio.h>
import "C"
func printstring(s string) { func printstring(s string) {
for i := 0; i < len(s); i++ { 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 { if prevdigits != 0 {
printuint(prevdigits) printuint(prevdigits)
} }
C.putchar(C.int((n % 10) + '0')) putchar(byte((n % 10) + '0'))
} }
func printint(n int) { func printint(n int) {
// Print integer in signed big-endian base-10 notation, for humans to // Print integer in signed big-endian base-10 notation, for humans to
// read. // read.
if n < 0 { if n < 0 {
C.putchar('-') putchar('-')
n = -n n = -n
} }
printuint(uint(n)) printuint(uint(n))
} }
func printbyte(c uint8) { func printbyte(c uint8) {
C.putchar(C.int(c)) putchar(c)
} }
func printspace() { func printspace() {
C.putchar(' ') putchar(' ')
} }
func printnl() { func printnl() {
C.putchar('\n') putchar('\r')
putchar('\n')
} }
func printitf(msg interface{}) { func printitf(msg interface{}) {

Просмотреть файл

@ -1,16 +1,13 @@
package runtime package runtime
// #include <stdlib.h>
import "C"
const Compiler = "tgo" const Compiler = "tgo"
func _panic(message interface{}) { func _panic(message interface{}) {
printstring("panic: ") printstring("panic: ")
printitf(message) printitf(message)
printnl() printnl()
C.exit(1) abort()
} }
func boundsCheck(outOfRange bool) { func boundsCheck(outOfRange bool) {
@ -18,6 +15,6 @@ func boundsCheck(outOfRange bool) {
// printstring() here is safe as this function is excluded from bounds // printstring() here is safe as this function is excluded from bounds
// checking. // checking.
printstring("panic: runtime error: index out of range\n") printstring("panic: runtime error: index out of range\n")
C.exit(1) abort()
} }
} }

Просмотреть файл

@ -9,3 +9,5 @@ typedef struct {
} string_t; } string_t;
typedef int32_t intgo_t; // may be 64-bit typedef int32_t intgo_t; // may be 64-bit
int main();

41
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);
}

23
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 {
}
}

7
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);

23
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()
}

Просмотреть файл

@ -3,18 +3,10 @@ package runtime
// TODO: use the time package for this. // TODO: use the time package for this.
// #include <unistd.h>
import "C"
type Duration uint64 type Duration uint64
// Use microseconds as the smallest time unit // Use microseconds as the smallest time unit
const ( const (
Microsecond = 1
Millisecond = Microsecond * 1000 Millisecond = Microsecond * 1000
Second = Millisecond * 1000 Second = Millisecond * 1000
) )
func Sleep(d Duration) {
C.usleep(C.useconds_t(d))
}