1 /***************************************************************************//**
2 * \file cy_syspm_btss.c
3 * \version 5.94
4 *
5 * Provides implementation of the BTSS PDL driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2016-2021 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25 #include "cy_device.h"
26
27 #if defined (CY_IP_MXS40BLE52SS)
28
29 #include "cy_syspm_btss.h"
30
31 #define CY_BTSS_RADIO_XTAL_OSC_FREQ (24000000UL) /* Hz */
32
33 /* BTSS Lock counter */
34 static uint32_t cy_btss_lock_count;
35
36 /* CPUSS Lock counter */
37 static uint32_t cy_cpuss_lock_count;
38
39
Cy_BTSS_GetXtalOscFreq(void)40 uint32_t Cy_BTSS_GetXtalOscFreq(void)
41 {
42 return CY_BTSS_RADIO_XTAL_OSC_FREQ;
43 }
44
Cy_BTSS_PowerDep(bool enable)45 cy_en_btss_status_t Cy_BTSS_PowerDep(bool enable)
46 {
47 cy_en_btss_status_t retVal = CY_BTSS_INVALID_STATE;
48 uint32_t interruptState;
49 uint32_t timeoutus = CY_BTSS_SL_CTL3_WAIT_DELAY_US;
50
51 if(enable)
52 {
53 interruptState = Cy_SysLib_EnterCriticalSection();
54 /* Set only if cy_btss_lock_count == 0 */
55 if(cy_btss_lock_count == 0UL)
56 {
57 (void)cy_pd_pdcm_set_dependency(CY_PD_PDCM_BTSS, CY_PD_PDCM_CPUSS); /* Suppress a compiler warning about unused return value */
58 }
59 Cy_SysLib_ExitCriticalSection(interruptState);
60
61 for(;(Cy_SysClk_PeriGroupGetSlaveCtl(CY_PERI_BLESS_GROUP_NR,CY_SYSCLK_PERI_GROUP_SL_CTL3) == 0UL) &&
62 (0UL != timeoutus);
63 timeoutus--)
64 {
65 Cy_SysLib_DelayUs(1U);
66 }
67 if(0UL == timeoutus)
68 {
69 retVal = CY_BTSS_TIMEOUT;
70 }
71 else
72 {
73 retVal = CY_BTSS_SUCCESS;
74 }
75
76 interruptState = Cy_SysLib_EnterCriticalSection();
77 if(retVal == CY_BTSS_SUCCESS)
78 {
79 cy_btss_lock_count++;
80 }
81 Cy_SysLib_ExitCriticalSection(interruptState);
82 }
83 else
84 {
85 /* Dont Decrement if already in Disable State */
86 interruptState = Cy_SysLib_EnterCriticalSection();
87 if(cy_btss_lock_count != 0UL)
88 {
89 cy_btss_lock_count--;
90 }
91
92 /* Clear only if cy_btss_lock_count == 0 */
93 if(cy_btss_lock_count == 0UL)
94 {
95 (void)cy_pd_pdcm_clear_dependency(CY_PD_PDCM_BTSS, CY_PD_PDCM_CPUSS); /* Suppress a compiler warning about unused return value */
96 }
97 Cy_SysLib_ExitCriticalSection(interruptState);
98
99 retVal = CY_BTSS_SUCCESS;
100 }
101
102 return retVal;
103 }
104
Cy_BTSS_CPUSSPowerDep(bool enable)105 cy_en_btss_status_t Cy_BTSS_CPUSSPowerDep(bool enable)
106 {
107 cy_en_btss_status_t retVal = CY_BTSS_INVALID_STATE;
108 uint32_t interruptState;
109
110 interruptState = Cy_SysLib_EnterCriticalSection();
111
112 if(enable)
113 {
114 /* Set only if cy_btss_lock_count == 0 */
115 if(cy_cpuss_lock_count == 0UL)
116 {
117 (void)cy_pd_pdcm_set_dependency(CY_PD_PDCM_CPUSS, CY_PD_PDCM_BTSS); /* Suppress a compiler warning about unused return value */
118 }
119
120 cy_cpuss_lock_count++;
121
122 retVal = CY_BTSS_SUCCESS;
123 }
124 else
125 {
126 /* Dont Decrement if already in Disable State */
127 if(cy_cpuss_lock_count != 0UL)
128 {
129 cy_cpuss_lock_count--;
130 }
131
132 /* Clear only if cy_btss_lock_count == 0 */
133 if(cy_cpuss_lock_count == 0UL)
134 {
135 (void)cy_pd_pdcm_clear_dependency(CY_PD_PDCM_CPUSS, CY_PD_PDCM_BTSS); /* Suppress a compiler warning about unused return value */
136 }
137
138 retVal = CY_BTSS_SUCCESS;
139 }
140
141 Cy_SysLib_ExitCriticalSection(interruptState);
142
143 return retVal;
144 }
145
146
Cy_BTSS_AssertReset(bool assertEn)147 void Cy_BTSS_AssertReset(bool assertEn)
148 {
149 (void)Cy_SysClk_PeriGroupSetSlaveCtl(CY_PERI_BLESS_GROUP_NR, CY_SYSCLK_PERI_GROUP_SL_CTL2, (assertEn ? 0x1U : 0x0U));
150 }
151
Cy_BTSS_IsResetAsserted(void)152 bool Cy_BTSS_IsResetAsserted(void)
153 {
154 return (Cy_SysClk_PeriGroupGetSlaveCtl(CY_PERI_BLESS_GROUP_NR, CY_SYSCLK_PERI_GROUP_SL_CTL2) != 0x0U);
155 }
156
157 #endif /* CY_IP_MXS40BLE52SS */
158 /* [] END OF FILE */
159
160