Repository navigation
Conversation
|
|
||
| fn transceivev(ctx: *anyopaque, write_chunks: []const []const u8, read_chunks: []const []u8) (WriteError || ReadError)!void { | ||
| const read_len = chunks_len(read_chunks); | ||
| std.debug.assert(chunks_len(write_chunks) == read_len); |
There was a problem hiding this comment.
Use microzig.assert. We often have to compile in release small, so the regular assert function doesn't give us enough flexibility on when to enable it.
There was a problem hiding this comment.
Thanks! The standalone drivers module has no microzig import configured and runs its own tests independently. Since this is in TestDevice, I replaced the assertion with an error.IoError return before any transfer, so the check stays on in every build mode, and added a length-mismatch test that verifies nothing was sent.
There was a problem hiding this comment.
If that's the case, make an assert function for the driver framework that can be configured and comptime like the microzig assert. Pass down the flag that activates it in MicroBuild so they're enabled at the same time.
There was a problem hiding this comment.
Added drivers.assert with a compile-time asserts flag: it panics on failure in any optimization mode when enabled and does nothing otherwise. MicroBuild forwards each firmware's asserts option, keeping it in sync with microzig.assert. Standalone driver tests enable it with zig build test -Dasserts=true from drivers/.
TestDevice.transceivev now uses it for the length precondition; I removed the test expecting IoError for mismatched lengths.
8b98a62 to
d9e4737
Compare
Adds optional full-duplex transfers to
DatagramDevice, as discussed in #1069 and requested in #637.transceive(src, dst)andtransceivev(write_chunks, read_chunks). Total write/read lengths must match; chunk boundaries may differ. Both returnerror.Unsupportedwhentransceivev_fnis absent.null, preserving existing named-field initializers. The!voidreturn type avoids the AVR issue affecting non-void error-union constants in Zig 0.17.0 (zig#37099).TestDevicesimulates the transfer with write/read, asserts equal total lengths when asserts are enabled, and returnsIoErrorfor a short reply.drivers.assert, controlled by a compile-time flag and able to panic in any optimization mode. MicroBuild forwards each firmware'sassertsoption, keeping it in sync withmicrozig.assert; standalone builds enable it with-Dasserts=true.@hasDeclfor concrete types.No port adapter implements the operation in this PR. I plan to add ATmega328P support in a follow-up for the nRF24L01+ driver, to receive STATUS alongside each command.