Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions port/raspberrypi/rp2xxx/src/hal/uart.zig
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ pub const UART = enum(u1) {
.deadline = deadline,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question that popped up when using the interfaces. Is this deadline correct? It's initialised when instantiating the Reader struct, but at least for the RP2040 I'm creating these deadlines with time.deadline_in_ms() which simply adds the argument with the current time to define an absolute timestamp when the deadline elapses.

Now, given the deadline's instantiated at the very beginning and never recreated it basically becomes a no-op as it's always elapsed later down the road.

Would it make sense to instead of passing an instantiated mdf.time.Deadline pass an integer (i.e. deadline_ms) to instantiate the deadline whenever we make a call such as a in stream()?

Maybe I'm just using the API wrong...

Should this be an error I'd be more than happy to provide a separate PR handling this as it affects both the Reader and Writer.

Thanks a ton for your time.

.interface = .{
.buffer = buffer,
.seek = 0,
.end = 0,
.vtable = &.{
.stream = stream,
},
Expand Down Expand Up @@ -206,21 +208,15 @@ pub const UART = enum(u1) {
return n;
}

fn stream(io_reader: *std.Io.Reader, w: *std.Io.Writer, limit: std.Io.Limit) std.Io.Reader.StreamError!usize {
const r: *Reader = @fieldParentPtr("interface", io_reader);
fn stream(r: *std.Io.Reader, w: *std.Io.Writer, limit: std.Io.Limit) std.Io.Reader.StreamError!usize {
const uart_reader: *Reader = @alignCast(@fieldParentPtr("interface", r));
const uart = uart_reader.uart;
return switch (limit) {
.nothing => 0,
else => blk: {
var buf: [1]u8 = undefined;
const n = r.uart.read_blocking(&buf, null) catch |err| switch (err) {
error.ReceiveError => return error.ReadError,
};

break :blk switch (n) {
0 => 0,
1 => try w.writeByte(buf[0]),
else => unreachable,
};
else => {
const b = uart.read_word_blocking(uart_reader.deadline) catch return error.ReadFailed;
try w.writeByte(b);
return 1;
},
};
}
Expand Down
Loading