Skip to content

Commit ab5eb07

Browse files
author
Kyle Kearney
committed
Stop the us_ticker timer before deepsleep
A running timer will block DeepSleep, which would normally be good because we don't want the timer to accidentally lose counts. We don't care about that for us_ticker (If we're requesting deepsleep the upper layers already determined that they are okay with that), so explicitly stop the us_ticker timer before we go to sleep and start it back up afterwards.
1 parent 8f87735 commit ab5eb07

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/cy_sleep_api.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,30 @@
1919

2020
#include "cmsis.h"
2121
#include "device.h"
22-
#include "cy_syspm.h"
22+
#include "cyhal_syspm.h"
23+
#include "cy_us_ticker.h"
2324

2425
#if DEVICE_SLEEP
2526

2627
void hal_sleep(void)
2728
{
28-
Cy_SysPm_CpuEnterSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
29+
cyhal_syspm_sleep();
2930
}
3031

3132
void hal_deepsleep(void)
3233
{
3334
#if DEVICE_LPTICKER
34-
Cy_SysPm_CpuEnterDeepSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
35+
// A running timer will block DeepSleep, which would normally be
36+
// good because we don't want the timer to accidentally
37+
// lose counts. We don't care about that for us_ticker
38+
// (If we're requesting deepsleep the upper layers already determined
39+
// that they are okay with that), so explicitly stop the us_ticker
40+
// timer before we go to sleep and start it back up afterwards.
41+
cy_us_ticker_stop();
42+
cyhal_syspm_deepsleep();
43+
cy_us_ticker_start();
3544
#else
36-
Cy_SysPm_CpuEnterSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
45+
cyhal_syspm_sleep();
3746
#endif /* DEVICE_LPTICKER */
3847
}
3948

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* mbed Microcontroller Library
3+
* Copyright (c) 2017-2018 Future Electronics
4+
* Copyright (c) 2019, Arm Limited and affiliates.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef MBED_CY_US_TICKER_H
21+
#define MBED_CY_US_TICKER_H
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/** Starts the us_ticker. */
28+
void cy_us_ticker_start();
29+
30+
/** Stops the us_ticker. */
31+
void cy_us_ticker_stop();
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif // MBED_CY_US_TICKER_H

targets/TARGET_Cypress/TARGET_PSOC6/cy_us_ticker_api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "cmsis.h"
1818
#include "us_ticker_api.h"
1919
#include "mbed_error.h"
20+
#include "cy_us_ticker.h"
2021
#include "cyhal_timer.h"
2122
#include "cy_tcpwm_counter.h"
2223

@@ -51,6 +52,16 @@ static void cy_us_ticker_irq_handler(MBED_UNUSED void *arg, MBED_UNUSED cyhal_ti
5152
us_ticker_irq_handler();
5253
}
5354

55+
void cy_us_ticker_start()
56+
{
57+
cyhal_timer_start(&cy_us_timer);
58+
}
59+
60+
void cy_us_ticker_stop()
61+
{
62+
cyhal_timer_stop(&cy_us_timer);
63+
}
64+
5465
void us_ticker_init(void)
5566
{
5667
if (!cy_us_ticker_initialized) {

0 commit comments

Comments
 (0)