1 /***************************************************************************//**
2 * \file cybsp_pm.c
3 *
4 * Description:
5 * Provides initialization code for starting up the hardware contained on the
6 * Infineon board.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
11 * an affiliate of Cypress Semiconductor Corporation
12 *
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 *     http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *******************************************************************************/
27 
28 #include <stdlib.h>
29 #include "cybsp_pm_callbacks.h"
30 #include "cybsp.h"
31 
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35 
36 //--------------------------------------------------------------------------------------------------
37 // cybsp_pm_callbacks_register
38 //--------------------------------------------------------------------------------------------------
cybsp_pm_callbacks_register(void)39 cy_rslt_t cybsp_pm_callbacks_register(void)
40 {
41     cy_stc_syspm_callback_t** _cybsp_callbacks_array;
42     size_t number_of_callbacks = 0;
43 
44     _cybsp_pm_callbacks_get_ptr_and_number(&_cybsp_callbacks_array, &number_of_callbacks);
45 
46     if ((number_of_callbacks == 0) || (*_cybsp_callbacks_array == NULL))
47     {
48         // Nothing to register, return success
49         return CY_RSLT_SUCCESS;
50     }
51 
52     for (size_t cb_idx = 0; cb_idx < number_of_callbacks; ++cb_idx)
53     {
54         if (!Cy_SysPm_RegisterCallback(_cybsp_callbacks_array[cb_idx]))
55         {
56             return CYBSP_RSLT_ERR_SYSCLK_PM_CALLBACK;
57         }
58     }
59 
60     return CY_RSLT_SUCCESS;
61 }
62 
63 
64 #if defined(__cplusplus)
65 }
66 #endif
67