1 /**
2  * @file xmc_ccu8.c
3  * @date 2017-04-27
4  *
5  * @cond
6  *********************************************************************************************************************
7  * XMClib v2.1.24 - XMC Peripheral Driver Library
8  *
9  * Copyright (c) 2015-2019, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  * Change History
37  * --------------
38  *
39  * 2015-02-20:
40  *     - Initial <br>
41  *
42  * 2015-06-20:
43  *     - Removed definition of GetDriverVersion API <br>
44  *     - Added XMC_CCU8_SLICE_LoadSelector() API, to select which compare register value has to be loaded
45  *       during external load event.
46  *
47  * 2015-07-24:
48  *     - XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent() is updated to support XMC14 device. <br>
49  *
50  * 2015-08-17:
51  *     - XMC_CCU8_SLICE_CHC_CONFIG_MASK is not applicable to XMC14 devices. <br>
52  *     - Start of prescaler XMC_CCU8_StartPrescaler() is invoked in XMC_CCU8_Init() API. <br>
53  *     - In XMC_CCU8_SLICE_CompareInit(), CHC register is updated according to the device. <br>
54  *     - Bug fix XMC_CCU8_SLICE_ConfigureEvent() during the level setting for XMC14 devices. <br>
55  *     - XMC_CCU8_EnableShadowTransfer() definition is removed, since the API is made as inline. <br>
56  *
57  * 2015-10-07:
58  *     - XMC_CCU8_SLICE_GetEvent() is made as inline.
59  *     - DOC updates for the newly added APIs.
60  *
61  * 2017-02-25:
62  *     - XMC_CCU8_lAssertReset(), XMC_CCU8_lDeassertReset(), XMC_CCU8_lGateClock() and XMC_CCU8_lUngateClock() fix compilation warnings.
63  *
64  * 2017-04-27:
65  *     - XMC_CCU8_SLICE_SetPrescaler() changed div_val parameter to type XMC_CCU8_SLICE_PRESCALER_t
66  *
67  * @endcond
68  */
69 /*********************************************************************************************************************
70  * HEADER FILES
71  ********************************************************************************************************************/
72 #include "xmc_ccu8.h"
73 
74 #if defined(CCU80)
75 #include "xmc_scu.h"
76 
77 /*********************************************************************************************************************
78  * MACROS
79  ********************************************************************************************************************/
80 #define XMC_CCU8_NUM_SLICES_PER_MODULE          (4U)
81 #define XMC_CCU8_SLICE_DITHER_PERIOD_MASK       (1U)
82 #define XMC_CCU8_SLICE_DITHER_DUTYCYCLE_MASK    (2U)
83 #define XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK   (3U)
84 #define XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK  (1U)
85 #define XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK (3U)
86 #if defined(CCU8V3) /* Defined for XMC1400 devices */
87 #define XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK  CCU8_CC8_INS1_EV0IS_Msk
88 #else
89 #define XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK  CCU8_CC8_INS_EV0IS_Msk
90 #endif
91 #define XMC_CCU8_GIDLC_CLOCK_MASK               (15U)
92 #define XMC_CCU8_GCSS_SLICE0_MASK               (1U)
93 #define XMC_CCU8_GCSS_SLICE1_MASK               (16U)
94 #define XMC_CCU8_GCSS_SLICE2_MASK               (256U)
95 #define XMC_CCU8_GCSS_SLICE3_MASK               (4096U)
96 #define XMC_CCU8_SLICE_DEAD_TIME_CONFIG_MASK    (63U)
97 #if !defined(CCU8V3) /* Defined for all devices except XMC1400 */
98 #define XMC_CCU8_SLICE_CHC_CONFIG_MASK          (20U)
99 #endif
100 
101 #define XMC_CCU8_SLICE_CHECK_DTC_DIV(div) \
102     ((div == XMC_CCU8_SLICE_DTC_DIV_1) || \
103      (div == XMC_CCU8_SLICE_DTC_DIV_2) || \
104      (div == XMC_CCU8_SLICE_DTC_DIV_4) || \
105      (div == XMC_CCU8_SLICE_DTC_DIV_8))
106 
107 #define XMC_CCU8_SLICE_CHECK_CLOCK(clock) \
108     ((clock == XMC_CCU8_CLOCK_SCU)        || \
109      (clock == XMC_CCU8_CLOCK_EXTERNAL_A) || \
110      (clock == XMC_CCU8_CLOCK_EXTERNAL_B) || \
111      (clock == XMC_CCU8_CLOCK_EXTERNAL_C))
112 
113 #define XMC_CCU8_SLICE_CHECK_OUTPUT(out) \
114     ((out == XMC_CCU8_SLICE_OUTPUT_0) || \
115      (out == XMC_CCU8_SLICE_OUTPUT_1) || \
116      (out == XMC_CCU8_SLICE_OUTPUT_2) || \
117      (out == XMC_CCU8_SLICE_OUTPUT_3))
118 
119 #define XMC_CCU8_SLICE_CHECK_END_MODE(end_mode) \
120     ((end_mode == XMC_CCU8_SLICE_END_MODE_TIMER_STOP) || \
121      (end_mode == XMC_CCU8_SLICE_END_MODE_TIMER_CLEAR) || \
122      (end_mode == XMC_CCU8_SLICE_END_MODE_TIMER_STOP_CLEAR))
123 
124 #define XMC_CCU8_SLICE_CHECK_EVENT_ID(event_id) \
125     ((event_id == XMC_CCU8_SLICE_EVENT_NONE)|| \
126      (event_id == XMC_CCU8_SLICE_EVENT_0)   || \
127      (event_id == XMC_CCU8_SLICE_EVENT_1)   || \
128      (event_id == XMC_CCU8_SLICE_EVENT_2))
129 
130 #define XMC_CCU8_SLICE_CHECK_EDGE_SENSITIVITY(edge) \
131     ((edge == XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_NONE)        || \
132      (edge == XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE) || \
133      (edge == XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE)|| \
134      (edge == XMC_CCU8_SLICE_EVENT_EDGE_SENSITIVITY_DUAL_EDGE))
135 
136 #define XMC_CCU8_SLICE_CHECK_EVENT_FILTER(cycles) \
137     ((cycles == XMC_CCU8_SLICE_EVENT_FILTER_DISABLED) || \
138      (cycles == XMC_CCU8_SLICE_EVENT_FILTER_3_CYCLES) || \
139      (cycles == XMC_CCU8_SLICE_EVENT_FILTER_5_CYCLES) || \
140      (cycles == XMC_CCU8_SLICE_EVENT_FILTER_7_CYCLES))
141 
142 #define XMC_CCU8_SLICE_CHECK_CAP_TIMER_CLEAR_MODE(mode) \
143     ((mode == XMC_CCU8_SLICE_TIMER_CLEAR_MODE_NEVER)   || \
144      (mode == XMC_CCU8_SLICE_TIMER_CLEAR_MODE_CAP_HIGH)|| \
145      (mode == XMC_CCU8_SLICE_TIMER_CLEAR_MODE_CAP_LOW) || \
146      (mode == XMC_CCU8_SLICE_TIMER_CLEAR_MODE_ALWAYS))
147 
148 #define XMC_CCU8_SLICE_CHECK_MCS_ACTION(mcs_action) \
149     ((mcs_action == XMC_CCU8_SLICE_MCMS_ACTION_TRANSFER_PR_CR)      || \
150      (mcs_action == XMC_CCU8_SLICE_MCMS_ACTION_TRANSFER_PR_CR_PCMP) || \
151      (mcs_action == XMC_CCU8_SLICE_MCMS_ACTION_TRANSFER_PR_CR_PCMP_DIT))
152 
153 #define XMC_CCU8_SLICE_CHECK_SR_ID(id) \
154     ((id == XMC_CCU8_SLICE_SR_ID_0) || \
155      (id == XMC_CCU8_SLICE_SR_ID_1) || \
156      (id == XMC_CCU8_SLICE_SR_ID_2) || \
157      (id == XMC_CCU8_SLICE_SR_ID_3))
158 
159 #define XMC_CCU8_SLICE_CHECK_MODULATION_CHANNEL(channel) \
160     ((channel == XMC_CCU8_SLICE_MODULATION_CHANNEL_NONE) || \
161      (channel == XMC_CCU8_SLICE_MODULATION_CHANNEL_1)    || \
162      (channel == XMC_CCU8_SLICE_MODULATION_CHANNEL_2)    || \
163      (channel == XMC_CCU8_SLICE_MODULATION_CHANNEL_1_AND_2))
164 
165 #if((UC_SERIES == XMC13) || (UC_SERIES == XMC14))
166 #define XMC_CCU8_SLICE_CHECK_SLICE_STATUS(channel) \
167     ((channel == XMC_CCU8_SLICE_STATUS_CHANNEL_1)       || \
168      (channel == XMC_CCU8_SLICE_STATUS_CHANNEL_2)       || \
169      (channel == XMC_CCU8_SLICE_STATUS_CHANNEL_1_AND_2) || \
170      (channel == XMC_CCU8_SLICE_STATUS_CHANNEL_1_OR_2))
171 #else
172 #define XMC_CCU8_SLICE_CHECK_SLICE_STATUS(channel) \
173     ((channel == XMC_CCU8_SLICE_STATUS_CHANNEL_1)       || \
174      (channel == XMC_CCU8_SLICE_STATUS_CHANNEL_2)       || \
175      (channel == XMC_CCU8_SLICE_STATUS_CHANNEL_1_AND_2))
176 #endif
177 
178 /*********************************************************************************************************************
179  * LOCAL ROUTINES
180  ********************************************************************************************************************/
181 #if defined(PERIPHERAL_RESET_SUPPORTED)
XMC_CCU8_lAssertReset(const XMC_CCU8_MODULE_t * const module)182 __STATIC_INLINE void XMC_CCU8_lAssertReset(const XMC_CCU8_MODULE_t *const module)
183 {
184   if (module == CCU80)
185   {
186     XMC_SCU_RESET_AssertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_CCU80);
187   }
188 #if defined(CCU81)
189   else if (module == CCU81)
190   {
191     XMC_SCU_RESET_AssertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_CCU81);
192   }
193 #endif
194   else
195   {
196     XMC_ASSERT("XMC_CCU8_lAssertReset:Invalid Module Pointer", 0);
197   }
198 }
199 
XMC_CCU8_lDeassertReset(const XMC_CCU8_MODULE_t * const module)200 __STATIC_INLINE void XMC_CCU8_lDeassertReset(const XMC_CCU8_MODULE_t *const module)
201 {
202   if (module == CCU80)
203   {
204     XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_CCU80);
205   }
206 #if defined(CCU81)
207   else if (module == CCU81)
208   {
209     XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_CCU81);
210   }
211 #endif
212   else
213   {
214     XMC_ASSERT("XMC_CCU8_lDeassertReset:Invalid Module Pointer", 0);
215   }
216 }
217 #endif
218 
219 #if defined(CLOCK_GATING_SUPPORTED)
XMC_CCU8_lGateClock(XMC_CCU8_MODULE_t * const module)220 __STATIC_INLINE void XMC_CCU8_lGateClock(XMC_CCU8_MODULE_t *const module)
221 {
222   if (module == CCU80)
223   {
224     XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_CCU80);
225   }
226 #if defined(CCU81)
227   else if (module == CCU81)
228   {
229     XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_CCU81);
230   }
231 #endif
232   else
233   {
234     XMC_ASSERT("XMC_CCU8_lGateClock:Invalid Module Pointer", 0);
235   }
236 }
237 
XMC_CCU8_lUngateClock(XMC_CCU8_MODULE_t * const module)238 __STATIC_INLINE void XMC_CCU8_lUngateClock(XMC_CCU8_MODULE_t *const module)
239 {
240   if (module == CCU80)
241   {
242     XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_CCU80);
243   }
244 #if defined(CCU81)
245   else if (module == CCU81)
246   {
247     XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_CCU81);
248   }
249 #endif
250   else
251   {
252     XMC_ASSERT("XMC_CCU8_lUngateClock:Invalid Module Pointer", 0);
253   }
254 }
255 #endif
256 
257 #if defined (XMC_ASSERT_ENABLE)
XMC_CCU8_SLICE_IsInputvalid(XMC_CCU8_SLICE_INPUT_t input)258 __STATIC_INLINE bool XMC_CCU8_SLICE_IsInputvalid(XMC_CCU8_SLICE_INPUT_t input)
259 {
260 #if (UC_SERIES == XMC14)
261   return (input < 48U);
262 #else
263   return (input < 16U);
264 #endif
265 }
266 #endif
267 /*********************************************************************************************************************
268  * API IMPLEMENTATION
269  ********************************************************************************************************************/
270 
271 /* API to set the CCU8 module as active and enable the clock  */
XMC_CCU8_EnableModule(XMC_CCU8_MODULE_t * const module)272 void XMC_CCU8_EnableModule(XMC_CCU8_MODULE_t *const module)
273 {
274   XMC_ASSERT("XMC_CCU8_EnableModule:Invalid Module Pointer", XMC_CCU8_IsValidModule(module));
275 
276 #if (UC_FAMILY == XMC4)
277   /* Enable CCU8 module clock */
278   XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_CCU);
279 #endif
280 
281 #if defined(CLOCK_GATING_SUPPORTED)
282   XMC_CCU8_lUngateClock(module);
283 #endif
284 
285 #if defined(PERIPHERAL_RESET_SUPPORTED)
286   XMC_CCU8_lDeassertReset(module);
287 #endif
288 }
289 
290 /* API to set the CCU8 module as idle and disable the clock  */
XMC_CCU8_DisableModule(XMC_CCU8_MODULE_t * const module)291 void XMC_CCU8_DisableModule(XMC_CCU8_MODULE_t *const module)
292 {
293   XMC_ASSERT("XMC_CCU8_DisableModule:Invalid Module Pointer", XMC_CCU8_IsValidModule(module));
294 
295 #if defined(PERIPHERAL_RESET_SUPPORTED)
296   XMC_CCU8_lAssertReset(module);
297 #endif
298 
299 #if defined(CLOCK_GATING_SUPPORTED)
300   XMC_CCU8_lGateClock(module);
301 #endif
302 }
303 
304 /* API to initialize CCU8 global resources  */
XMC_CCU8_Init(XMC_CCU8_MODULE_t * const module,const XMC_CCU8_SLICE_MCMS_ACTION_t mcs_action)305 void XMC_CCU8_Init(XMC_CCU8_MODULE_t *const module, const XMC_CCU8_SLICE_MCMS_ACTION_t mcs_action)
306 {
307   uint32_t gctrl;
308 
309   XMC_ASSERT("XMC_CCU8_Init:Invalid Module Pointer", XMC_CCU8_IsValidModule(module));
310   XMC_ASSERT("XMC_CCU8_Init:Invalid mcs action", XMC_CCU8_SLICE_CHECK_MCS_ACTION(mcs_action));
311 
312   /* Enable CCU8 module */
313   XMC_CCU8_EnableModule(module);
314   /* Start the prescaler */
315   XMC_CCU8_StartPrescaler(module);
316 
317   gctrl = module->GCTRL;
318   gctrl &= ~((uint32_t) CCU8_GCTRL_MSDE_Msk);
319   gctrl |= (uint32_t)mcs_action << CCU8_GCTRL_MSDE_Pos;
320 
321   module->GCTRL = gctrl;
322 }
323 
324 /* API to select CCU8 module clock */
XMC_CCU8_SetModuleClock(XMC_CCU8_MODULE_t * const module,const XMC_CCU8_CLOCK_t clock)325 void XMC_CCU8_SetModuleClock(XMC_CCU8_MODULE_t *const module, const XMC_CCU8_CLOCK_t clock)
326 {
327   uint32_t gctrl;
328 
329   XMC_ASSERT("XMC_CCU8_SetModuleClock:Invalid Module Pointer", XMC_CCU8_IsValidModule(module));
330   XMC_ASSERT("XMC_CCU8_SetModuleClock:Invalid Module Clock", XMC_CCU8_SLICE_CHECK_CLOCK(clock));
331 
332   gctrl = module->GCTRL;
333   gctrl &= ~((uint32_t) CCU8_GCTRL_PCIS_Msk);
334   gctrl |= ((uint32_t) clock) << CCU8_GCTRL_PCIS_Pos;
335 
336   module->GCTRL = gctrl;
337 }
338 
339 /* API to configure CC8 Slice in Compare mode */
XMC_CCU8_SLICE_CompareInit(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_COMPARE_CONFIG_t * const compare_init)340 void XMC_CCU8_SLICE_CompareInit(XMC_CCU8_SLICE_t *const slice,
341                                 const XMC_CCU8_SLICE_COMPARE_CONFIG_t *const compare_init)
342 {
343   XMC_ASSERT("XMC_CCU8_SLICE_CompareInit:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
344   XMC_ASSERT("XMC_CCU8_SLICE_CompareInit:Timer Init Pointer is NULL",
345              (XMC_CCU8_SLICE_COMPARE_CONFIG_t *) NULL != compare_init);
346   /* Stops the timer */
347   XMC_CCU8_SLICE_StopTimer(slice);
348   /* Program the timer mode */
349   slice->TC = compare_init->tc;
350   /* Enable the timer concatenation */
351   slice->CMC =  (uint32_t)compare_init->timer_concatenation << CCU8_CC8_CMC_TCE_Pos;
352   /* Program initial prescaler divider value */
353   slice->PSC = (uint32_t) compare_init->prescaler_initval;
354   /* Program floating prescaler compare value */
355   slice->FPCS = (uint32_t) compare_init->float_limit;
356   /* Program the dither compare value */
357   slice->DITS = (uint32_t) compare_init->dither_limit;
358   /* Program timer output passive level */
359   slice->PSL = (uint32_t) compare_init->psl;
360   /* Asymmetric PWM and Slice output routing configuration */
361 #if defined(CCU8V3) /* Defined for XMC1400 devices only */
362   slice->CHC = (uint32_t) compare_init->chc;
363 #else
364   slice->CHC = (uint32_t)((uint32_t)compare_init->chc ^ XMC_CCU8_SLICE_CHC_CONFIG_MASK);
365 #endif
366 }
367 
368 /* API to configure CC8 Slice in Capture mode */
XMC_CCU8_SLICE_CaptureInit(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_CAPTURE_CONFIG_t * const capture_init)369 void XMC_CCU8_SLICE_CaptureInit(XMC_CCU8_SLICE_t *const slice,
370                                 const XMC_CCU8_SLICE_CAPTURE_CONFIG_t *const capture_init)
371 {
372   XMC_ASSERT("XMC_CCU8_SLICE_CaptureInit:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
373   XMC_ASSERT("XMC_CCU8_SLICE_CaptureInit:Capture Init Pointer is NULL",
374              (XMC_CCU8_SLICE_CAPTURE_CONFIG_t *) NULL != capture_init);
375   /* Stops the timer */
376   XMC_CCU8_SLICE_StopTimer(slice);
377   /* Capture mode configuration */
378   slice->TC = capture_init->tc;
379   /* Enable the timer concatenation */
380   slice->CMC = (uint32_t)capture_init->timer_concatenation << CCU8_CC8_CMC_TCE_Pos;
381   /* Program floating prescaler compare value */
382   slice->FPCS = (uint32_t) capture_init->float_limit;
383   /* Program initial prescaler divider value */
384   slice->PSC = (uint32_t) capture_init->prescaler_initval;
385 }
386 
387 /* API to configure the each output of the slice with either STx or inverted STx. */
XMC_CCU8_SLICE_SetOutPath(XMC_CCU8_SLICE_t * const slice,const uint32_t out_path_msk)388 void XMC_CCU8_SLICE_SetOutPath(XMC_CCU8_SLICE_t *const slice, const uint32_t out_path_msk)
389 {
390   uint32_t chc;
391   XMC_ASSERT("XMC_CCU8_SLICE_SetOutPath:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
392   chc = slice->CHC;
393 #if !defined(CCU8V3) /* Defined for all devices except XMC1400 */
394   chc &= ~((uint32_t)out_path_msk >> 16U);
395   chc |= ((uint32_t)out_path_msk & 0xFFFFU);
396 #else
397   chc &= ~((uint32_t)((uint32_t)(out_path_msk & 0xCCCC0U) >> 2U));
398   chc |= ((uint32_t)out_path_msk & 0x33330U);
399 #endif
400   slice->CHC = chc;
401 }
402 
403 /* API to configure the multichannel shadow transfer request via SW and via the CCU8x.MCSS input. */
XMC_CCU8_SetMultiChannelShadowTransferMode(XMC_CCU8_MODULE_t * const module,const uint32_t slice_mode_msk)404 void XMC_CCU8_SetMultiChannelShadowTransferMode(XMC_CCU8_MODULE_t *const module, const uint32_t slice_mode_msk)
405 {
406   uint32_t gctrl;
407 
408   XMC_ASSERT("XMC_CCU8_SetMultiChannelShadowTransferMode:Invalid module Pointer", XMC_CCU8_IsValidModule(module));
409 
410   gctrl = module->GCTRL;
411   gctrl &= ~((uint32_t)slice_mode_msk >> 16U);
412   gctrl |= ((uint32_t)slice_mode_msk & 0xFFFFU);
413   module->GCTRL = gctrl;
414 }
415 
416 
417 /* API to configure the Start trigger function of a slice*/
XMC_CCU8_SLICE_StartConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event,const XMC_CCU8_SLICE_START_MODE_t start_mode)418 void XMC_CCU8_SLICE_StartConfig(XMC_CCU8_SLICE_t *const slice,
419                                 const XMC_CCU8_SLICE_EVENT_t event,
420                                 const XMC_CCU8_SLICE_START_MODE_t start_mode)
421 {
422   uint32_t cmc;
423   uint32_t tc;
424 
425   XMC_ASSERT("XMC_CCU8_SLICE_StartConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
426   XMC_ASSERT("XMC_CCU8_SLICE_StartConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
427   XMC_ASSERT("XMC_CCU8_SLICE_StartConfig:Invalid Start Mode",
428              ((start_mode == XMC_CCU8_SLICE_START_MODE_TIMER_START) ||\
429               (start_mode == XMC_CCU8_SLICE_START_MODE_TIMER_START_CLEAR)));
430   cmc = slice->CMC;
431 
432   cmc &= ~((uint32_t) CCU8_CC8_CMC_STRTS_Msk);
433   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_STRTS_Pos;
434 
435   slice->CMC = cmc;
436 
437   tc  = slice->TC;
438 
439   if(start_mode == XMC_CCU8_SLICE_START_MODE_TIMER_START_CLEAR)
440   {
441     tc |= (uint32_t) CCU8_CC8_TC_STRM_Msk;
442   }
443   else
444   {
445     tc &= ~((uint32_t) CCU8_CC8_TC_STRM_Msk);
446   }
447 
448   slice->TC = tc;
449 }
450 
451 /* API to configure the Stop trigger function of a slice */
XMC_CCU8_SLICE_StopConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event,const XMC_CCU8_SLICE_END_MODE_t end_mode)452 void XMC_CCU8_SLICE_StopConfig(XMC_CCU8_SLICE_t *const slice,
453                                const XMC_CCU8_SLICE_EVENT_t event,
454                                const XMC_CCU8_SLICE_END_MODE_t end_mode)
455 {
456   uint32_t cmc;
457   uint32_t tc;
458 
459   XMC_ASSERT("XMC_CCU8_SLICE_StopConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
460   XMC_ASSERT("XMC_CCU8_SLICE_StopConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
461   XMC_ASSERT("XMC_CCU8_SLICE_StopConfig:Invalid End Mode", XMC_CCU8_SLICE_CHECK_END_MODE(end_mode));
462 
463   cmc = slice->CMC;
464   /* First, Bind the event with the stop function */
465   cmc &= ~((uint32_t) CCU8_CC8_CMC_ENDS_Msk);
466   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_ENDS_Pos;
467 
468   slice->CMC = cmc;
469 
470   /* Configure the stop mode */
471   tc = slice->TC;
472   tc &= ~((uint32_t) CCU8_CC8_TC_ENDM_Msk);
473   tc |= ((uint32_t) end_mode) << CCU8_CC8_TC_ENDM_Pos;
474 
475   slice->TC = tc;
476 }
477 
478 /* API to configure the Load trigger function of a slice*/
XMC_CCU8_SLICE_LoadConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)479 void XMC_CCU8_SLICE_LoadConfig(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
480 {
481   uint32_t cmc;
482 
483   XMC_ASSERT("XMC_CCU8_SLICE_LoadConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
484   XMC_ASSERT("XMC_CCU8_SLICE_LoadConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
485 
486   cmc = slice->CMC;
487 
488   /* First, Bind the event with the load function */
489   cmc &= ~((uint32_t) CCU8_CC8_CMC_LDS_Msk);
490   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_LDS_Pos;
491 
492   slice->CMC = cmc;
493 }
494 
495 /* API to configure, which compare register value has to be loaded during external load event */
XMC_CCU8_SLICE_LoadSelector(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_COMPARE_CHANNEL_t ch_num)496 void XMC_CCU8_SLICE_LoadSelector(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_COMPARE_CHANNEL_t ch_num)
497 {
498   uint32_t tc;
499 
500   XMC_ASSERT("XMC_CCU8_SLICE_LoadSelector:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
501   XMC_ASSERT("XMC_CCU8_SLICE_LoadSelector:Invalid Channel number", XMC_CCU8_SLICE_CHECK_COMP_CHANNEL(ch_num));
502 
503   tc = slice->TC;
504 
505   /* First, Bind the event with the load function */
506   tc &= ~((uint32_t) CCU8_CC8_TC_TLS_Msk);
507   tc |= (uint32_t)ch_num << CCU8_CC8_TC_TLS_Pos;
508 
509   slice->TC = tc;
510 }
511 
512 /* API to configure the slice modulation function */
XMC_CCU8_SLICE_ModulationConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event,const XMC_CCU8_SLICE_MODULATION_MODE_t mod_mode,const XMC_CCU8_SLICE_MODULATION_CHANNEL_t channel,const bool synch_with_pwm)513 void XMC_CCU8_SLICE_ModulationConfig(XMC_CCU8_SLICE_t *const slice,
514                                      const XMC_CCU8_SLICE_EVENT_t event,
515                                      const XMC_CCU8_SLICE_MODULATION_MODE_t mod_mode,
516                                      const XMC_CCU8_SLICE_MODULATION_CHANNEL_t channel,
517                                      const bool synch_with_pwm)
518 {
519   uint32_t cmc;
520   uint32_t tc;
521 
522   XMC_ASSERT("XMC_CCU8_SLICE_ModulationConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
523   XMC_ASSERT("XMC_CCU8_SLICE_ModulationConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
524   XMC_ASSERT("XMC_CCU8_SLICE_ModulationConfig:Invalid channel for modulation",
525              XMC_CCU8_SLICE_CHECK_MODULATION_CHANNEL(channel));
526   XMC_ASSERT("XMC_CCU8_SLICE_ModulationConfig:Invalid Modulation Mode",
527              ((mod_mode == XMC_CCU8_SLICE_MODULATION_MODE_CLEAR_ST_OUT) ||\
528               (mod_mode == XMC_CCU8_SLICE_MODULATION_MODE_CLEAR_OUT)));
529 
530   cmc = slice->CMC;
531 
532   /* First, Bind the event with the modulation function */
533   cmc &= ~((uint32_t) CCU8_CC8_CMC_MOS_Msk);
534   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_MOS_Pos;
535 
536   slice->CMC = cmc;
537 
538   tc  = slice->TC;
539 
540   /* Next, Modulation mode */
541   if(mod_mode == XMC_CCU8_SLICE_MODULATION_MODE_CLEAR_OUT)
542   {
543     tc |= (uint32_t) CCU8_CC8_TC_EMT_Msk;
544   }
545   else
546   {
547     tc &= ~((uint32_t) CCU8_CC8_TC_EMT_Msk);
548   }
549 
550   /* Synchronization of modulation effect with PWM cycle */
551   if(synch_with_pwm == true)
552   {
553     tc |= (uint32_t) CCU8_CC8_TC_EMS_Msk;
554   }
555   else
556   {
557     tc &= ~((uint32_t) CCU8_CC8_TC_EMS_Msk);
558   }
559 
560   /* Configure on which channel external modulation to be applied */
561   tc &= ~((uint32_t) CCU8_CC8_TC_EME_Msk);
562   tc |= (uint32_t)channel << CCU8_CC8_TC_EME_Pos;
563 
564   slice->TC = tc;
565 }
566 
567 /* API to configure the slice count function */
XMC_CCU8_SLICE_CountConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)568 void XMC_CCU8_SLICE_CountConfig(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
569 {
570   uint32_t cmc;
571 
572   XMC_ASSERT("XMC_CCU8_SLICE_CountConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
573   XMC_ASSERT("XMC_CCU8_SLICE_CountConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
574 
575   cmc = slice->CMC;
576 
577   /* First, Bind the event with the count function */
578   cmc &= ~((uint32_t) CCU8_CC8_CMC_CNTS_Msk);
579   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_CNTS_Pos;
580 
581   slice->CMC = cmc;
582 }
583 
584 /* API to configure slice gate function */
XMC_CCU8_SLICE_GateConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)585 void XMC_CCU8_SLICE_GateConfig(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
586 {
587   uint32_t cmc;
588 
589   XMC_ASSERT("XMC_CCU8_SLICE_GateConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
590   XMC_ASSERT("XMC_CCU8_SLICE_GateConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
591 
592   cmc = slice->CMC;
593 
594   /* First, Bind the event with the gate function */
595   cmc &= ~((uint32_t) CCU8_CC8_CMC_GATES_Msk);
596   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_GATES_Pos;
597 
598   slice->CMC = cmc;
599 }
600 
601 /* API to configure Capture-0 function */
XMC_CCU8_SLICE_Capture0Config(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)602 void XMC_CCU8_SLICE_Capture0Config(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
603 {
604   uint32_t cmc;
605 
606   XMC_ASSERT("XMC_CCU8_SLICE_Capture0Config:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
607   XMC_ASSERT("XMC_CCU8_SLICE_Capture0Config:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
608 
609   cmc = slice->CMC;
610 
611   /* First, Bind the event with the gate function */
612   cmc &= ~((uint32_t) CCU8_CC8_CMC_CAP0S_Msk);
613   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_CAP0S_Pos;
614 
615   slice->CMC = cmc;
616 }
617 
618 /* API to configure Capture-1 function */
XMC_CCU8_SLICE_Capture1Config(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)619 void XMC_CCU8_SLICE_Capture1Config(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
620 {
621   uint32_t cmc;
622 
623   XMC_ASSERT("XMC_CCU8_SLICE_Capture1Config:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
624   XMC_ASSERT("XMC_CCU8_SLICE_Capture1Config:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
625 
626 
627   cmc = slice->CMC;
628 
629   /* First, Bind the event with the gate function */
630   cmc &= ~((uint32_t) CCU8_CC8_CMC_CAP1S_Msk);
631   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_CAP1S_Pos;
632 
633   slice->CMC = cmc;
634 }
635 
636 /* API to configure direction function */
XMC_CCU8_SLICE_DirectionConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event)637 void XMC_CCU8_SLICE_DirectionConfig(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_EVENT_t event)
638 {
639   uint32_t cmc;
640 
641   XMC_ASSERT("XMC_CCU8_SLICE_DirectionConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
642   XMC_ASSERT("XMC_CCU8_SLICE_DirectionConfig:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
643 
644   cmc = slice->CMC;
645 
646   /* First, Bind the event with the direction function */
647   cmc &= ~((uint32_t) CCU8_CC8_CMC_UDS_Msk);
648   cmc |= ((uint32_t) event) << CCU8_CC8_CMC_UDS_Pos;
649 
650   slice->CMC = cmc;
651 }
652 
653 /* API to configure slice status bit override function */
XMC_CCU8_SLICE_StatusBitOverrideConfig(XMC_CCU8_SLICE_t * const slice)654 void XMC_CCU8_SLICE_StatusBitOverrideConfig(XMC_CCU8_SLICE_t *const slice)
655 {
656   uint32_t cmc;
657 
658   XMC_ASSERT("XMC_CCU8_SLICE_StatusBitOverrideConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
659 
660   cmc = slice->CMC;
661 
662   /* Map status bit trigger override to Event 1 &
663          status bit value override to Event 2 */
664   cmc &= ~((uint32_t) CCU8_CC8_CMC_OFS_Msk);
665   cmc |= ((uint32_t) 1) << CCU8_CC8_CMC_OFS_Pos;
666 
667   slice->CMC = cmc;
668 }
669 
670 /* API to configure trap function*/
XMC_CCU8_SLICE_TrapConfig(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_TRAP_EXIT_MODE_t exit_mode,const bool synch_with_pwm)671 void XMC_CCU8_SLICE_TrapConfig(XMC_CCU8_SLICE_t *const slice,
672                                const XMC_CCU8_SLICE_TRAP_EXIT_MODE_t exit_mode,
673                                const bool synch_with_pwm)
674 {
675   uint32_t cmc;
676   uint32_t tc;
677 
678   XMC_ASSERT("XMC_CCU8_SLICE_TrapConfig:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
679   XMC_ASSERT("XMC_CCU8_SLICE_TrapConfig:Invalid Exit Mode", ((exit_mode == XMC_CCU8_SLICE_TRAP_EXIT_MODE_AUTOMATIC) ||\
680                                                              (exit_mode == XMC_CCU8_SLICE_TRAP_EXIT_MODE_SW)));
681 
682   cmc = slice->CMC;
683 
684   /* Map trap function to Event 2 */
685   cmc &= ~((uint32_t) CCU8_CC8_CMC_TS_Msk);
686   cmc |= ((uint32_t) 1) << CCU8_CC8_CMC_TS_Pos;
687 
688   slice->CMC = cmc;
689 
690   tc = slice->TC;
691 
692   /* Configure synchronization option */
693   if(synch_with_pwm == true)
694   {
695     tc |= (uint32_t) CCU8_CC8_TC_TRPSE_Msk;
696   }
697   else
698   {
699     tc &= ~((uint32_t) CCU8_CC8_TC_TRPSE_Msk);
700   }
701 
702   /* Configure exit mode */
703   if(exit_mode == XMC_CCU8_SLICE_TRAP_EXIT_MODE_SW)
704   {
705     tc |= (uint32_t) CCU8_CC8_TC_TRPSW_Msk;
706   }
707   else
708   {
709     tc &= ~((uint32_t) CCU8_CC8_TC_TRPSW_Msk);
710   }
711 
712   slice->TC = tc;
713 }
714 
715 /* API to configure a slice Status Bit Override event */
XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_CONFIG_t * const ev1_config,const XMC_CCU8_SLICE_EVENT_CONFIG_t * const ev2_config)716 void XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent(XMC_CCU8_SLICE_t *const slice,
717                                                     const XMC_CCU8_SLICE_EVENT_CONFIG_t *const ev1_config,
718                                                     const XMC_CCU8_SLICE_EVENT_CONFIG_t *const ev2_config)
719 {
720   uint32_t ins;
721 
722   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
723   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Input",
724          XMC_CCU8_SLICE_IsInputvalid(ev1_config->mapped_input));
725   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Edge Sensitivity",
726              XMC_CCU8_SLICE_CHECK_EDGE_SENSITIVITY(ev1_config->edge));
727   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Level Sensitivity",
728              ((ev1_config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH) ||\
729               (ev1_config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_LOW)));
730   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Debounce Period",
731               XMC_CCU8_SLICE_CHECK_EVENT_FILTER(ev1_config->duration));
732   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Input",
733           XMC_CCU8_SLICE_IsInputvalid(ev2_config->mapped_input));
734   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Edge Sensitivity",
735               XMC_CCU8_SLICE_CHECK_EDGE_SENSITIVITY(ev2_config->edge));
736   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Level Sensitivity",
737              ((ev2_config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH) ||\
738               (ev2_config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_LOW)));
739   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOverrideEvent:Invalid Debounce Period",
740              XMC_CCU8_SLICE_CHECK_EVENT_FILTER(ev2_config->duration));
741 
742 #if defined(CCU8V3) /* Defined for XMC1400 devices only */
743   ins = slice->INS2;
744 
745   /* Configure the edge sensitivity for event 1 */
746   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << CCU8_CC8_INS2_EV1EM_Pos);
747   ins |= ((uint32_t) ev1_config->edge) << CCU8_CC8_INS2_EV1EM_Pos;
748 
749   /* Configure the edge sensitivity for event 2 */
750   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << CCU8_CC8_INS2_EV2EM_Pos);
751   ins |= ((uint32_t) ev2_config->edge) << CCU8_CC8_INS2_EV2EM_Pos;
752 
753   /* Configure the level sensitivity for event 1 */
754   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << CCU8_CC8_INS2_EV1LM_Pos);
755   ins |= ((uint32_t) ev1_config->level) << CCU8_CC8_INS2_EV1LM_Pos;
756 
757   /* Configure the level sensitivity for event 2 */
758   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << CCU8_CC8_INS2_EV2LM_Pos);
759   ins |= ((uint32_t) ev2_config->level) << CCU8_CC8_INS2_EV2LM_Pos;
760 
761   /* Configure the debounce filter for event 1 */
762   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << CCU8_CC8_INS2_LPF1M_Pos);
763   ins |= ((uint32_t) ev1_config->duration) << CCU8_CC8_INS2_LPF1M_Pos;
764 
765   /* Configure the debounce filter for event 2 */
766   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << CCU8_CC8_INS2_LPF2M_Pos);
767   ins |= ((uint32_t) ev2_config->duration) << CCU8_CC8_INS2_LPF2M_Pos;
768 
769   slice->INS2 = ins;
770 
771   ins = slice->INS1;
772   /* Next, the input for Event1 */
773   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << CCU8_CC8_INS1_EV1IS_Pos);
774   ins |= ((uint32_t) ev1_config->mapped_input) << CCU8_CC8_INS1_EV1IS_Pos;
775 
776   /* Finally, the input for Event2 */
777   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << CCU8_CC8_INS1_EV2IS_Pos);
778   ins |= ((uint32_t) ev2_config->mapped_input) << CCU8_CC8_INS1_EV2IS_Pos;
779 
780   slice->INS1 = ins;
781 #else
782   ins = slice->INS;
783 
784   /* Configure the edge sensitivity for event 1 */
785   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << CCU8_CC8_INS_EV1EM_Pos);
786   ins |= ((uint32_t) ev1_config->edge) << CCU8_CC8_INS_EV1EM_Pos;
787 
788   /* Configure the edge sensitivity for event 2 */
789   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << CCU8_CC8_INS_EV2EM_Pos);
790   ins |= ((uint32_t) ev2_config->edge) << CCU8_CC8_INS_EV2EM_Pos;
791 
792   /* Configure the level sensitivity for event 1 */
793   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << CCU8_CC8_INS_EV1LM_Pos);
794   ins |= ((uint32_t) ev1_config->level) << CCU8_CC8_INS_EV1LM_Pos;
795 
796   /* Configure the level sensitivity for event 2 */
797   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << CCU8_CC8_INS_EV2LM_Pos);
798   ins |= ((uint32_t) ev2_config->level) << CCU8_CC8_INS_EV2LM_Pos;
799 
800   /* Configure the debounce filter for event 1 */
801   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << CCU8_CC8_INS_LPF1M_Pos);
802   ins |= ((uint32_t) ev1_config->duration) << CCU8_CC8_INS_LPF1M_Pos;
803 
804   /* Configure the debounce filter for event 2 */
805   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << CCU8_CC8_INS_LPF2M_Pos);
806   ins |= ((uint32_t) ev2_config->duration) << CCU8_CC8_INS_LPF2M_Pos;
807 
808   /* Next, the input for Event1 */
809   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << CCU8_CC8_INS_EV1IS_Pos);
810   ins |= ((uint32_t) ev1_config->mapped_input) << CCU8_CC8_INS_EV1IS_Pos;
811 
812   /* Finally, the input for Event2 */
813   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << CCU8_CC8_INS_EV2IS_Pos);
814   ins |= ((uint32_t) ev2_config->mapped_input) << CCU8_CC8_INS_EV2IS_Pos;
815 
816   slice->INS = ins;
817 #endif
818 }
819 
820 /* API to configure a slice trigger event */
XMC_CCU8_SLICE_ConfigureEvent(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event,const XMC_CCU8_SLICE_EVENT_CONFIG_t * const config)821 void XMC_CCU8_SLICE_ConfigureEvent(XMC_CCU8_SLICE_t *const slice,
822                                    const XMC_CCU8_SLICE_EVENT_t event,
823                                    const XMC_CCU8_SLICE_EVENT_CONFIG_t *const config)
824 {
825   uint32_t ins;
826   uint8_t  pos;
827   uint8_t  offset;
828 
829   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
830   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
831   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Input",  XMC_CCU8_SLICE_IsInputvalid(config->mapped_input));
832   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Edge Sensitivity",
833              XMC_CCU8_SLICE_CHECK_EDGE_SENSITIVITY(config->edge));
834   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Level Sensitivity",
835              ((config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH) ||\
836               (config->level == XMC_CCU8_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_LOW)));
837   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureEvent:Invalid Debounce Period",
838              XMC_CCU8_SLICE_CHECK_EVENT_FILTER(config->duration));
839 
840   /* Calculate offset with reference to event */
841   offset = ((uint8_t) event) - 1U;
842 
843 #if defined(CCU8V3) /* Defined for XMC1400 devices only */
844   ins = slice->INS2;
845 
846   /* First, configure the edge sensitivity */
847   pos = ((uint8_t) CCU8_CC8_INS2_EV0EM_Pos) + (uint8_t)(offset << 2U);
848   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << pos);
849   ins |= ((uint32_t) config->edge) << pos;
850 
851   /* Next, the level */
852   pos = ((uint8_t) CCU8_CC8_INS2_EV0LM_Pos) + (uint8_t)(offset << 2U);
853   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << pos);
854   ins |= ((uint32_t) (config->level)) << pos;
855 
856   /* Next, the debounce filter */
857   pos = ((uint8_t) CCU8_CC8_INS2_LPF0M_Pos) + (uint8_t)(offset << 2U);
858   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << pos);
859   ins |= ((uint32_t) config->duration) << pos;
860 
861   slice->INS2 = ins;
862 
863   ins = slice->INS1;
864 
865   /* Finally the input */
866   pos = ((uint8_t) CCU8_CC8_INS1_EV0IS_Pos) + (uint8_t)(offset << 3U);
867   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << pos);
868   ins |= ((uint32_t) config->mapped_input) << pos;
869 
870   slice->INS1 = ins;
871 
872 #else
873   ins = slice->INS;
874 
875   /* First, configure the edge sensitivity */
876   pos = ((uint8_t) CCU8_CC8_INS_EV0EM_Pos) + (uint8_t)(offset << 1U);
877   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_EDGE_CONFIG_MASK) << pos);
878   ins |= ((uint32_t) config->edge) << pos;
879 
880   /* Next, the level */
881   pos = ((uint8_t) CCU8_CC8_INS_EV0LM_Pos) + offset;
882   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_LEVEL_CONFIG_MASK) << pos);
883   ins |= ((uint32_t) (config->level)) << pos;
884 
885   /* Next, the debounce filter */
886   pos = ((uint8_t) CCU8_CC8_INS_LPF0M_Pos) + (uint8_t)(offset << 1U);
887   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_FILTER_CONFIG_MASK) << pos);
888   ins |= ((uint32_t) config->duration) << pos;
889 
890   /* Finally the input */
891   pos = ((uint8_t) CCU8_CC8_INS_EV0IS_Pos) + (uint8_t)(offset << 2U);
892   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << pos);
893   ins |= ((uint32_t) config->mapped_input) << pos;
894 
895   slice->INS = ins;
896 #endif
897 }
898 
899 /* API to bind an input to a slice trigger event */
XMC_CCU8_SLICE_SetInput(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_EVENT_t event,const XMC_CCU8_SLICE_INPUT_t input)900 void XMC_CCU8_SLICE_SetInput(XMC_CCU8_SLICE_t *const slice,
901                          const XMC_CCU8_SLICE_EVENT_t event,
902                              const XMC_CCU8_SLICE_INPUT_t input)
903 {
904   uint32_t ins;
905   uint8_t  pos;
906   uint8_t  offset;
907 
908   XMC_ASSERT("XMC_CCU8_SLICE_SetInput:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
909   XMC_ASSERT("XMC_CCU8_SLICE_SetInput:Invalid Event ID", XMC_CCU8_SLICE_CHECK_EVENT_ID(event));
910   XMC_ASSERT("XMC_CCU8_SLICE_SetInput:Invalid Input", XMC_CCU8_SLICE_IsInputvalid(input));
911 
912   /* Calculate offset with reference to event */
913   offset = ((uint8_t) event) - 1U;
914 
915 #if defined(CCU8V3) /* Defined for XMC1400 devices only */
916   pos = ((uint8_t) CCU8_CC8_INS1_EV0IS_Pos) + (uint8_t) (offset << 3U);
917   ins = slice->INS1;
918   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << pos);
919   ins |= ((uint32_t) input) << pos;
920 
921   slice->INS1 = ins;
922 #else
923 
924   pos = ((uint8_t) CCU8_CC8_INS_EV0IS_Pos) + (uint8_t) (offset << 2U);
925   ins = slice->INS;
926   ins &= ~(((uint32_t) XMC_CCU8_SLICE_EVENT_INPUT_CONFIG_MASK) << pos);
927   ins |= ((uint32_t) input) << pos;
928 
929   slice->INS = ins;
930 #endif
931 }
932 
933 /* API to program timer repeat mode - Single shot vs repeat  */
XMC_CCU8_SLICE_SetTimerRepeatMode(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_TIMER_REPEAT_MODE_t mode)934 void XMC_CCU8_SLICE_SetTimerRepeatMode(XMC_CCU8_SLICE_t *const slice,
935                                    const XMC_CCU8_SLICE_TIMER_REPEAT_MODE_t mode)
936 {
937   uint32_t tc;
938 
939   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerRepeatMode:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
940   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerRepeatMode:Invalid Timer Repeat Mode",
941              ((mode == XMC_CCU8_SLICE_TIMER_REPEAT_MODE_REPEAT) ||\
942               (mode == (mode == XMC_CCU8_SLICE_TIMER_REPEAT_MODE_REPEAT))));
943 
944   tc = slice->TC;
945 
946   if(XMC_CCU8_SLICE_TIMER_REPEAT_MODE_REPEAT == mode)
947   {
948     tc &= ~((uint32_t) CCU8_CC8_TC_TSSM_Msk);
949   }
950   else
951   {
952     tc |= (uint32_t) CCU8_CC8_TC_TSSM_Msk;
953   }
954 
955   slice->TC = tc;
956 }
957 
958 /* Programs timer counting mode  */
XMC_CCU8_SLICE_SetTimerCountingMode(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_TIMER_COUNT_MODE_t mode)959 void XMC_CCU8_SLICE_SetTimerCountingMode(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_TIMER_COUNT_MODE_t mode)
960 {
961   uint32_t tc;
962 
963   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerCountingMode:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
964   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerCountingMode:Invalid Timer Count Mode",
965              ((mode == XMC_CCU8_SLICE_TIMER_COUNT_MODE_EA) ||\
966               (mode == XMC_CCU8_SLICE_TIMER_COUNT_MODE_CA)));
967 
968   tc = slice->TC;
969 
970   if(XMC_CCU8_SLICE_TIMER_COUNT_MODE_EA == mode)
971   {
972     tc &= ~((uint32_t) CCU8_CC8_TC_TCM_Msk);
973   }
974   else
975   {
976     tc |= (uint32_t) CCU8_CC8_TC_TCM_Msk;
977   }
978 
979   slice->TC = tc;
980 }
981 
982 /* Programs period match value of the timer  */
XMC_CCU8_SLICE_SetTimerPeriodMatch(XMC_CCU8_SLICE_t * const slice,const uint16_t period_val)983 void XMC_CCU8_SLICE_SetTimerPeriodMatch(XMC_CCU8_SLICE_t *const slice, const uint16_t period_val)
984 {
985   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerPeriodMatch:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
986   slice->PRS = (uint32_t) period_val;
987 }
988 
989 /* Retrieves desired capture register value */
XMC_CCU8_SLICE_GetCaptureRegisterValue(const XMC_CCU8_SLICE_t * const slice,const uint8_t reg_num)990 uint32_t XMC_CCU8_SLICE_GetCaptureRegisterValue(const XMC_CCU8_SLICE_t *const slice, const uint8_t reg_num)
991 {
992   XMC_ASSERT("XMC_CCU8_SLICE_GetCaptureRegisterValue:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
993   XMC_ASSERT("XMC_CCU8_SLICE_GetCaptureRegisterValue:Invalid register number", (reg_num < 4U));
994   return(slice->CV[reg_num]);
995 }
996 
997 /* @brief Retrieves the latest captured timer value */
XMC_CCU8_SLICE_GetLastCapturedTimerValue(const XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_CAP_REG_SET_t set,uint32_t * val_ptr)998 XMC_CCU8_STATUS_t XMC_CCU8_SLICE_GetLastCapturedTimerValue(const XMC_CCU8_SLICE_t *const slice,
999                                                            const XMC_CCU8_SLICE_CAP_REG_SET_t set,
1000                                                            uint32_t *val_ptr)
1001 {
1002 
1003   XMC_CCU8_STATUS_t retval;
1004   uint8_t i;
1005   uint8_t start;
1006   uint8_t end;
1007 
1008   XMC_ASSERT("XMC_CCU8_SLICE_GetLastCapturedTimerValue:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1009   XMC_ASSERT("XMC_CCU8_SLICE_GetLastCapturedTimerValue:Invalid Register Set",
1010              ((set == XMC_CCU8_SLICE_CAP_REG_SET_LOW) ||\
1011               (set == XMC_CCU8_SLICE_CAP_REG_SET_HIGH)));
1012 
1013   retval = XMC_CCU8_STATUS_ERROR;
1014 
1015   /* First check if extended capture mode is enabled */
1016   if((slice->TC) & CCU8_CC8_TC_ECM_Msk)
1017   {
1018     /* Extended capture mode has been enabled. So start with the lowest capture register and work your way up */
1019     start = 0U;
1020     end = XMC_CCU8_NUM_SLICES_PER_MODULE;
1021   }
1022   else
1023   {
1024     /* Extended capture mode is not enabled */
1025     if(set == XMC_CCU8_SLICE_CAP_REG_SET_HIGH)
1026     {
1027       start = ((uint8_t) XMC_CCU8_NUM_SLICES_PER_MODULE) >> 1U;
1028       end   = (uint8_t) XMC_CCU8_NUM_SLICES_PER_MODULE;
1029     }
1030     else
1031     {
1032       start = 0U;
1033       end = ((uint8_t) XMC_CCU8_NUM_SLICES_PER_MODULE) >> 1U;
1034     }
1035   }
1036 
1037   for(i=start; i<end; i++)
1038   {
1039     if( (slice->CV[i]) & CCU8_CC8_CV_FFL_Msk )
1040     {
1041       *val_ptr = slice->CV[i];
1042       retval = XMC_CCU8_STATUS_OK;
1043       break;
1044     }
1045   }
1046 
1047   return retval;
1048 }
1049 /* Retrieves timer capture value from a FIFO made of capture registers */
1050 #if defined(CCU8V1) /* Defined for XMC4800, XMC4700, XMC4500, XMC4400, XMC4200, XMC4100 devices only */
XMC_CCU8_GetCapturedValueFromFifo(const XMC_CCU8_MODULE_t * const module,const uint8_t slice_number)1051 int32_t XMC_CCU8_GetCapturedValueFromFifo(const XMC_CCU8_MODULE_t *const module, const uint8_t slice_number)
1052 {
1053   int32_t  cap;
1054   uint32_t extracted_slice;
1055 
1056   XMC_ASSERT("XMC_CCU8_GetCapturedValueFromFifo:Invalid Slice Pointer", XMC_CCU8_IsValidModule(module));
1057 
1058   /* First read the global fifo register */
1059   cap = (int32_t) module->ECRD;
1060 
1061   extracted_slice = (((uint32_t) cap) & ((uint32_t) CCU8_ECRD_SPTR_Msk)) >> CCU8_ECRD_SPTR_Pos;
1062 
1063   /* Return captured result only if it were applicable to this slice */
1064   if(extracted_slice != ((uint32_t)slice_number))
1065   {
1066     cap = -1;
1067   }
1068 
1069   return (cap);
1070 }
1071 #else
1072 /* Retrieves timer capture value from a FIFO made of capture registers */
XMC_CCU8_SLICE_GetCapturedValueFromFifo(const XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_CAP_REG_SET_t set)1073 uint32_t XMC_CCU8_SLICE_GetCapturedValueFromFifo(const XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_CAP_REG_SET_t set)
1074 {
1075   uint32_t cap;
1076 
1077   XMC_ASSERT("XMC_CCU8_SLICE_GetCapturedValueFromFifo:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1078   XMC_ASSERT("XMC_CCU8_SLICE_GetCapturedValueFromFifo:Invalid Register Set",
1079              ((set == XMC_CCU8_SLICE_CAP_REG_SET_LOW) ||\
1080               (set == XMC_CCU8_SLICE_CAP_REG_SET_HIGH)));
1081 
1082   if(XMC_CCU8_SLICE_CAP_REG_SET_LOW == set)
1083   {
1084     cap = slice->ECRD0;
1085   }
1086   else
1087   {
1088     cap = slice->ECRD1;
1089   }
1090 
1091   return cap;
1092 }
1093 #endif
1094 
1095 /* Enables PWM dithering feature */
XMC_CCU8_SLICE_EnableDithering(XMC_CCU8_SLICE_t * const slice,const bool period_dither,const bool duty_dither,const uint8_t spread)1096 void XMC_CCU8_SLICE_EnableDithering(XMC_CCU8_SLICE_t *const slice,
1097                                     const bool period_dither,
1098                                     const bool duty_dither,
1099                                     const uint8_t spread)
1100 {
1101   uint32_t tc;
1102 
1103   XMC_ASSERT("XMC_CCU8_SLICE_EnableDithering:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1104 
1105   tc = slice->TC;
1106   tc &= ~((uint32_t) CCU8_CC8_TC_DITHE_Msk);
1107 
1108   if(true == period_dither)
1109   {
1110     tc |= (((uint32_t) XMC_CCU8_SLICE_DITHER_PERIOD_MASK) << CCU8_CC8_TC_DITHE_Pos);
1111   }
1112   if(true == duty_dither)
1113   {
1114     tc |= (((uint32_t) XMC_CCU8_SLICE_DITHER_DUTYCYCLE_MASK) << CCU8_CC8_TC_DITHE_Pos);
1115   }
1116 
1117   slice->TC = tc;
1118 
1119   XMC_CCU8_SLICE_SetDitherCompareValue((XMC_CCU8_SLICE_t *)slice, (uint8_t)spread);
1120 }
1121 
1122 /* Programs Pre-scaler divider  */
XMC_CCU8_SLICE_SetPrescaler(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_PRESCALER_t div_val)1123 void XMC_CCU8_SLICE_SetPrescaler(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_PRESCALER_t div_val)
1124 {
1125   uint32_t fpc;
1126 
1127   XMC_ASSERT("XMC_CCU8_SLICE_SetPrescaler:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1128 
1129   /* If the prescaler is not running, update directly the divider*/
1130   fpc = slice->FPC;
1131   fpc &= ~((uint32_t) CCU8_CC8_FPC_PVAL_Msk);
1132   fpc |= ((uint32_t) div_val) << CCU8_CC8_FPC_PVAL_Pos;
1133   slice->FPC = fpc;
1134 
1135   /*
1136    * In any case, update the initial value of the divider which is to be loaded once the prescaler increments to the
1137    * compare value.
1138    */
1139   slice->PSC = (uint32_t) div_val;
1140 }
1141 
1142 /* Programs timer compare match value for channel 1 or 2 */
XMC_CCU8_SLICE_SetTimerCompareMatch(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel,const uint16_t compare_val)1143 void XMC_CCU8_SLICE_SetTimerCompareMatch(XMC_CCU8_SLICE_t *const slice,
1144                                          const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel,
1145                                          const uint16_t compare_val)
1146 {
1147   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerCompareMatch:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1148   XMC_ASSERT("XMC_CCU8_SLICE_SetTimerCompareMatch:Invalid channel", XMC_CCU8_SLICE_CHECK_COMP_CHANNEL(channel));
1149 
1150   if (XMC_CCU8_SLICE_COMPARE_CHANNEL_1 == channel)
1151   {
1152     slice->CR1S = (uint32_t) compare_val;
1153   }
1154   else
1155   {
1156     slice->CR2S = (uint32_t) compare_val;
1157   }
1158 }
1159 
1160 /* Returns the timer compare match value for channel 1 or 2 */
XMC_CCU8_SLICE_GetTimerCompareMatch(const XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel)1161 uint16_t XMC_CCU8_SLICE_GetTimerCompareMatch(const XMC_CCU8_SLICE_t *const slice,
1162                                              const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel)
1163 {
1164   uint16_t compare_value;
1165 
1166   XMC_ASSERT("XMC_CCU8_SLICE_GetCompareMatch:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1167   XMC_ASSERT("XMC_CCU8_SLICE_GetCompareMatch:Invalid channel", XMC_CCU8_SLICE_CHECK_COMP_CHANNEL(channel));
1168 
1169   if (XMC_CCU8_SLICE_COMPARE_CHANNEL_1 == channel)
1170   {
1171     compare_value = (uint16_t) slice->CR1;
1172   }
1173   else
1174   {
1175     compare_value = (uint16_t) slice->CR2;
1176   }
1177 
1178   return(compare_value);
1179 }
1180 
1181 /* Binds a capcom event to an NVIC node  */
XMC_CCU8_SLICE_SetInterruptNode(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_IRQ_ID_t event,const XMC_CCU8_SLICE_SR_ID_t sr)1182 void XMC_CCU8_SLICE_SetInterruptNode(XMC_CCU8_SLICE_t *const slice,
1183                                      const XMC_CCU8_SLICE_IRQ_ID_t event,
1184                                      const XMC_CCU8_SLICE_SR_ID_t sr)
1185 {
1186   uint32_t srs;
1187   uint32_t mask;
1188   uint32_t pos;
1189 
1190   XMC_ASSERT("XMC_CCU8_SLICE_SetInterruptNode:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1191   XMC_ASSERT("XMC_CCU8_SLICE_SetInterruptNode:Invalid SR ID ", XMC_CCU8_SLICE_CHECK_SR_ID(sr));
1192   XMC_ASSERT("XMC_CCU8_SLICE_SetInterruptNode:Invalid event", XMC_CCU8_SLICE_CHECK_INTERRUPT(event));
1193 
1194   srs = slice->SRS;
1195 
1196   switch(event)
1197   {
1198     case XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH:
1199     case XMC_CCU8_SLICE_IRQ_ID_ONE_MATCH:
1200       mask = ((uint32_t) CCU8_CC8_SRS_POSR_Msk);
1201       pos  = CCU8_CC8_SRS_POSR_Pos;
1202       break;
1203 
1204     case XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_1:
1205     case XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_DOWN_CH_1:
1206       mask = ((uint32_t) CCU8_CC8_SRS_CM1SR_Msk);
1207       pos  = CCU8_CC8_SRS_CM1SR_Pos;
1208       break;
1209 
1210     case XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_2:
1211     case XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_DOWN_CH_2:
1212       mask = ((uint32_t) CCU8_CC8_SRS_CM2SR_Msk);
1213       pos  = CCU8_CC8_SRS_CM2SR_Pos;
1214       break;
1215 
1216     case XMC_CCU8_SLICE_IRQ_ID_EVENT0:
1217       mask = ((uint32_t) CCU8_CC8_SRS_E0SR_Msk);
1218       pos  = CCU8_CC8_SRS_E0SR_Pos;
1219       break;
1220 
1221     case XMC_CCU8_SLICE_IRQ_ID_EVENT1:
1222       mask = ((uint32_t) CCU8_CC8_SRS_E1SR_Msk);
1223       pos  = CCU8_CC8_SRS_E1SR_Pos;
1224       break;
1225 
1226     default:
1227       mask = ((uint32_t) CCU8_CC8_SRS_E2SR_Msk);
1228       pos  = CCU8_CC8_SRS_E2SR_Pos;
1229       break;
1230   }
1231 
1232   srs &= ~mask;
1233   srs |= (uint32_t)sr << pos;
1234 
1235   slice->SRS = srs;
1236 }
1237 
1238 /* Asserts passive level for the slice output */
XMC_CCU8_SLICE_SetPassiveLevel(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_OUTPUT_t out,const XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_t level)1239 void XMC_CCU8_SLICE_SetPassiveLevel(XMC_CCU8_SLICE_t *const slice,
1240                                     const XMC_CCU8_SLICE_OUTPUT_t out,
1241                                     const XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_t level)
1242 {
1243   uint32_t psl;
1244 
1245   XMC_ASSERT("XMC_CCU8_SLICE_SetPassiveLevel:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1246   XMC_ASSERT("XMC_CCU8_SLICE_SetPassiveLevel:Invalid Slice Output", XMC_CCU8_SLICE_CHECK_OUTPUT(out));
1247   XMC_ASSERT("XMC_CCU8_SLICE_SetPassiveLevel:Invalid Passive Level",
1248              ((level == XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_LOW) ||\
1249               (level == XMC_CCU8_SLICE_OUTPUT_PASSIVE_LEVEL_HIGH)));
1250 
1251   psl = slice->PSL;
1252 
1253   psl &= ~((uint32_t) out);
1254   psl |= (uint32_t) level << ((uint32_t)out >> 1U);
1255 
1256   /* Program CC8 slice output passive level */
1257   slice->PSL = psl;
1258 }
1259 
1260 /* Initializes Dead time configuration for the slice outputs */
XMC_CCU8_SLICE_DeadTimeInit(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_DEAD_TIME_CONFIG_t * const config)1261 void XMC_CCU8_SLICE_DeadTimeInit(XMC_CCU8_SLICE_t *const slice,
1262                                  const XMC_CCU8_SLICE_DEAD_TIME_CONFIG_t *const config)
1263 {
1264   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureDeadTime:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1265 
1266   /* Program dead time value for channel 1 */
1267   slice->DC1R = config->dc1r;
1268   /* Program dead time value for channel 2 */
1269   slice->DC2R = config->dc2r;
1270   /* Program dead time control configuration */
1271   slice->DTC = config->dtc;
1272 }
1273 
1274 /* Activates or deactivates dead time for compare channel and ST path */
XMC_CCU8_SLICE_ConfigureDeadTime(XMC_CCU8_SLICE_t * const slice,const uint8_t mask)1275 void XMC_CCU8_SLICE_ConfigureDeadTime(XMC_CCU8_SLICE_t *const slice, const uint8_t mask)
1276 {
1277   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureDeadTime:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1278   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureDeadTime:Invalid Channel", (mask <= XMC_CCU8_SLICE_DEAD_TIME_CONFIG_MASK));
1279 
1280   slice->DTC &= ~((uint32_t) XMC_CCU8_SLICE_DEAD_TIME_CONFIG_MASK);
1281   slice->DTC |= (uint32_t) mask;
1282 }
1283 
1284 /* Configures rising edge delay and falling edge delay for dead time */
XMC_CCU8_SLICE_SetDeadTimeValue(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel,const uint8_t rise_value,const uint8_t fall_value)1285 void XMC_CCU8_SLICE_SetDeadTimeValue(XMC_CCU8_SLICE_t *const slice,
1286                                      const XMC_CCU8_SLICE_COMPARE_CHANNEL_t channel,
1287                                      const uint8_t rise_value,
1288                                      const uint8_t fall_value)
1289 {
1290   XMC_ASSERT("XMC_CCU8_SLICE_SetDeadTimeValue:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1291   XMC_ASSERT("XMC_CCU8_SLICE_SetDeadTimeValue:Invalid channel", XMC_CCU8_SLICE_CHECK_COMP_CHANNEL(channel));
1292 
1293   if (XMC_CCU8_SLICE_COMPARE_CHANNEL_1 == channel)
1294   {
1295     slice->DC1R = (((uint32_t) fall_value) << CCU8_CC8_DC1R_DT1F_Pos) | ((uint32_t) rise_value);
1296   }
1297   else
1298   {
1299   slice->DC2R = (((uint32_t) fall_value) << CCU8_CC8_DC2R_DT2F_Pos) | ((uint32_t) rise_value);
1300   }
1301 }
1302 
1303 /* Configures clock division factor for dead time */
XMC_CCU8_SLICE_SetDeadTimePrescaler(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_DTC_DIV_t div_val)1304 void XMC_CCU8_SLICE_SetDeadTimePrescaler(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_DTC_DIV_t div_val)
1305 {
1306   XMC_ASSERT("XMC_CCU8_SLICE_SetDeadTimePrescaler:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1307   XMC_ASSERT("XMC_CCU8_SLICE_SetDeadTimePrescaler:Invalid divider value", XMC_CCU8_SLICE_CHECK_DTC_DIV(div_val));
1308 
1309   slice->DTC &= ~((uint32_t) CCU8_CC8_DTC_DTCC_Msk);
1310   slice->DTC |= ((uint32_t) div_val) << CCU8_CC8_DTC_DTCC_Pos;
1311 }
1312 
1313 /* Configures status ST1, ST2 mapping to STy */
XMC_CCU8_SLICE_ConfigureStatusBitOutput(XMC_CCU8_SLICE_t * const slice,const XMC_CCU8_SLICE_STATUS_t channel)1314 void XMC_CCU8_SLICE_ConfigureStatusBitOutput(XMC_CCU8_SLICE_t *const slice, const XMC_CCU8_SLICE_STATUS_t channel)
1315 {
1316   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOutput:Invalid Slice Pointer", XMC_CCU8_IsValidSlice(slice));
1317   XMC_ASSERT("XMC_CCU8_SLICE_ConfigureStatusBitOutput:Invalid Channel", XMC_CCU8_SLICE_CHECK_SLICE_STATUS(channel));
1318 
1319   slice->TC &= ~((uint32_t) CCU8_CC8_TC_STOS_Msk);
1320   slice->TC |= ((uint32_t) channel) << CCU8_CC8_TC_STOS_Pos;
1321 }
1322 
1323 #endif /* CCU80 */
1324