-
Notifications
You must be signed in to change notification settings - Fork 747
Switch SPI master HIL to leasable buffers instead of raw slices #4173
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
Conversation
Migrates SPI HIL to leasable buffers (SubSliceMut) rather than raw slices, in accordance with the draft SPI TRD
696dd29
to
cd411b4
Compare
status: Result<(), ErrorCode>, | ||
write_buffer: SubSliceMut<'static, u8>, | ||
read_buffer: Option<SubSliceMut<'static, u8>>, | ||
status: Result<usize, ErrorCode>, |
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.
What is the usize
?
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.
Length
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.
Can you update the comment?
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.
done
@tock/core-wg note last call on this |
This breaks SPI on the Apollo3 |
self.spi_master | ||
.read_write_bytes(self.kernel_write.take().unwrap(), None, write_len) | ||
let kwbuf = self | ||
.kernel_write | ||
.take() | ||
.unwrap_or((&mut [] as &'static mut [u8]).into()); | ||
self.spi_master.read_write_bytes(kwbuf, None) |
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.
What happens to write_len
here? It seems like it's being lost
let kwbuf = self | ||
.kernel_write | ||
.take() | ||
.unwrap_or((&mut [] as &'static mut [u8]).into()); | ||
self.spi_master | ||
.read_write_bytes(kwbuf, self.kernel_read.take()) |
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.
Same with read_len
here.
Userspace might use a single large buffer, but want to do smaller SPI operations at times. It seems like that might be broken now
self.spi_master.read_write_bytes( | ||
self.kernel_write.take().unwrap(), | ||
self.kernel_read.take(), | ||
write_len, | ||
) | ||
let kwbuf = self | ||
.kernel_write | ||
.take() | ||
.unwrap_or((&mut [] as &'static mut [u8]).into()); | ||
self.spi_master | ||
.read_write_bytes(kwbuf, self.kernel_read.take()) |
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.
Same with write_len
here
@alevy ping! |
tock#4173 broke userspace SPI operations as the length of the operation that the application requested was ignored see [1] and [2]. This commit fixes SPI operations by ensuring that we only write the data requested by the application, not just the entire buffer. 1: https://github.com/tock/tock/pull/4173/files#r1783773610 2: https://github.com/tock/tock/pull/4173/files#r1783774331 Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
tock#4173 drops the length specified by the application for read only operations. This commit fixes the read buffer length before calling the SPI operation. Signed-off-by: Alistair Francis <alistair@alistair23.me>
Pull Request Overview
This pull request migrates the SPI master HIL to use leasable buffers (SubSliceMut) rather than raw
slices, in accordance with the draft SPI TRD. As a result, this touches every module that either implements or uses the SPI master HIL, as well as a some dependencies in some cases (e.g. DMA modules).
While it is mostly a mechanical transformation aided by some additional helper methods in leasable buffers, the length parameter, is notably, redundant for both the
read_write_bytes
downcall and client callback, which requires adapting some of the length computations in various implementations. In cases where the implementation is shared with other HIL implementations that have not migrated toSubSliceMut
there is some ultimately unnecessary complexity.Testing Strategy
This touches many chips and thus almost every board as well as a few capsules for peripherals I don't have currently access to. The shared code is fairly straight forward, but the devil is mostly going to be in specific chip implementations.
I've tested on an NRF52-based platform with a SPI peripheral, but that's it for now.
TODO or Help Wanted
SubSliceMut
s in capsules... kind of everywhere?write_buffer
also be anOption
?Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.