Skip to content

PSoC 6: rework sleep overrides by Cypress's debug macro #13976

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
merged 2 commits into from
Dec 17, 2020

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented Nov 27, 2020

Summary of changes

Fix for PSoC 6 targets mentioned in #13265

According to the discussion here, Cypress has a debug tool that generates the macro CY_CFG_PWR_SYS_IDLE_MODE which intends to disable/limit sleep during debug sessions:

  • unset or set to CY_CFG_PWR_MODE_DEEPSLEEP: sleep and deep sleep
  • CY_CFG_PWR_MODE_SLEEP: sleep only
  • CY_CFG_PWR_MODE_ACTIVE: no sleep

To override sleep behaviours, the previous implementation relies on rtos_attach_idle_hook(), which is a non-API internal function reserved for the user-facing API Kernel::attach_idle_hook() only. Functionally, if an application uses Kernel::attach_idle_hook() (which is a valid use case), the Cypress debug idle hook will get overriden.

As discussed here, this PR moves the sleep overriding to hal_sleep() and hal_deepsleep() implementations.

Impact of changes

Target-specific rework, no noticeable impact to developers.

Migration actions required

None.

Documentation

None.


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@ARMmbed/team-cypress @ARMmbed/mbed-os-core


cyhal_syspm_sleep();
#endif
Copy link
Contributor Author

@LDong-Arm LDong-Arm Nov 27, 2020

Choose a reason for hiding this comment

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

Question: As the macro CY_CFG_PWR_SYS_IDLE_MODE is Cypress-specific, maybe it makes more sense to have that defined in cyhal_syspm_sleep() (Cypress SDK code) instead of the Mbed OS HAL implementation? In that case we wouldn't need any tricks at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ARMmbed/team-cypress Or, could you confirm if the macro is still being used by Cypress's debug tool as of today?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good suggestion.
@kyle-cypress please review this proposal and let us know if you'd rather change your SDK.

Choose a reason for hiding this comment

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

I don't think we should change cyhal_syspm_sleep. The intent of CY_CFG_PWR_SYS_IDLE_MODE is to control how the RTOS idle task behaves, not to completely disable the sleep driver (even if the two wind up being very similar in practice).

Copy link
Contributor

Choose a reason for hiding this comment

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

The current proposal is good and easy to follow so I would go with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent of CY_CFG_PWR_SYS_IDLE_MODE is to control how the RTOS idle task behaves,

Well, as explained in the description, the idle overriding is a feature we provide to the application. Overriding it by drivers/BSPs would create a conflict if the application uses it.

@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Nov 27, 2020
@ciarmcom ciarmcom requested review from a team November 27, 2020 18:00
@ciarmcom
Copy link
Member

@LDong-Arm, thank you for your changes.
@ARMmbed/team-cypress @ARMmbed/mbed-os-maintainers please review.

cyhal_syspm_sleep();
#endif

Choose a reason for hiding this comment

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

I don't think we should change cyhal_syspm_sleep. The intent of CY_CFG_PWR_SYS_IDLE_MODE is to control how the RTOS idle task behaves, not to completely disable the sleep driver (even if the two wind up being very similar in practice).

@@ -41,9 +46,14 @@ void hal_deepsleep(void)
cy_us_ticker_stop();
cyhal_syspm_deepsleep();
cy_us_ticker_start();
#else
#else // DEVICE_LPTICKER
cyhal_syspm_sleep();

Choose a reason for hiding this comment

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

This seems like it is adding a lot of complexity to the hal_deepsleep implementation. Wouldn't it be simpler to keep the call to sleep_manager_lock_deep_sleep and let the sleep manager take care of figuring out whether to call hal_sleep or hal_deepsleep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sleep_manager_lock_deep_sleep() as used before is fine in my opinion. I changed hal_deepsleep() for consistency with the macro-checks in hal_sleep(), but if it's overly complex I can revert this bit.

* Configurator. The default value is system deep sleep.
*/
#if (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_ACTIVE)
rtos_attach_idle_hook(&active_idle_hook);

Choose a reason for hiding this comment

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

Instead of removing this entirely and adding extra checks to hal_sleep to turn it into a no-op, could this be replaced by a call to sleep_manager_lock_sleep? That would be simpler and I believe it would produce more correct results from the sleep/deepsleep statistics mechanism when that is enabled.

Copy link
Contributor Author

@LDong-Arm LDong-Arm Dec 2, 2020

Choose a reason for hiding this comment

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

Mbed OS only supports locking deep sleep, not sleep. This was probably the reason an idle hook was used instead. The locking of deep sleep ensures all features work:

* Use locking/unlocking deepsleep for drivers that depend on features that
* are not allowed (=disabled) during the deepsleep. For instance, high frequency
* clocks.

I think in most use cases, the need to lock regular sleep is comparatively low.

@evedon @kjbracey-arm In terms of functionality/actual use cases, does it make sense to add a lock for regular sleep?

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see why anyone would lock sleep, as it is very shallow mode (core system clock is disabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @0xc0170 said, locking normal sleep makes little sense in actual use cases, so we may not add that to the API.

cyhal_syspm_sleep();
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

The current proposal is good and easy to follow so I would go with it.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 9, 2020

@kyle-cypress @LDong-Arm are there any outstanding questions? There were couple of comments and some were answered. I set this to review again as I do not believe this is ready for CI.

@LDong-Arm
Copy link
Contributor Author

We have given our views on the questions, is there any proposal on how we can handle this? @ARMmbed/team-cypress

@dustin-crossman
Copy link
Contributor

@0xc0170 @LDong-Arm While we still think the new behavior here will differ slightly from the old behavior, we don't have any other proposals for this. We think it's fine to go ahead with this as-is.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 14, 2020

Thanks @dustin-crossman , we will proceed

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 16, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 16, 2020

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️

@0xc0170 0xc0170 merged commit 89bd565 into ARMmbed:master Dec 17, 2020
@mergify mergify bot removed the ready for merge label Dec 17, 2020
@mbedmain mbedmain added release-version: 6.7.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jan 25, 2021
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.

8 participants