Skip to content
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

Platform: Add sleep/deepsleep user facing functions #3607

Merged
merged 4 commits into from
Jan 26, 2017
Merged

Conversation

bulislaw
Copy link
Member

Add sleep/deepsleep functions to platform layer which are replacing HAL
functions with the same name, rename existing symbols in HAL layer
to hal_sleep/hal_deepsleep. This way sleep functions
are always available, even if target doesn't implement them, which makes
the code using sleep clearer. It also enables us to make decision on in
which builds (debug/release) the sleep will be enabled.

Status

READY

Related PRs

#3566

CC: @0xc0170 @sg- @betzw

@bridadan
Copy link
Contributor

@bulislaw This seems a bit misleading to me, though I may not understand all the implications of this. Without this patch if I call sleep and the target doesn't implement it, I'll get a compiler error with an undefined function. This gives me at least an indication that the target doesn't support it.

Perhaps we could add a #warning or #error in the case where the target doesn't support sleep or it's using NDEBUG? That way the user has some indication that the target isn't actually sleeping?

__INLINE void sleep(void)
{
#ifdef NDEBUG
#ifdef DEVICE_SLEEP
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe #if DEVICE_SLEEP is slightly better as more inline with other usages of this macro.

__INLINE void deepsleep(void)
{
#ifdef NDEBUG
#ifdef DEVICE_SLEEP
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe #if DEVICE_SLEEP is slightly better as more inline with other usages of this macro.

@betzw
Copy link
Contributor

betzw commented Jan 19, 2017

Does this mean that I should remove the #if DEVICE_SLEEP from PR #3566?!?

@bulislaw
Copy link
Member Author

@bridadan

@bulislaw This seems a bit misleading to me, though I may not understand all the implications of this. Without this patch if I call sleep and the target doesn't implement it, I'll get a compiler error with an undefined function. This gives me at least an indication that the target doesn't support it.

That was partially my point, I think usage of sleep shouldn't be surrounded in flag checking which is pointless. Also going to sleep it's an optimization rather then an functional action. I was wondering on adding a bool return value that indicates if the platform actually went to sleep, but decided that it's not like user can do anything useful with that.

Perhaps we could add a #warning or #error in the case where the target doesn't support sleep or it's using NDEBUG? That way the user has some indication that the target isn't actually sleeping?

Yeah I guess #warning would be good.

@betzw

Does this mean that I should remove the #if DEVICE_SLEEP from PR #3566?!?

Yeah no need to have it twice. I'll replace #ifdef with #if according to your comments.

Add sleep/deepsleep functions to platform layer which are replacing HAL
functions with the same name, rename existing symbols in HAL layer
to hal_sleep/hal_deepsleep. This way sleep functions
are always available, even if target doesn't implement them, which makes
the code using sleep clearer. It also enables us to make decision on in
which builds (debug/release) the sleep will be enabled.
@bulislaw bulislaw requested a review from 0xc0170 January 19, 2017 10:24
@bulislaw
Copy link
Member Author

@0xc0170 please review.

{
// ensure debug is disconnected if semihost is enabled....
NRF_POWER->TASKS_LOWPWR = 1;
// wait for interrupt
__WFE();
}

MBED_WEAK void deepsleep(void)
MBED_WEAK void hal_deepsleep(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to remove weak linkage, as it's not applied to any other implementations.

* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
__INLINE void sleep(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

functions in these header should be defined with static specifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why static?

#warning Sleep is not supported on this platform.
#else /* DEVICE_SLEEP */
#ifndef NDEBUG
#warning Sleep is disabled for debug builds.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this warning active by default (default profile)? means if I use mbed compile -m K64F -t GCC_ARM I would get always this warning? If that's the case, I would comment out this code straight away just to remove this annoyance.

As I recall only small-build defines NDEBUG symbol. Is default profile debug build?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not like our builds are clean of warnings. And yes default build is debug, which is probably the correct behavior for mbed-os. So you think that the documentation note (which i will submit separately to the handbook) is enough of a info?

@bulislaw
Copy link
Member Author

To summarize our discussion and changes :

  • Warnings removed as they will be distracting in the default profiles
  • static added to sleep functions
  • MBED_WEAK removed from NRF51
  • Profiles will be rethink and renamed in near future.

@bulislaw
Copy link
Member Author

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1429

All builds and test passed!

@bridadan
Copy link
Contributor

I'm actually going to suggest we run a full nightly on this, just because there are tests that call sleep that are only ran during the nightly.

/morph test-nightly

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1431

All builds and test passed!

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

This is a breaking change though, yes? Previously calling sleep in the default build profile would actually put the target to sleep. Now this won't be the case. Just double checking this is an intended API break.

@betzw
Copy link
Contributor

betzw commented Jan 20, 2017

@bridadan as far as I remember this (breaking) change has been requested/suggested by @sg-, so maybe he is the right person to clarify if he intended what has been done here ...

@bulislaw
Copy link
Member Author

Yes the platform won't go to sleep for default & debug profile, but I would say it's not really a breaking change as sleep is an optimization and more of a express of a intent for user, which should be opaque. Ideally platform should go to sleep whenever it can without being explicitly told to (and accidentally @betzw PR achieves just that). This PR clarifies the API and hides ugly #ifdefs from the code. Also I took the action to rethink our profiles (what the heck is default profile anyway) and come up with something like debug/release/small with some set characteristics.

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

Thanks for clarifying @bulislaw and @betzw, seems ok to me 👍

@betzw
Copy link
Contributor

betzw commented Jan 24, 2017

What will be the next steps for this PR & PR #3566?

@bulislaw
Copy link
Member Author

@sg- @0xc0170 can we merge that?

@betzw
Copy link
Contributor

betzw commented Jan 26, 2017

@bulislaw seems as we if have the "ready to merge" go from @0xc0170.
As I do not have write access permissions could you pls. merge this PR and take care also of PR #3566 to get merged?!?

cc @screamerbg

@bulislaw
Copy link
Member Author

I don't have the powers, someone will merge it soon.

@0xc0170 0xc0170 merged commit ade6722 into master Jan 26, 2017
pan- added a commit to pan-/mbed that referenced this pull request Mar 9, 2017
The `sleep` function as been changed into `hal_sleep` by ARMmbed#3607.
Unfortunately the call to `sleep` in the hal_patch for the NRF51822 has not been
updated to `hal_sleep`. The result was a link time error for targets based on
NRF51822_LEGACY compiling with the mbed OS 5 tree.
adbridge pushed a commit that referenced this pull request Mar 13, 2017
The `sleep` function as been changed into `hal_sleep` by #3607.
Unfortunately the call to `sleep` in the hal_patch for the NRF51822 has not been
updated to `hal_sleep`. The result was a link time error for targets based on
NRF51822_LEGACY compiling with the mbed OS 5 tree.
bulislaw pushed a commit that referenced this pull request Mar 13, 2017
The `sleep` function as been changed into `hal_sleep` by #3607.
Unfortunately the call to `sleep` in the hal_patch for the NRF51822 has not been
updated to `hal_sleep`. The result was a link time error for targets based on
NRF51822_LEGACY compiling with the mbed OS 5 tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants