Skip to content

Enable deepsleep for LowPowerXXX objects #5148

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

Merged

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Sep 20, 2017

Fix for issue #5076.

Description

This PR contains fix to be able to enter deep-sleep mode while using low power ticker/timer.

Status

READY

Migrations

YES
After this fix is when low power ticker/timer is in use deep-sleep will not be disabled.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2017

cc @c1728p9 @ccli8

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

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

What if I initialize a ticker with the following expression:

Ticker foo(get_lp_ticker_data());

The change is broken too easily.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2017

@pan-

what is your suggestion? introduce deep_sleep_allowed boolean (if lp ticker data are used, deepsleep is allowed by default) ?

    Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0) {
        data->interface->init();
        // if lp ticker interface used
        // disable locking deep sleep
    }

Ticker foo(get_lp_ticker_data()); I would consider this as an intention, if Ticker is defined to be locking deepsleep, no matter what ticker interface is used, it locks deep sleep - that is the current situation as I understand. If we move this to ticker interface used as I highlighted above, then we are moving this promise to ticker interface, better?

@mprse
Copy link
Contributor Author

mprse commented Sep 20, 2017

@pan- This example breaks using convention of the Ticker class. If you want to use low power ticker you should use LowPowerTicker class.
If you decided to use Ticker class which operates on low power timer, then it is your decision, but you should be aware that deep-sleep is blocked in this case.
What do you suggest?

@pan-
Copy link
Member

pan- commented Sep 20, 2017

@pan- This example breaks using convention of the Ticker class. If you want to use low power ticker you should use LowPowerTicker class.

No its not breaking conventions, there is a public constructor for it. The LowPowerTicker class has always been a shorthand for Ticker(get_lp_ticker_data()) there is literally no other added value in that class.

what is your suggestion? introduce deep_sleep_allowed boolean (if lp ticker data are used, deepsleep is allowed by default) ?

My suggestion would be to expose whether the ticker continue to work in deep sleep or not in the ticker data so it can be reused by upper layers. I'd also drop the virtual keyword off lock_deepsleep and unlock_deepsleep.

As a side note I'd also make sure that lock and unlock goes in pair. It is not the case with the current code. If the user calls three time in a row attach_us without a detach in between the internal counter of the deepsleep lock will be incremented three times.

@pan-
Copy link
Member

pan- commented Sep 20, 2017

Note: In #5028 @c1728p9 add a get_info function which might be useful if we want to make sure a ticker peripheral can continue to work in deepsleep or not.

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 20, 2017

A similar change will also be needed for Timer, as LowPowerTimer has a similar problem. @pan- did you have any ideas on where to expose ticker deep sleep operation info? This could be part of ticker get_info which is in PR #5028. Alternatively, this could be passed into the constructor like the ticker data itself is.

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 20, 2017

@pan- you beat me to the post by 8 seconds

@mprse
Copy link
Contributor Author

mprse commented Sep 20, 2017

@pan @0xc0170
So as far as I understand, the solution is to use new feature provided in PR #5028 with a little extension.
We can add extra field to the ticker_info_t structure which will provide information if the ticker runs in deep-sleep mode or not. Then in the Ticker class we can use get_info() function from the specified ticker interface to determine if deep-sleep should be disabled or not.
It looks like I need to wait with updates in this PR until PR #5028 is processed to be able to build/test updates in Ticker class. Am I right?
Extra field to the ticker_info_t structure should be added as a part of this PR or PR #5028 ?

As a side note I'd also make sure that lock and unlock go in pair. It is not the case with the current code. If the user calls three time in a row attach_us without a detach in between the internal counter of the deepsleep lock will be incremented three times.

It looks like lock_deepsleep()/unlock_deepsleep() functions implement protection against multi calls to attache() / detatch() functions. Lock is performed only for the initial callback setup and unlock only when callback is registered.

A similar change will also be needed for Timer, as LowPowerTimer has a similar problem.

Fix to the Timer/LowPowerTimer should be provided in the additional PR?

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2017

Fix to the Timer/LowPowerTimer should be provided in the additional PR?

I would clean it all within one patch.

It looks like lock_deepsleep()/unlock_deepsleep() functions implement protection against multi calls to attache() / detatch() functions. Lock is performed only for the initial callback setup and unlock only when callback is registered.

That should be the case, if it's not is a bug.

@pan @0xc0170
So as far as I understand, the solution is to use new feature provided in PR #5028 with a little extension.
We can add extra field to the ticker_info_t structure which will provide information if the ticker runs in deep-sleep mode or not. Then in the Ticker class we can use get_info() function from the specified ticker interface to determine if deep-sleep should be disabled or not.
It looks like I need to wait with updates in this PR until PR #5028 is processed to be able to build/test updates in Ticker class. Am I right?
Extra field to the ticker_info_t structure should be added as a part of this PR or PR #5028 ?

How far are with with 5028? If we can make progress with that one fast (there is Ci running now). We will need to add there that info plus fix these classes also.

Because I can see also another path. To fix this by just getting ticker data - if it's lp ticker, deepsleep locking is disabled (that is what we have now, no info). This would be intermediate fix that 5028 could clean up once we get the proper info in.

@mprse
Copy link
Contributor Author

mprse commented Sep 21, 2017

Because I can see also another path. To fix this by just getting ticker data - if it's lp ticker, deepsleep locking is disabled (that is what we have now, no info). This would be intermediate fix that 5028 could clean up once we get the proper info in.

I understand that this solution is a workaround for now. Should i proceed with this fix?

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2017

Yes, I discussed it with @pan- , agrees also. please update

@pan-
Copy link
Member

pan- commented Sep 21, 2017

To fix this by just getting ticker data - if it's lp ticker, deepsleep locking is disabled (that is what we have now, no info).

That's the best solution for now, it doesn't require API changes and it should always work.

It looks like lock_deepsleep()/unlock_deepsleep() functions implement protection against multi calls to attache() / detatch() functions. Lock is performed only for the initial callback setup and unlock only when callback is registered.

That's right, apologies I misread the code.

@mprse mprse force-pushed the fix_enable_deepsleep_for_lp_timer branch from 380ba30 to 06a3db9 Compare September 21, 2017 10:29
@mprse mprse force-pushed the fix_enable_deepsleep_for_lp_timer branch from 06a3db9 to 10ee2fa Compare September 22, 2017 06:30
}

void Timer::start() {
core_util_critical_section_enter();
if (!_running) {
sleep_manager_lock_deep_sleep();
if(_lock_deepsleep) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be space if (

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 28, 2017

@pan- @c1728p9 Please rereview, the code was updated based on our suggestions

@0xc0170 0xc0170 changed the title Enable deepsleep for LowPowerTicker. Enable deepsleep for LowPowerXXX objects Sep 28, 2017
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 28, 2017

/morph test

@mbed-bot
Copy link

Result: SUCCESS

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

/morph test

Output

mbed Build Number: 1421

All builds and test passed!

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