-
Notifications
You must be signed in to change notification settings - Fork 3k
NRF5x: rationalise sleep+critical #9358
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
This effectively completely replaces the sleep and critical code, and is kind of a "best-of" the various implementations around, with some of my own special sauce. First draft, untested, but I want feedback. I'm not clear how the SDK and glue stuff in FEATURE_BLE relates to the rest of the tree - I can't see they co-exist, so I've just deleted the "hal_patch" directory from there for now, and I'm assuming we're using either SDK11 or SDK14 from the targets directory. One small "adaptation" header put in to cover up API differences between the SDKs. I think we might have a problem in that the SoftDevice event wait API is unclear on whether it's a "WFE" or "WFI", and implementation may be too. I've added notes on how it might work for both purposes. But this PR doesn't change that mode - only the SoftDevice-disabled mode. |
@kjbracey-arm, thank you for your changes. |
// Will likely recurse, as assert failure will try to take critical region | ||
MBED_ASSERT(sd_result == NRF_SUCCESS); | ||
#else | ||
(void) sd_nvic_critical_region_enter(&nested); |
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 function is not defined when softdevice is included.
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.
When it is not included, you mean?
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 it ever not be included? Is there not SOFTDEVICE_NONE
, at minimum, which gives us a stubbed implementation of that? (Not that it should ever be used, as mbed_softdevice_is_enabled
will be a constant false in that case).
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.
Yes, I made more investigation and the definition is not included on NRF52840_DK. When the soft device is on, the definition is in nrf_nvic.h
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.
So could we turn on SDK14_2, NORDIC_SOFTDEVICE and SOFTDEVICE_NONE for that? Would that make sense?
uint32_t sd_result = sd_nvic_critical_region_exit(!critical_interrupts_enabled); | ||
MBED_ASSERT(sd_result == NRF_SUCCESS); | ||
#else | ||
(void) sd_nvic_critical_region_exit(!critical_interrupts_enabled); |
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 function is not defined when softdevice is included.
Please rebase your PR. A fix for the |
Besides rebase to resolve travis failures (there was another tool breakage), needs reviews ! |
This follows up from previous closed PRs ARMmbed#8366 and ARMmbed#9211, in an attempt to fix the issue originally reported as ARMmbed#5647. As discussed in those PRs, the sleep behaviour of the NRF5x family is apparently unsafe, at least for the cases where the SoftDevice is disabled. This commit fixes it up by: * Collapsing down to 1 implementation, from 3. * Using standard PRIMASK disable when SoftDevice is disabled. * Using standard WFI when SoftDevice is disabled. This commit shouldn't change the functionality for when it is enabled - it retains the "SEVONPEND" and "FPU pending" fudges. If SoftDevice is enabled, we continue to hope that its sd_app_evt_wait() call does the Right Thing(TM). However, this seems unlikely, as documentation and the "nosd" stubs visible suggests they just do a "WFE", when we are looking for a "WFI" equivalent. Or it's possible their real implementation does the unsafe and racy "SEV; WFE; WFE;" sequence. Comments added to clarify what we are hoping for from SoftDevice.
Will also need to coordinate with #9019 - that no doubt will affect this. Seems like it might be increasing the number of HW/SDK/how-to-drive-it permutations further :/ |
The update went in to the feature branch , anything to do there? This still needs reviews |
@0xc0170 As this was still under review it was not brought into the nrf52-sdk15 feature branch. What level of testing has been performed on this? |
This is still at discussion stage - this is a proposal, and I was awaiting feedback and answers to some questions above. Particularly:
I will no doubt need to update this for SDK15, but not sure how to co-ordinate that if you're on a feature branch. Haven't looked at it yet, so I don't know how it changes anything. There should be a follow-up discussion about how |
@kjbracey-arm Any progress? |
@kjbracey-arm
I'm not sure what functions you are referring to, but yes building for SOFTDEVICE_NONE doesn't kill the SDK - it prevents the SoftDevice and MBR from being built into the final image. Some helper utility functions are located here for SOFTDEVICE_NONE: I just checked your branch and it doesn't yet build for SOFTDEVICE_NONE.
Not sure - perhaps @desmond-blue knows? |
@TacoGrandeTX |
@kjbracey-arm @ARMmbed/mbed-os-pan Any thoughts on how to progress this PR? |
@kjbracey-arm @ARMmbed/mbed-os-pan ^^^ |
Test run: FAILEDSummary: 3 of 7 test jobs failed Failed test jobs:
|
@kjbracey-arm as this has seen no update for 29 days I am closing this. Please re-open once there are any new changes. |
Description
This follows up from previous closed PRs #8366 and #9211, in an attempt to fix the issue originally reported as #5647.
As discussed in those PRs, the sleep behaviour of the NRF5x family is apparently unsafe, at least for the cases where the SoftDevice is disabled.
This commit fixes it up by:
This commit shouldn't change the functionality for when it is enabled - it retains the "SEVONPEND" and "FPU pending" fudges.
If SoftDevice is enabled, we continue to hope that its sd_app_evt_wait() call does the Right Thing(TM). However, this seems unlikely, as documentation and the "nosd" stubs visible suggests they just do a
"WFE", when we are looking for a "WFI" equivalent. Or it's possible their real implementation does the unsafe and racy "SEV; WFE; WFE;" sequence.
Comments added to clarify what we are hoping for from SoftDevice.
Pull request type
Reviewers
@TacoGrandeTX, @deepikabhavnani, @pan-, @marcuschangarm, @scartmell-arm