Skip to content

Commit 28b7cf3

Browse files
authored
Merge pull request #13130 from kyle-cypress/pr/psoc-usticker
Cypress: us_ticker fixes
2 parents e1b8f06 + 6a2d93e commit 28b7cf3

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* mbed Microcontroller Library
3+
* Copyright (c) 2019, Arm Limited and affiliates.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef CY_MBED_POST_INIT_H
20+
#define CY_MBED_POST_INIT_H
21+
22+
#include "mbed_toolchain.h"
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/*******************************************************************************
29+
* Function Name: cy_mbed_post_bsp_init_hook
30+
****************************************************************************//**
31+
*
32+
* Function that is called immediately after cybsp_init finishes executing
33+
* Applications can override this definition if they need to reserve resources
34+
* early in the startup process so that later stages won't try and use them.
35+
* For example, a timer instance might be reserved so that the us_ticker won't
36+
* try to allocate it.
37+
*
38+
*******************************************************************************/
39+
void cy_mbed_post_bsp_init_hook(void);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif /* CY_MBED_POST_INIT_H */

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) {

targets/TARGET_Cypress/TARGET_PSOC6/mbed_overrides.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "cycfg.h"
2121
#include "cyhal_hwmgr.h"
2222
#include "cybsp.h"
23+
#include "cy_mbed_post_init.h"
2324
#include "mbed_power_mgmt.h"
2425
#if MBED_CONF_RTOS_PRESENT
2526
#include "rtos_idle.h"
@@ -49,6 +50,11 @@ static void active_idle_hook(void)
4950
}
5051
#endif
5152

53+
MBED_WEAK void cy_mbed_post_bsp_init_hook(void)
54+
{
55+
/* By default, do nothing */
56+
}
57+
5258
/*******************************************************************************
5359
* Function Name: mbed_sdk_init
5460
****************************************************************************//**
@@ -71,6 +77,8 @@ void mbed_sdk_init(void)
7177
/* Set up the device based on configurator selections */
7278
cybsp_init();
7379

80+
cy_mbed_post_bsp_init_hook();
81+
7482
#if CY_CPU_CORTEX_M0P
7583
/* Enable global interrupts */
7684
__enable_irq();

0 commit comments

Comments
 (0)