Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 committed Mar 10, 2022
1 parent 556d7f1 commit 1c5d5a8
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/os/file_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package os

import (
"machine"
_ "unsafe"
)

Expand Down Expand Up @@ -42,7 +41,18 @@ func NewFile(fd uintptr, name string) *File {
// Read reads up to len(b) bytes from machine.Serial.
// It returns the number of bytes read and any error encountered.
func (f stdioFileHandle) Read(b []byte) (n int, err error) {
return machine.Serial.Read(b)
size := 0
for size == 0 {
size = buffered()
}

if size > len(b) {
size = len(b)
}
for i := 0; i < size; i++ {
b[i] = getchar()
}
return size, nil
}

func (f stdioFileHandle) ReadAt(b []byte, off int64) (n int, err error) {
Expand Down Expand Up @@ -76,6 +86,12 @@ func (f stdioFileHandle) Seek(offset int64, whence int) (int64, error) {
//go:linkname putchar runtime.putchar
func putchar(c byte)

//go:linkname getchar runtime.getchar
func getchar() byte

//go:linkname buffered runtime.buffered
func buffered() int

func Pipe() (r *File, w *File, err error) {
return nil, nil, ErrNotImplemented
}
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime_arm7tdmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ func putchar(c byte) {
// dummy, TODO
}

func getchar() byte {
// dummy, TODO
return 0
}

func buffered() int {
// dummy, TODO
return 0
}

//go:extern _sbss
var _sbss [0]byte

Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_atmega.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

// Sleep for a given period. The period is defined by the WDT peripheral, and is
// on most chips (at least) 3 bits wide, in powers of two from 16ms to 2s
// (0=16ms, 1=32ms, 2=64ms...). Note that the WDT is not very accurate: it can
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_atsamd21.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initClocks() {
// Set 1 Flash Wait State for 48MHz, required for 3.3V operation according to SAMD21 Datasheet
sam.NVMCTRL.CTRLB.SetBits(sam.NVMCTRL_CTRLB_RWS_HALF << sam.NVMCTRL_CTRLB_RWS_Pos)
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_atsamd51.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initClocks() {
// set flash wait state
sam.NVMCTRL.CTRLA.SetBits(0 << sam.NVMCTRL_CTRLA_RWS_Pos)
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime_attiny.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ func putchar(c byte) {
// UART is not supported.
}

func getchar() byte {
// UART is not supported.
return 0
}

func buffered() int {
// UART is not supported.
return 0
}

func sleepWDT(period uint8) {
// TODO: use the watchdog timer instead of a busy loop.
for i := 0x45; i != 0; i-- {
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime_cortexm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func putchar(c byte) {
stdoutWrite.Set(uint8(c))
}

func getchar() byte {
// dummy, TODO
return 0
}

func buffered() int {
// dummy, TODO
return 0
}

func waitForEvents() {
arm.Asm("wfe")
}
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_esp32xx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

// Initialize .bss: zero-initialized global variables.
// The .data section has already been loaded by the ROM bootloader.
func clearbss() {
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_esp8266.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

// Write to the internal control bus (using I2C?).
// Signature found here:
// https://github.com/espressif/ESP8266_RTOS_SDK/blob/14171de0/components/esp8266/include/esp8266/rom_functions.h#L54
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_fe310.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

var timerWakeup volatile.Register8

func ticks() timeUnit {
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_k210.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

var timerWakeup volatile.Register8

func ticks() timeUnit {
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_mimxrt1062.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.UART1.Buffered() == 0 {
}
v, _ := machine.UART1.ReadByte()
return v
}

func buffered() int {
return machine.UART1.Buffered()
}

func exit(code int) {
abort()
}
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_nrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func sleepTicks(d timeUnit) {
for d != 0 {
ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime_nxpmk66f18.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ func putchar(c byte) {
machine.PutcharUART(machine.UART0, c)
}

func getchar() byte {
// dummy, TODO
return 0
}

func buffered() int {
// dummy, TODO
return 0
}

func exit(code int) {
abort()
}
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

// machineInit is provided by package machine.
func machineInit()

Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32f103.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

// initCLK sets clock to 72MHz using HSE 8MHz crystal w/ PLL X 9 (8MHz x 9 = 72MHz).
func initCLK() {
stm32.FLASH.ACR.SetBits(stm32.FLASH_ACR_LATENCY_WS2) // Two wait states, per datasheet
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32f4.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initCLK() {
// Reset clock registers
// Set HSION
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32f405.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,14 @@ func initCOM() {
func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32f7x2.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initCLK() {
// PWR_CLK_ENABLE
stm32.RCC.APB1ENR.SetBits(stm32.RCC_APB1ENR_PWREN)
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32l0.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initCLK() {
// Set Power Regulator to enable max performance (1.8V)
stm32.PWR.CR.ReplaceBits(1<<stm32.PWR_CR_VOS_Pos, stm32.PWR_CR_VOS_Msk, 0)
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime_stm32l4.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ func putchar(c byte) {
machine.Serial.WriteByte(c)
}

func getchar() byte {
for machine.Serial.Buffered() == 0 {
}
v, _ := machine.Serial.ReadByte()
return v
}

func buffered() int {
return machine.Serial.Buffered()
}

func initCLK() {
// PWR_CLK_ENABLE
stm32.RCC.APB1ENR1.SetBits(stm32.RCC_APB1ENR1_PWREN)
Expand Down
Loading

0 comments on commit 1c5d5a8

Please sign in to comment.