0% found this document useful (0 votes)
27 views5 pages

XMC Posif C

posif

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

XMC Posif C

posif

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1 /**

2 * @file xmc_posif.c
3 * @date 2019-12-16
4 *
5 * @cond
6 *****************************************************************************
7 * XMClib v2.2.0 - XMC Peripheral Driver Library
8 *
9 * Copyright (c) 2015-2020, Infineon Technologies AG
10 * All rights reserved.
11 *
12 * Boost Software License - Version 1.0 - August 17th, 2003
13 *
14 * Permission is hereby granted, free of charge, to any person or organization
15 * obtaining a copy of the software and accompanying documentation covered by
16 * this license (the "Software") to use, reproduce, display, distribute,
17 * execute, and transmit the Software, and to prepare derivative works of the
18 * Software, and to permit third-parties to whom the Software is furnished to
19 * do so, all subject to the following:
20 *
21 * The copyright notices in the Software and this entire statement, including
22 * the above license grant, this restriction and the following disclaimer,
23 * must be included in all copies of the Software, in whole or in part, and
24 * all derivative works of the Software, unless such copies or derivative
25 * works are solely in the form of machine-executable object code generated by
26 * a source language processor.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
31 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
32 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
33 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 * DEALINGS IN THE SOFTWARE.
35 *
36 * To improve the quality of the software, users are encouraged to share
37 * modifications, enhancements or bug fixes with Infineon Technologies AG
38 * at [email protected].
39 *****************************************************************************
40 *
41 * Change History
42 * --------------
43 *
44 * 2015-02-18:
45 * - Initial version
46 *
47 * 2015-02-20:
48 * - Driver description added <BR>
49 *
50 * 2015-04-30:
51 * - XMC_POSIF_Enable and XMC_POSIF_Disable APIs updated for POSIF1 peripheral
check <BR>
52 *
53 * 2015-06-19:
54 * - Removed GetDriverVersion API <BR>
55 *
56 * 2017-02-25:
57 * - XMC_POSIF_Enable() and XMC_POSIF_Disable() fixed compilation warnings
58 *
59 * 2019-12-16:
60 * - Fix including files following the convention: angle brackets are used for
standard includes and double quotes for everything else.
61 *
62 * @endcond
63 *
64 */
65
66 /*************************************************************************************
********************************
67 * HEADER FILES
68
*************************************************************************************
*******************************/
69 #include "xmc_posif.h"
70
71 /* POSIF is not available on XMC1100 and XMC1200 */
72 #if defined(POSIF0)
73 #include "xmc_scu.h"
74
75 /*************************************************************************************
********************************
76 * MACROS
77
*************************************************************************************
*******************************/
78 #define XMC_POSIF_PCONF_INSEL_Msk (0x3fUL << POSIF_PCONF_INSEL0_Pos) /*< Mask
for input pins selection */
79 #define XMC_POSIF_INSEL_MAX (4U) /*< Maximum possible input selector */
80
81 /*************************************************************************************
********************************
82 * LOCAL ROUTINES
83
*************************************************************************************
*******************************/
84 #ifdef XMC_ASSERT_ENABLE
85 __STATIC_INLINE bool XMC_POSIF_IsPeripheralValid(const XMC_POSIF_t *const peripheral)
86 {
87 bool tmp;
88
89 tmp = (peripheral == POSIF0);
90 #if defined(POSIF1)
91 tmp |= (peripheral == POSIF1);
92 #endif
93
94 return tmp;
95 }
96 #endif
97 /*************************************************************************************
********************************
98 * API IMPLEMENTATION
99
*************************************************************************************
*******************************/
100
101 /* API to enable the POSIF module */
102 void XMC_POSIF_Enable(XMC_POSIF_t *const peripheral)
103 {
104 #if UC_FAMILY == XMC4
105 XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_CCU);
106 #endif
107
108 if (peripheral == POSIF0)
109 {
110 #if defined(CLOCK_GATING_SUPPORTED)
111 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_POSIF0);
112 #endif
113 #if defined(PERIPHERAL_RESET_SUPPORTED)
114 XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_POSIF0);
115 #endif
116 }
117 #if defined(POSIF1)
118 else if (peripheral == POSIF1)
119 {
120 #if defined(CLOCK_GATING_SUPPORTED)
121 XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_POSIF1);
122 #endif
123 #if defined(PERIPHERAL_RESET_SUPPORTED)
124 XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_POSIF1);
125 #endif
126 }
127 #endif
128 else
129 {
130 XMC_ASSERT("XMC_POSIF_Disable:Invalid module pointer", 0);
131 }
132 }
133
134 /* API to disable the POSIF module */
135 void XMC_POSIF_Disable(XMC_POSIF_t *const peripheral)
136 {
137 if (peripheral == POSIF0)
138 {
139 #if defined(PERIPHERAL_RESET_SUPPORTED)
140 XMC_SCU_RESET_AssertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_POSIF0);
141 #endif
142 #if defined(CLOCK_GATING_SUPPORTED)
143 XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_POSIF0);
144 #endif
145 }
146 #if defined(POSIF1)
147 else if (peripheral == POSIF1)
148 {
149 #if defined(PERIPHERAL_RESET_SUPPORTED)
150 XMC_SCU_RESET_AssertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_POSIF1);
151 #endif
152 #if defined(CLOCK_GATING_SUPPORTED)
153 XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_POSIF1);
154 #endif
155 }
156 #endif
157 else
158 {
159 XMC_ASSERT("XMC_POSIF_Disable:Invalid module pointer", 0);
160 }
161 }
162
163 /* API to initialize POSIF global resources */
164 void XMC_POSIF_Init(XMC_POSIF_t *const peripheral, const XMC_POSIF_CONFIG_t *const
config)
165 {
166 XMC_ASSERT("XMC_POSIF_Init:Invalid module pointer", XMC_POSIF_IsPeripheralValid(
peripheral));
167 XMC_ASSERT("XMC_POSIF_Init:NULL Pointer", (config != (XMC_POSIF_CONFIG_t *)NULL) );
168
169 /* Enable the POSIF module */
170 XMC_POSIF_Enable(peripheral);
171
172 /* Stop POSIF */
173 XMC_POSIF_Stop(peripheral);
174
175 /* Program the operational mode, input selectors and debounce filter */
176 peripheral->PCONF = config->pconf;
177 }
178
179 /* API to initialize hall sensor interface */
180 XMC_POSIF_STATUS_t XMC_POSIF_HSC_Init(XMC_POSIF_t *const peripheral, const
XMC_POSIF_HSC_CONFIG_t *const config)
181 {
182 XMC_POSIF_STATUS_t retval;
183
184 XMC_ASSERT("XMC_POSIF_HSC_Init:Invalid module pointer\n",
XMC_POSIF_IsPeripheralValid(peripheral));
185 XMC_ASSERT("XMC_POSIF_HSC_Init:NULL Pointer\n", (config != (XMC_POSIF_HSC_CONFIG_t
*)NULL) );
186
187 if (XMC_POSIF_MODE_HALL_SENSOR == (XMC_POSIF_MODE_t)((peripheral->PCONF) & (uint32_t
)POSIF_PCONF_FSEL_Msk) )
188 {
189 peripheral->PCONF |= config->hall_config;
190 retval = XMC_POSIF_STATUS_OK;
191 }
192 else
193 {
194 retval = XMC_POSIF_STATUS_ERROR;
195 }
196 return retval;
197 }
198
199 /* API to initialize quadrature decoder interface */
200 XMC_POSIF_STATUS_t XMC_POSIF_QD_Init(XMC_POSIF_t *const peripheral, const
XMC_POSIF_QD_CONFIG_t *const config)
201 {
202 uint8_t reg;
203 XMC_POSIF_STATUS_t retval;
204
205 XMC_ASSERT("XMC_POSIF_QD_Init:Invalid module pointer", XMC_POSIF_IsPeripheralValid(
peripheral));
206 XMC_ASSERT("XMC_POSIF_QD_Init:NULL Pointer", (config != (XMC_POSIF_QD_CONFIG_t *)
NULL) );
207
208 reg = (uint8_t)((peripheral->PCONF) & (uint32_t)POSIF_PCONF_FSEL_Msk);
209 if (((uint32_t)XMC_POSIF_MODE_QD == reg) || ((uint32_t)XMC_POSIF_MODE_MCM_QD == reg
))
210 {
211 /* Program the quadrature mode */
212 peripheral->PCONF |= (uint32_t)(config->mode) << POSIF_PCONF_QDCM_Pos;
213 peripheral->QDC = config->qdc;
214 retval = XMC_POSIF_STATUS_OK;
215 }
216 else
217 {
218 retval = XMC_POSIF_STATUS_ERROR;
219 }
220
221 return retval;
222 }
223
224 /* API to initialize multi-channel mode.
225 * This is used in Hall mode, standalone multi-channel mode and quadrature with
multi-channel mode
226 */
227 XMC_POSIF_STATUS_t XMC_POSIF_MCM_Init(XMC_POSIF_t *const peripheral, const
XMC_POSIF_MCM_CONFIG_t *const config)
228 {
229 XMC_POSIF_STATUS_t retval;
230
231 XMC_ASSERT("XMC_POSIF_MCM_Init:Invalid module pointer", XMC_POSIF_IsPeripheralValid(
peripheral));
232 XMC_ASSERT("XMC_POSIF_MCM_Init:NULL Pointer", (config != (XMC_POSIF_MCM_CONFIG_t *)
NULL) );
233
234 if ((XMC_POSIF_MODE_t)((peripheral->PCONF) & (uint32_t)POSIF_PCONF_FSEL_Msk) !=
XMC_POSIF_MODE_QD)
235 {
236 peripheral->PCONF |= config->mcm_config;
237 retval = XMC_POSIF_STATUS_OK;
238 }
239 else
240 {
241 retval = XMC_POSIF_STATUS_ERROR;
242 }
243 return retval;
244 }
245
246 /* API to configure input source */
247 void XMC_POSIF_SelectInputSource (XMC_POSIF_t *const peripheral, const
XMC_POSIF_INPUT_PORT_t input0,
248 const XMC_POSIF_INPUT_PORT_t input1, const
XMC_POSIF_INPUT_PORT_t input2)
249 {
250 uint32_t reg;
251 XMC_ASSERT("XMC_POSIF_SelectInputSource:Invalid module pointer",
XMC_POSIF_IsPeripheralValid(peripheral));
252 XMC_ASSERT("XMC_POSIF_SelectInputSource:Wrong input port input0", (input0 <
XMC_POSIF_INSEL_MAX));
253 XMC_ASSERT("XMC_POSIF_SelectInputSource:Wrong input port input1", (input1 <
XMC_POSIF_INSEL_MAX));
254 XMC_ASSERT("XMC_POSIF_SelectInputSource:Wrong input port input2", (input2 <
XMC_POSIF_INSEL_MAX));
255
256 reg = (uint32_t)((((uint32_t)input0 << POSIF_PCONF_INSEL0_Pos) & (uint32_t)
POSIF_PCONF_INSEL0_Msk) |
257 (((uint32_t)input1 << POSIF_PCONF_INSEL1_Pos) & (uint32_t)
POSIF_PCONF_INSEL1_Msk) |
258 (((uint32_t)input2 << POSIF_PCONF_INSEL2_Pos) & (uint32_t)
POSIF_PCONF_INSEL2_Msk));
259 peripheral->PCONF = ((peripheral->PCONF & ~(uint32_t)XMC_POSIF_PCONF_INSEL_Msk) |
reg);
260 }
261
262 /* API to select an interrupt node */
263 void XMC_POSIF_SetInterruptNode(XMC_POSIF_t *const peripheral, const
XMC_POSIF_IRQ_EVENT_t event, const XMC_POSIF_SR_ID_t sr)
264 {
265 uint32_t reg;
266
267 XMC_ASSERT("XMC_POSIF_SetInterruptNode:Invalid module pointer",
XMC_POSIF_IsPeripheralValid(peripheral));
268 XMC_ASSERT("XMC_POSIF_SetInterruptNode:Wrong IRQ event", (event <=
XMC_POSIF_IRQ_EVENT_PCLK) );
269 XMC_ASSERT("XMC_POSIF_SetInterruptNode:Wrong SR ID", (sr <= XMC_POSIF_SR_ID_1) );
270
271 reg = peripheral->PFLGE;
272 reg &= ~((uint32_t)1 << ((uint32_t)event + (uint32_t)POSIF_PFLGE_CHESEL_Pos));
273 reg |= (uint32_t)sr << ((uint32_t)event + (uint32_t)POSIF_PFLGE_CHESEL_Pos);
274 peripheral->PFLGE = reg;
275 }
276 #endif /* #if defined(POSIF0) */
277

You might also like