-
-
Notifications
You must be signed in to change notification settings - Fork 771
Port NRF Serialization to 2.0 #2393
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
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 can imagine that we might want a map
and mut_map
, but I think in this case you want to use mut_map_or
in order to pass a useful value to userspace. With the current implementation, it's possible userspace passes a smaller buffer than what's received and you'll pass the complete receive length rather than what's copied. This will likely lead userspace to run off the end of the buffer.
Working on this now. |
I've updated this to use I've also updated the libtock-c support to use the new APIS: https://github.com/tock/libtock-c/tree/nrf_serialization_2.0 However, it seems to fail immediately ( |
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 still needs to be tested -- can't get the userspace library working.
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.
Needs testing.
I had to make one change, removing the buffer length from the rx syscall. Otherwise I was able to make this interface work with libtock-c. |
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.
LGTM, I don't think Tock 2.0 requires that apps be able to specify a receive 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.
@@ -244,24 +281,26 @@ impl uart::ReceiveClient for Nrf51822Serialization<'_> { | |||
|
|||
self.active_app.map(|appid| { | |||
let _ = self.apps.enter(*appid, |app, _| { | |||
app.rx_buffer = app.rx_buffer.take().map(|mut rb| { | |||
let len = app.rx_buffer.mut_map_or(0, |rb| { |
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 believe the len
variable and the mut_map_or
and later map_or
are wrong here.
The comment below says Note: This indicates how many bytes were received by hardware, regardless of how much space (if any) was available in the buffer provided by the app.
But with the current code, if the rx_buffer
is missing it will return 0
instead, and if it's too short, the later max_len
will return the app's rx_buffer
length, not the returned hardware length.
I think the fix is simply to remove the len
variable, remove all of the _or
's here, and pass rx_len
in the callback below. I'm not going to push that fix without consensus though, as I think we'd be going back and forth if I did that..
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.
Good point -- then we should pass both. I assume these semantics are there for the peculiarities of the nRF serialization library? I'd therefore recommend this become
app.callback.schedule(4, rx_len, len);
Having implemented a bunch of these capsules, I've come to think that a simple map
is dangerous; the situations in which you want to plug away when there's nothing there is pretty narrow. The API you describe, in which the byte count is the number received by the hardware, rather than what's in the buffer, is fine as long as there is always a buffer (of known length) there. But this map
indicates that there might not be; calling map
prevents you from being able to detect an error case. It might be that we do not want to dig into the nRF code to handle this case right now, but I think it doesn't speak well for the kernel if we make it impossible to handle. map_or
has the advantage that it forces you to think about this -- what if the buffer isn't there?
Fix comment to match implementation of new interface.
…-serialization-2.0
OK, this is now working. Thanks to @bradjc for suggesting to start first with porting the original |
This is great! (Modulo @hudson-ayers's comments) Can we please squash these nine commits and rewrite a single descriptive commit message? They are kind of all over the place and ultimately the changes in the final diff are fairly self contained. Otherwise, I think, good to merge |
Co-authored-by: Hudson Ayers <[email protected]>
…-serialization-2.0
semantics of `subscribe` to no longer issue a read; this requires userspace to issue an additional `command` call to start the read.
…-serialization-2.0
…s the" This reverts commit 342396c.
Ugh. Because I pulled tock-2.0-dev into it back on the 9th, squashing is beyond my git abilities. |
bors r+ |
This is a reconstruction of the commits of GitHub Pull Request tock#2393 [1], given that this pull request introduced commits which reverted merge commits, cluttering the Git history. This includes the following commits, and is based on the raw diff instead: Brad Campbell (1): capsules: nrf-serialization: no recv length Pat Pannuto (1): kernel: add `map` to AppSlice interface nrf51822_serialization: port to 2.0 interface Update capsules/src/nrf51822_serialization.rs Philip Levis (13): Merge branch 'tock-2.0-dev' of github.com:tock/tock into nrf-serialization-2.0 Updating to use map_or to detect proper lengths. Formatting. ble-uart app in libtock-c now works. Merge branch 'nrf-serialization-2.0' of github.com:tock/tock into nrf-serialization-2.0 Update capsules/src/nrf51822_serialization.rs Cut the map methods. Merge branch 'nrf-serialization-2.0' of github.com:tock/tock into nrf-serialization-2.0 Transitions the nRF51 syscall capsule to the 2.0 APIs. Changes the semantics of `subscribe` to no longer issue a read; this requires userspace to issue an additional `command` call to start the read. Merge branch 'nrf-serialization-2.0' of github.com:tock/tock into nrf-serialization-2.0 Revert "Transitions the nRF51 syscall capsule to the 2.0 APIs. Changes the" Revert "Merge branch 'nrf-serialization-2.0' of github.com:tock/tock into nrf-serialization-2.0" Revert "Revert "Merge branch 'nrf-serialization-2.0' of github.com:tock/tock into nrf-serialization-2.0"" Revert "Revert "Transitions the nRF51 syscall capsule to the 2.0 APIs. Changes the"" [1]: tock#2393 Co-authored-by: Pat Pannuto <[email protected]> Co-authored-by: Philip Levis <[email protected]> Co-authored-by: Brad Campbell <[email protected]>
2393: Port NRF Serialization to 2.0 r=phil-levis a=ppannuto This updates the nrf serialization to the 2.0 interface. Tested on imix with the `ble-uart` test application and the nRF BLE sniffer app for an iPhone. The device advertises with an interval of 505ms. Not required, but figuring out why the `ble-uart` application throws an error, code 16835, would be good. The code in master throws this as well, so it's not blocking on this PR. - [x] Updated the relevant files in `/docs`, or no updates are required. - [x] Ran `make prepush`. Co-authored-by: Pat Pannuto <[email protected]> Co-authored-by: Philip Levis <[email protected]> Co-authored-by: Brad Campbell <[email protected]>
Pull Request Overview
This updates the nrf serialization to the 2.0 interface.
Testing Strategy
Tested on imix with the
ble-uart
test application and the nRF BLE sniffer app for an iPhone. The device advertises with an interval of 505ms.TODO or Help Wanted
Not required, but figuring out why the
ble-uart
application throws an error, code 16835, would be good. The code in master throws this as well, so it's not blocking on this PR.Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.