-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os, runtime: enable os.Stdin for baremetal target #2625
Conversation
src/os/file_other.go
Outdated
@@ -38,7 +39,7 @@ func NewFile(fd FileHandle, name string) *File { | |||
|
|||
// Read is unsupported on this system. | |||
func (f stdioFileHandle) Read(b []byte) (n int, err error) { | |||
return 0, ErrUnsupported | |||
return machine.Serial.Read(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to change here without changing uart.go and usb.go.
I think it would be better to call runtime.Gosched(), but it can't be called from the machine package.
func (f stdioFileHandle) Read(b []byte) (n int, err error) {
size := 0
for size == 0 {
size = machine.Serial.Buffered()
runtime.Gosched()
}
return machine.Serial.Read(b)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this proposal is much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like CI fail here https://github.com/tinygo-org/tinygo/runs/5110984825?check_suite_focus=true#step:17:492 |
@sago35 if I read this correctly, it makes UART blocking on read whereas it was non-blocking before. I can see this breaking existing code. it would be better to put the blocking behaviour outside of UART implementation? |
@kenbell |
If we do not change uart or usbcdc, but only os.Stdin, the following problem occurs. // It works as expected.
scanner := bufio.NewScanner(os.Stdin) // Not working as expected.
scanner := bufio.NewScanner(machine.Serial) |
40af7f2
to
170ba92
Compare
49f4f50
to
1c5d5a8
Compare
@kenbell @deadprogram |
e19531f
to
3c9db4a
Compare
This PR only adds os.Stdin, so there are no compatibility-breaking changes. |
@kenbell @deadprogram With this PR, the following code will work in both standard Go and tinygo-baremetal. |
After a cursory review, I don't see any potential blockers with respect to the USB 2.0 package. But I'm still a little confused as to what we gain with this capability. Is this to create a type-safe, consistent IO interface? As opposed to the awkward juggling we are currently doing with |
What we get with this PR is support for
old : Lines 41 to 48 in 486b999
|
Any other feedback or comments before we merge this? |
Merging in order to keep this process with improvements for serial/USB communication moving along. Thanks @sago35 |
This PR enables os.Stdin for the baremetal target.
There are two items that need to be discussed and agreement.
Can an os package import a machine package?There are changes that will break compatibilityI've changedsrc/machine/uart.go
andsrc/machine/usb.go
, and the behavior changes significantly.bufio.Scanner.Scan()
will not work without this change (error message ismultiple Read calls return no data or error
)