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
Spi: Move SPI buffer size into SPI capsule #1744
Conversation
SPI is a rare case where the buffer isn't specified in the capsule for convenience. Move the declarations of read and write buffers into capsule so that the component author will know what the capsule expects.
So this is definitely the fix that #1462 was asking for, but looking at it now I am not sure about the philosophy behind putting buffers in the capsule instead of the component. For capsules where a specific size buffer is required, it makes sense. But the SPI syscall capsule already has machinery to accept different buffer sizes ( If the buffers are in the component, any board wishing to choose a different buffer size can simply forego use of the component and declare its own buffers and initialize the component itself. If the buffers are in the capsule this isn't an option (unless rustc is smart enough to exclude the unused Capsule buffers in this case? either way it is less clear it is an option). |
I think the reason that The RTT capsule recently changed to move the buffer out of the capsule, and instead includes the buffer lengths in the capsule: tock/capsules/src/segger_rtt.rs Lines 101 to 105 in cfa0757
That way the buffer can be created in a component or anywhere else. However, what I think is important is having the "suggested length" specified directly in the capsule as a starting point for board customization. While I agree many capsules will support buffers of any length, the capsule author probably knows what a "reasonable" size is given the use case, or a length that might result in less overhead. I think this should still be recorded in the capsule source directly. If it's recorded at the |
I am in favor of SPI moving to the approach used by the RTT capsule then -- declaring the preferred lengths in the capsule makes a lot of sense, but I think putting the actual buffer in the component (or individual boards |
Thanks for the reviews and detailed discussion. I was wondering then if in this case, should I just go for declaring preferred length in the SPI capsule and then using it in the component as it been done in RTT component? Also, does it makes sense to change the buffer size in Hail - back to 64-byte? [That can also provide an example of how it can be done at individual board level] |
That would be great, thank you.
I think it is fine for Hail to still use the buffer in the component (and stay at the default length specified by the capsule). |
Signed-off-by: Vaishali Thakkar <vthakkar@vaishalithakkar.in>
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.
This looks good! Just one change leftover from the original approach
capsules/src/spi.rs
Outdated
pub static mut SPI_WRITE_BUF: [u8; 1024] = [0; 1024]; | ||
pub static mut SPI_READ_BUF: [u8; 1024] = [0; 1024]; | ||
|
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 should be no need for these buffers now that you have reverted to initializing in the component.
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.
Oops, of course. Sorry, I missed it in this patch while jumping between branches in the local repo. Thanks for notifying.
bors r+ |
This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried. |
Pull Request Overview
This pull request moves the SPI buffer size into capsule from the component, thus addressing the solution for #1462 .
Testing Strategy
This pull request was tested by
make allcheck
andmake allboards
, no device testing.TODO or Help Wanted
Should be fine.
Documentation Updated
/docs
, or no updates are required.Formatting
make formatall
.