Skip to content

Commit 69165d3

Browse files
author
Kyle Kearney
committed
Register Sysclk PM callback in BSP Init
1 parent 3f4c888 commit 69165d3

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062S2_43012/cybsp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cy_rslt_t cybsp_init(void)
3737
cy_rslt_t result = CY_RSLT_SUCCESS;
3838

3939
init_cycfg_system();
40+
result = cybsp_register_sysclk_pm_callback();
4041

4142
#ifndef __MBED__
4243
if (CY_RSLT_SUCCESS == result)

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_BLE/cybsp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ extern "C" {
3333

3434
cy_rslt_t cybsp_init(void)
3535
{
36-
init_cycfg_system();
37-
3836
cy_rslt_t result = CY_RSLT_SUCCESS;
3937

38+
init_cycfg_system();
39+
result = cybsp_register_sysclk_pm_callback();
4040

4141
#ifndef __MBED__
4242
if (CY_RSLT_SUCCESS == result)

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/cybsp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ extern "C" {
3434

3535
cy_rslt_t cybsp_init(void)
3636
{
37-
init_cycfg_system();
38-
3937
cy_rslt_t result = CY_RSLT_SUCCESS;
4038

39+
init_cycfg_system();
40+
result = cybsp_register_sysclk_pm_callback();
41+
4142
#ifndef __MBED__
4243
if (CY_RSLT_SUCCESS == result)
4344
{

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/TARGET_CY8CPROTO_062_4343W/cybsp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ extern "C" {
3333

3434
cy_rslt_t cybsp_init(void)
3535
{
36-
init_cycfg_system();
37-
3836
cy_rslt_t result = CY_RSLT_SUCCESS;
3937

38+
init_cycfg_system();
39+
result = cybsp_register_sysclk_pm_callback();
40+
4041
#ifndef __MBED__
4142
if (CY_RSLT_SUCCESS == result)
4243
{

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/cybsp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ extern "C" {
3333

3434
cy_rslt_t cybsp_init(void)
3535
{
36-
init_cycfg_system();
37-
3836
cy_rslt_t result = CY_RSLT_SUCCESS;
3937

38+
init_cycfg_system();
39+
result = cybsp_register_sysclk_pm_callback();
40+
4041
#ifndef __MBED__
4142
if (CY_RSLT_SUCCESS == result)
4243
{

targets/TARGET_Cypress/TARGET_PSOC6/common/cybsp_core.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ void cybsp_btn_set_interrupt(cybsp_btn_t which, cyhal_gpio_event_t type, cyhal_g
6060
cyhal_gpio_enable_event((cyhal_gpio_t)which, type, 7, 1);
6161
}
6262

63+
/* The sysclk deep sleep callback is recommended to be the last callback that
64+
* is executed before entry into deep sleep mode and the first one upon
65+
* exit the deep sleep mode.
66+
* Doing so minimizes the time spent on low power mode entry and exit.
67+
*/
68+
#ifndef CYBSP_SYSCLK_PM_CALLBACK_ORDER
69+
#define CYBSP_SYSCLK_PM_CALLBACK_ORDER (255u)
70+
#endif
71+
72+
cy_rslt_t cybsp_register_sysclk_pm_callback(void)
73+
{
74+
cy_rslt_t result = CY_RSLT_SUCCESS;
75+
static cy_stc_syspm_callback_params_t cybsp_sysclk_pm_callback_param = {NULL, NULL};
76+
static cy_stc_syspm_callback_t cybsp_sysclk_pm_callback = {
77+
.callback = &Cy_SysClk_DeepSleepCallback,
78+
.type = CY_SYSPM_DEEPSLEEP,
79+
.callbackParams = &cybsp_sysclk_pm_callback_param,
80+
.order = CYBSP_SYSCLK_PM_CALLBACK_ORDER
81+
};
82+
83+
if (!Cy_SysPm_RegisterCallback(&cybsp_sysclk_pm_callback))
84+
{
85+
result = CYBSP_RSLT_ERR_SYSCLK_PM_CALLBACK;
86+
}
87+
return result;
88+
}
89+
6390
#if defined(__cplusplus)
6491
}
6592
#endif

targets/TARGET_Cypress/TARGET_PSOC6/common/cybsp_core.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ extern "C" {
5151
* \{
5252
*/
5353

54+
/** Failed to configure sysclk power management callback */
55+
#define CYBSP_RSLT_ERR_SYSCLK_PM_CALLBACK (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_BSP, 0))
5456

5557
/** \} group_abstraction_board_macros */
5658

@@ -130,6 +132,13 @@ bool cybsp_btn_get_state(cybsp_btn_t which);
130132
*/
131133
void cybsp_btn_set_interrupt(cybsp_btn_t which, cyhal_gpio_event_t type, cyhal_gpio_event_callback_t callback, void *callback_arg);
132134

135+
/**
136+
* \brief Registers a power management callback that prepares the clock system
137+
* for entering deep sleep mode and restore the clocks upon wakeup from deep sleep.
138+
* \returns CY_RSLT_SUCCESS if the callback is sucessfully registered, if there is
139+
* a problem registering the callback it returns CYBSP_RSLT_ERR_SYSCLK_PM_CALLBACK.
140+
*/
141+
cy_rslt_t cybsp_register_sysclk_pm_callback(void);
133142

134143
/** \} group_abstraction_board_functions */
135144

0 commit comments

Comments
 (0)