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

System.sleep() wake up reason #1410

Merged
merged 7 commits into from Jan 23, 2018

Conversation

@avtolstoy
Copy link
Member

commented Oct 23, 2017

submission notes
**Important:** Please sanitize/remove any confidential info like usernames, passwords, org names, product names/ids, access tokens, client ids/secrets, or anything else you don't wish to share.

Please Read and Sign the Contributor License Agreement ([Info here](https://github.com/spark/firmware/blob/develop/CONTRIBUTING.md)).

You may also delete this submission notes header if you'd like. Thank you for contributing!

NOTE: Target branch is set to feature/system-sleep-multiple-pins

Problem

Users should be able to easily determine why the device woke up from STOP mode, especially after introduction of #1405

Solution

  • All System.sleep() variants now return
    SleepResult object that can be queried on the result of System.sleep() execution:
    • WakeupReason SleepResult::reason();
    • bool SleepResult::wokenUpByRtc();
    • bool SleepResult::wokenUpByPin();
    • pin_t SleepResult::pin();
    • bool SleepResult::rtc();
    • system_error_t SleepResult::error();
  • A set of convenient functions was added to System class to retrieve information about the last sleep:
    • WakeupReason System::wakeUpReason();
    • bool System::wokenUpByPin();
    • bool System::wokenUpByRtc();
    • pin_t System::wakeUpPin();
    • SleepResult System::sleepResult();
    • system_error_t System::sleepError();
  • WakeupReason is an enum of:
    • WAKEUP_REASON_NONE = 0
    • WAKEUP_REASON_PIN = 1
    • WAKEUP_REASON_RTC = 2
    • WAKEUP_REASON_PIN_OR_RTC = 3

Steps to Test

  • wiring/api
  • app/sleep_multiple_pins

Example App

See app/sleep_multiple_pins

References


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • TODO: Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)
@avtolstoy avtolstoy referenced this pull request Oct 25, 2017
3 of 6 tasks complete
@pkourany

This comment has been minimized.

Copy link
Contributor

commented Nov 20, 2017

@avtolstoy, this PR covers a STOP mode wake reason. What about STANDBY (deep sleep) mode wake reason?

@avtolstoy

This comment has been minimized.

Copy link
Member Author

commented Nov 21, 2017

@pkourany Currently the bootloader does not distinguish between being woken up by RTC or WKP pin (RESET_REASON_POWER_MANAGEMENT), so for STANDY mode the reason will be WAKEUP_REASON_PIN_OR_RTC.

@pkourany

This comment has been minimized.

Copy link
Contributor

commented Nov 21, 2017

@avtolstoy, is the plan to update the bootloader at some point to distinguish the two?

@avtolstoy

This comment has been minimized.

Copy link
Member Author

commented Nov 21, 2017

@pkourany It sure would be nice :) I'm not sure that we can do that though. As far as I remember, when waking up from STANDBY mode all the registers except for PWR_CSR are set to default values, and there is a single WUF bit in there that indicates there was a wakeup event either from WKP pin or from RTC:
image

@m-mcgowan m-mcgowan added this to the 0.8.0-rc.2 milestone Jan 18, 2018

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Jan 18, 2018

For visibility, it looks like the conversation is resolved, so I will go ahead and merge this in for the upcoming 0.8.0-rc.2 release.

@m-mcgowan m-mcgowan force-pushed the feature/system-sleep-multiple-pins branch from c53601e to 02618ea Jan 22, 2018

@m-mcgowan m-mcgowan changed the base branch from feature/system-sleep-multiple-pins to develop Jan 23, 2018

@m-mcgowan m-mcgowan force-pushed the feature/system-sleep-wkp-reason branch from 4bd3469 to 7467aed Jan 23, 2018

@m-mcgowan m-mcgowan force-pushed the feature/system-sleep-wkp-reason branch from 7467aed to 38a88c0 Jan 23, 2018

@m-mcgowan m-mcgowan merged commit 7a5fda4 into develop Jan 23, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@m-mcgowan m-mcgowan deleted the feature/system-sleep-wkp-reason branch Jan 23, 2018

avtolstoy added a commit to particle-iot/docs that referenced this pull request Feb 23, 2018
Documents System.sleep() wake up reason (particle-iot/device-os#1410)
- `SleepResult` class
  - `WakeupReason SleepResult::reason();`
  - `bool SleepResult::wokenUpByRtc();`
  - `bool SleepResult::wokenUpByPin();`
  - `pin_t SleepResult::pin();`
  - `bool SleepResult::rtc();`
  - `system_error_t SleepResult::error();`

- `WakeupReason System::wakeUpReason();`
- `bool System::wokenUpByPin();`
- `bool System::wokenUpByRtc();`
- `pin_t System::wakeUpPin();`
- `SleepResult System::sleepResult();`
- `system_error_t System::sleepError();`

- `WakeupReason` enum:
  - `WAKEUP_REASON_NONE = 0`
  - `WAKEUP_REASON_PIN = 1`
  - `WAKEUP_REASON_RTC = 2`
  - `WAKEUP_REASON_PIN_OR_RTC = 3`
technobly added a commit to particle-iot/docs that referenced this pull request Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.