1 /***************************************************************************//**
2 * \file cy_sysanalog.c
3 * \version 2.10
4 *
5 * Provides the public functions for the API for the SysAnalog driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2017-2020 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 #include "cy_sysanalog.h"
25
26 #ifdef CY_IP_MXS40PASS
27
28 #if defined(__cplusplus)
29 extern "C" {
30 #endif
31
32 CY_MISRA_DEVIATE_BLOCK_START('MISRA C-2012 Rule 11.3', 5, \
33 'PASS_Type will typecast to either PASS_V1_Type or PASS_V2_Type but not both on PDL initialization based on the target device at compile time.')
34
35 #define IS_TMR_CLK_VALID(clock) (((clock) == CY_SYSANALOG_TIMER_CLK_PERI) || \
36 ((clock) == CY_SYSANALOG_TIMER_CLK_DEEPSLEEP) || \
37 ((clock) == CY_SYSANALOG_TIMER_CLK_LF))
38
39 #define IS_TMR_PERIOD_VALID(period) ((period) <= PASS_TIMER_V2_PERIOD_PER_VAL_Msk)
40
41 #define IS_DSMODE_VALID(dsmode) (((dsmode) == CY_SYSANALOG_LPOSC_DUTY_CYCLED) || \
42 ((dsmode) == CY_SYSANALOG_LPOSC_ALWAYS_ON))
43
44 #define IS_SRC_VALID(src) (((src) == CY_SYSANALOG_DEEPSLEEP_SRC_LPOSC) || \
45 ((src) == CY_SYSANALOG_DEEPSLEEP_SRC_CLK_MF))
46
47 #define IS_DIV_VALID(div) (((div) == CY_SYSANALOG_DEEPSLEEP_CLK_NO_DIV) || \
48 ((div) == CY_SYSANALOG_DEEPSLEEP_CLK_DIV_BY_2) || \
49 ((div) == CY_SYSANALOG_DEEPSLEEP_CLK_DIV_BY_4) || \
50 ((div) == CY_SYSANALOG_DEEPSLEEP_CLK_DIV_BY_8) || \
51 ((div) == CY_SYSANALOG_DEEPSLEEP_CLK_DIV_BY_16))
52
53 /* Configure the AREF to use the local Vref and local IZTAT. Can be used with \ref Cy_SysAnalog_Init. */
54 const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_Local =
55 {
56 /*.startup */ CY_SYSANALOG_STARTUP_FAST,
57 /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_LOCAL,
58 /*.vref */ CY_SYSANALOG_VREF_SOURCE_LOCAL_1_2V,
59 /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE,
60 };
61
62 /* Configure the AREF to use the SRSS Vref and SRSS IZTAT. Can be used with \ref Cy_SysAnalog_Init. */
63 const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_SRSS =
64 {
65 /*.startup */ CY_SYSANALOG_STARTUP_FAST,
66 /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_SRSS,
67 /*.vref */ CY_SYSANALOG_VREF_SOURCE_SRSS,
68 /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE,
69 };
70
71 /* Configure the AREF to use the external Vref and local IZTAT. Can be used with \ref Cy_SysAnalog_Init. */
72 const cy_stc_sysanalog_config_t Cy_SysAnalog_Fast_External =
73 {
74 /*.startup */ CY_SYSANALOG_STARTUP_FAST,
75 /*.iztat */ CY_SYSANALOG_IZTAT_SOURCE_LOCAL,
76 /*.vref */ CY_SYSANALOG_VREF_SOURCE_EXTERNAL,
77 /*.deepSleep */ CY_SYSANALOG_DEEPSLEEP_DISABLE,
78 };
79
80 /*******************************************************************************
81 * Function Name: Cy_SysAnalog_Init
82 ****************************************************************************//**
83 *
84 * Initialize the AREF block.
85 *
86 * \param config
87 * Pointer to structure containing configuration data. See \ref cy_stc_sysanalog_config_t
88 *
89 * \return
90 * - \ref CY_SYSANALOG_SUCCESS : initialization complete
91 * - \ref CY_SYSANALOG_BAD_PARAM : input pointers are null, initialization incomplete
92 *
93 * \funcusage
94 *
95 * \snippet sysanalog/snippet/main.c SYSANA_SNIPPET_INIT
96 *
97 *******************************************************************************/
Cy_SysAnalog_Init(const cy_stc_sysanalog_config_t * config)98 cy_en_sysanalog_status_t Cy_SysAnalog_Init(const cy_stc_sysanalog_config_t * config)
99 {
100 CY_ASSERT_L1(NULL != config);
101
102 cy_en_sysanalog_status_t result = CY_SYSANALOG_BAD_PARAM;
103
104 if (NULL != config)
105 {
106 CY_ASSERT_L3(CY_SYSANALOG_DEEPSLEEP(config->deepSleep));
107 CY_ASSERT_L3(CY_SYSANALOG_VREF(config->vref));
108 CY_ASSERT_L3(CY_SYSANALOG_IZTAT(config->iztat));
109
110 PASS_AREF_AREF_CTRL = (uint32_t) CY_SYSANALOG_STARTUP_FAST \
111 | (uint32_t) CY_SYSANALOG_DEFAULT_BIAS_SCALE \
112 | (uint32_t) config->iztat \
113 | (uint32_t) config->vref \
114 | (uint32_t) config->deepSleep;
115
116 result = CY_SYSANALOG_SUCCESS;
117 }
118
119 return result;
120 }
121
122
123 /*******************************************************************************
124 * Function Name: Cy_SysAnalog_DeepSleepInit
125 ****************************************************************************//**
126 *
127 * Initialize PASS_ver2 Deep Sleep features such as Low Power Oscillator, Deep Sleep Clock, Timer.
128 *
129 * \param base Pointer to the PASS register structure.
130 *
131 * \param config
132 * Pointer to structure containing configuration data. See \ref cy_stc_sysanalog_deep_sleep_config_t
133 *
134 * \return
135 * - \ref CY_SYSANALOG_SUCCESS : initialization complete
136 * - \ref CY_SYSANALOG_BAD_PARAM : input pointers are null, initialization incomplete
137 *
138 * \funcusage \snippet sysanalog/snippet/main.c SYSANA_SNIPPET_INIT_DS
139 *
140 *******************************************************************************/
Cy_SysAnalog_DeepSleepInit(PASS_Type * base,const cy_stc_sysanalog_deep_sleep_config_t * config)141 cy_en_sysanalog_status_t Cy_SysAnalog_DeepSleepInit(PASS_Type * base, const cy_stc_sysanalog_deep_sleep_config_t * config)
142 {
143 cy_en_sysanalog_status_t result = CY_SYSANALOG_UNSUPPORTED;
144
145 CY_ASSERT_L1(NULL != base);
146 CY_ASSERT_L1(NULL != config);
147
148 if(!CY_PASS_V1)
149 {
150 if ((NULL == base) || (NULL == config))
151 {
152 result = CY_SYSANALOG_BAD_PARAM;
153 }
154 else
155 {
156 uint32_t locPeriod = config->timerPeriod - 1UL; /* Convert the user value into the machine value */
157
158 CY_ASSERT_L3(IS_DSMODE_VALID(config->lpOscDsMode));
159 CY_ASSERT_L3(IS_SRC_VALID(config->dsClkSource));
160 CY_ASSERT_L3(IS_DIV_VALID(config->dsClkdivider));
161 CY_ASSERT_L3(IS_TMR_CLK_VALID(config->timerClock));
162 CY_ASSERT_L2(IS_TMR_PERIOD_VALID(locPeriod));
163
164 PASS_LPOSC_CONFIG(base) = _VAL2FLD(PASS_LPOSC_V2_CONFIG_DEEPSLEEP_MODE , config->lpOscDsMode);
165 PASS_DPSLP_CLOCK_SEL(base) = _VAL2FLD(PASS_V2_DPSLP_CLOCK_SEL_DPSLP_CLOCK_SEL, config->dsClkSource) |
166 _VAL2FLD(PASS_V2_DPSLP_CLOCK_SEL_DPSLP_CLOCK_DIV, config->dsClkdivider);
167 PASS_TIMER_CONFIG(base) = _VAL2FLD(PASS_TIMER_V2_CONFIG_CLOCK_SEL , config->timerClock);
168 PASS_TIMER_PERIOD(base) = _VAL2FLD(PASS_TIMER_V2_PERIOD_PER_VAL , locPeriod);
169
170 result = CY_SYSANALOG_SUCCESS;
171 }
172 }
173
174 return result;
175 }
176
177 CY_MISRA_BLOCK_END('MISRA C-2012 Rule 11.3')
178
179 #if defined(__cplusplus)
180 }
181 #endif
182
183 #endif /* CY_IP_MXS40PASS */
184
185 /* [] END OF FILE */
186