1 /**
2 * @file xmc_acmp.c
3 * @date 2015-06-20
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 * 2014-12-10:
40 * - Initial <br>
41 * 2015-02-20:
42 * - Removed unused declarations<br>
43 * 2015-05-08:
44 * - Fixed sequence problem of low power mode in XMC_ACMP_Init() API<br>
45 * - Fixed wrong register setting in XMC_ACMP_SetInput() API<br>
46 * - Removed return type variable and by default comparator enable from XMC_ACMP_Init() API. <br>
47 * Additional call to XMC_ACMP_EnableComparator() API needed to start Comparator after Init.<br>
48 * 2015-06-04:
49 * - Removed return type variable and by default comparator enable from XMC_ACMP_Init() API. <br>
50 * - Divided XMC_ACMP_SetInput into two 3 APIs to reduce the code size and complexity as stated below<br>
51 * (a)XMC_ACMP_EnableReferenceDivider <br>
52 * (b)XMC_ACMP_DisableReferenceDivider <br>
53 * (c)XMC_ACMP_SetInput <br>
54 * - Optimized enable and disable API's and moved to header file as static inline APIs.
55 * - XMC_ACMP_t typedef changed to structure which overrides the standard header file structure.
56 * 2015-06-20:
57 * - Removed definition of GetDriverVersion API
58 * @endcond
59 *
60 */
61
62
63 /*********************************************************************************************************************
64 * HEADER FILES
65 ********************************************************************************************************************/
66 #include <xmc_acmp.h>
67
68 /* If ACMP is available*/
69 #if defined (COMPARATOR)
70
71 /*********************************************************************************************************************
72 * MACROS
73 ********************************************************************************************************************/
74
75 #define XMC_ACMP_INSTANCE_1 (1U) /* Instance number for Slice-1 */
76
77 /*********************************************************************************************************************
78 * API IMPLEMENTATION
79 ********************************************************************************************************************/
80
81 /* API to initialize an instance of ACMP module */
XMC_ACMP_Init(XMC_ACMP_t * const peripheral,uint32_t instance,const XMC_ACMP_CONFIG_t * const config)82 void XMC_ACMP_Init(XMC_ACMP_t *const peripheral, uint32_t instance, const XMC_ACMP_CONFIG_t *const config)
83 {
84
85 XMC_ASSERT("XMC_ACMP_Init:NULL Configuration", (config != (XMC_ACMP_CONFIG_t *)NULL))
86 XMC_ASSERT("XMC_ACMP_Init:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
87 XMC_ASSERT("XMC_ACMP_Init:Wrong instance number", XMC_ACMP_CHECK_INSTANCE(instance) )
88
89 /*
90 * Initializes the comparator with configuration supplied. Low power node setting is retained during initialization.
91 * All the instances passed are handled with low power setting, to avoid conditional check for ACMP0 instance.
92 * This reduces the code size. No side effects, because this register bit field is empty for other instances.
93 */
94 peripheral->ANACMP[instance] = ((peripheral->ANACMP[instance] & (uint32_t)COMPARATOR_ANACMP0_CMP_LPWR_Msk)) |
95 (uint32_t)config->anacmp;
96 }
97
98 /* API to select INP source */
XMC_ACMP_SetInput(XMC_ACMP_t * const peripheral,uint32_t instance,XMC_ACMP_INP_SOURCE_t source)99 void XMC_ACMP_SetInput(XMC_ACMP_t *const peripheral, uint32_t instance, XMC_ACMP_INP_SOURCE_t source)
100 {
101 XMC_ASSERT("XMC_ACMP_SetInput:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
102 XMC_ASSERT("XMC_ACMP_SetInput:Wrong instance number", ((instance != XMC_ACMP_INSTANCE_1) &&
103 XMC_ACMP_CHECK_INSTANCE(instance)) )
104 XMC_ASSERT("XMC_ACMP_SetInput:Wrong input source", ((source == XMC_ACMP_INP_SOURCE_STANDARD_PORT) ||
105 (source == XMC_ACMP_INP_SOURCE_ACMP1_INP_PORT)) )
106
107 /*
108 * Three options of Input Setting are listed below
109 * 1. The comparator inputs aren't connected to other comparator inputs
110 * 2. Can program the comparators to connect ACMP0.INP to ACMP1.INP in XMC1200 AA or XMC1300 AA
111 * Can program the comparators to connect ACMP0.INN to ACMP1.INP in XMC1200 AB or XMC1300 AB or XMC1400 AA
112 * 3. Can program the comparators to connect ACMP2.INP to ACMP1.INP
113 * 4. Can program the comparators to connect ACMP3.INP to ACMP1.INP in XMC1400
114 */
115 peripheral->ANACMP[instance] = ((peripheral->ANACMP[instance] & (uint32_t)(~COMPARATOR_ANACMP0_ACMP0_SEL_Msk))) |
116 (uint32_t)source;
117 }
118
119 #endif /* #ifdef ACMP_AVAILABLE */
120