Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ppannuto
Copy link
Member

@ppannuto ppannuto commented Jan 29, 2021

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

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@bradjc bradjc added the tock-2.0 Issues and PRs related to Tock version 2.0. label Jan 29, 2021
Copy link
Contributor

@phil-levis phil-levis left a 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.

@phil-levis
Copy link
Contributor

Working on this now.

@phil-levis
Copy link
Contributor

I've updated this to use mut_map_or and pass lengths properly back to userspace.

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 (simple_ble_init returns an error), and this occurs when registering a handler through SOFTDEVICE_HANDLER_INIT. I'd appreciate it if someone who is at last familiar with the NRF softdevices takes a look.

@phil-levis phil-levis marked this pull request as ready for review February 10, 2021 04:24
phil-levis
phil-levis previously approved these changes Feb 10, 2021
Copy link
Contributor

@phil-levis phil-levis left a 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.

Copy link
Contributor

@phil-levis phil-levis left a comment

Choose a reason for hiding this comment

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

Needs testing.

@phil-levis phil-levis dismissed their stale review February 10, 2021 04:29

Should just be a comment.

@bradjc
Copy link
Contributor

bradjc commented Feb 12, 2021

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.

Copy link
Contributor

@hudson-ayers hudson-ayers left a 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

Copy link
Member Author

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

image

Okay github.

@@ -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| {
Copy link
Member Author

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..

Copy link
Contributor

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?

@phil-levis
Copy link
Contributor

phil-levis commented Feb 14, 2021

OK, this is now working. Thanks to @bradjc for suggesting to start first with porting the original subscribe-based reading API then transition it to using command to be in line with 2.0 semantics.

@alevy
Copy link
Member

alevy commented Feb 15, 2021

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

@github-actions github-actions bot removed the kernel label Feb 15, 2021
semantics of `subscribe` to no longer issue a read; this requires
userspace to issue an additional `command` call to start the read.
…into nrf-serialization-2.0"

This reverts commit 1ffd5de, reversing
changes made to f9a79bf.
@github-actions github-actions bot added kernel chips/sam4l Change pertains to the SAM4L MCU. tock-libraries This affects libraries supported by the Tock project WG-OpenTitan In the purview of the OpenTitan working group. labels Feb 15, 2021
@github-actions github-actions bot removed WG-OpenTitan In the purview of the OpenTitan working group. kernel tock-libraries This affects libraries supported by the Tock project chips/sam4l Change pertains to the SAM4L MCU. labels Feb 15, 2021
@phil-levis
Copy link
Contributor

phil-levis commented Feb 15, 2021

Ugh. Because I pulled tock-2.0-dev into it back on the 9th, squashing is beyond my git abilities.

@phil-levis
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 15, 2021

@bors bors bot merged commit bc69582 into tock-2.0-dev Feb 15, 2021
@bors bors bot deleted the nrf-serialization-2.0 branch February 15, 2021 07:08
lschuermann added a commit to lschuermann/tock that referenced this pull request Mar 22, 2021
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]>
lschuermann pushed a commit to lschuermann/tock that referenced this pull request Mar 22, 2021
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]>
@lschuermann lschuermann mentioned this pull request Mar 22, 2021
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tock-2.0 Issues and PRs related to Tock version 2.0.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants