CC23x0R5DriverLibrary
lpcmp.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: lpcmp.h
3  *
4  * Description: Defines and prototypes for the LPCMP peripheral.
5  *
6  * Copyright (c) 2022-2024, Texas Instruments Incorporated
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1) Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2) Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 #ifndef __LPCMP_H__
38 #define __LPCMP_H__
39 
40 //*****************************************************************************
41 //
46 //
47 //*****************************************************************************
48 
49 #include <stdbool.h>
50 #include <stdint.h>
51 #include "../inc/hw_types.h"
52 #include "../inc/hw_memmap.h"
53 #include "../inc/hw_sys0.h"
54 
55 //*****************************************************************************
56 //
57 // If building with a C++ compiler, make all of the definitions in this header
58 // have a C binding.
59 //
60 //*****************************************************************************
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 //*****************************************************************************
66 //
67 // Defines that can be passed to LPCMPSetDividerPath() to select the voltage
68 // divider path.
69 //
70 //*****************************************************************************
71 #define LPCMP_DIVISION_PATH_N SYS0_LPCMPCFG_DIVPATH_NSIDE
72 #define LPCMP_DIVISION_PATH_P SYS0_LPCMPCFG_DIVPATH_PSIDE
73 
74 //*****************************************************************************
75 //
76 // Defines that can be passed to LPCMPSetDividerRatio() to select which ratio
77 // should be used by the voltage divider.
78 //
79 //*****************************************************************************
80 #define LPCMP_DIVISION_FACTOR_1_1 SYS0_LPCMPCFG_DIV_VAL0
81 #define LPCMP_DIVISION_FACTOR_3_4 SYS0_LPCMPCFG_DIV_VAL1
82 #define LPCMP_DIVISION_FACTOR_1_2 SYS0_LPCMPCFG_DIV_VAL2
83 #define LPCMP_DIVISION_FACTOR_1_3 SYS0_LPCMPCFG_DIV_VAL3
84 #define LPCMP_DIVISION_FACTOR_1_4 SYS0_LPCMPCFG_DIV_VAL4
85 
86 //*****************************************************************************
87 //
88 // Defines that can be passed to LPCMPSetPolarity() to select which edge type
89 // should generate a LPCMP event.
90 //
91 //*****************************************************************************
92 #define LPCMP_POLARITY_FALL SYS0_LPCMPCFG_EDGCFG_FALL
93 #define LPCMP_POLARITY_RISE SYS0_LPCMPCFG_EDGCFG_RISE
94 
95 //*****************************************************************************
96 //
97 // Defines that can be passed to LPCMPNegativeInputSelect() to select which
98 // signal should be muxed to LPCMP negative input.
99 //
100 //*****************************************************************************
101 #define LPCMP_NEG_INPUT_VDDD SYS0_LPCMPCFG_NSEL_VDDD
102 #define LPCMP_NEG_INPUT_VDDS SYS0_LPCMPCFG_NSEL_VDDA
103 #define LPCMP_NEG_INPUT_A2 SYS0_LPCMPCFG_NSEL_VA_PAD_A2
104 #define LPCMP_NEG_INPUT_A3 SYS0_LPCMPCFG_NSEL_VA_PAD_A3
105 #define LPCMP_NEG_INPUT_OPEN SYS0_LPCMPCFG_NSEL_OPEN
106 
107 //*****************************************************************************
108 //
109 // Defines that can be passed to LPCMPPositiveInputSelect() to select which
110 // signal should be muxed to LPCMP positive input.
111 //
112 //*****************************************************************************
113 #define LPCMP_POS_INPUT_A1 SYS0_LPCMPCFG_PSEL_VA_PAD_A1
114 #define LPCMP_POS_INPUT_A2 SYS0_LPCMPCFG_PSEL_VA_PAD_A2
115 #define LPCMP_POS_INPUT_A3 SYS0_LPCMPCFG_PSEL_VA_PAD_A3
116 #define LPCMP_POS_INPUT_VDDS SYS0_LPCMPCFG_PSEL_VDDA
117 #define LPCMP_POS_INPUT_OPEN SYS0_LPCMPCFG_PSEL_OPEN
118 
119 //*****************************************************************************
120 //
121 // API Functions and prototypes
122 //
123 //*****************************************************************************
124 
125 //*****************************************************************************
126 //
131 //
132 //*****************************************************************************
134 {
135  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) |= SYS0_LPCMPCFG_EN;
136 }
137 
138 //*****************************************************************************
139 //
143 //
144 //*****************************************************************************
146 {
147  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_EN;
148 }
149 
150 //*****************************************************************************
151 //
159 //
160 //*****************************************************************************
162 {
163  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) |= SYS0_LPCMPCFG_EVTEN;
164 }
165 
166 //*****************************************************************************
167 //
171 //
172 //*****************************************************************************
174 {
175  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_EVTEN;
176 }
177 
178 //*****************************************************************************
179 //
184 //
185 //*****************************************************************************
187 {
188  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_EVTIFG;
189 }
190 
191 //*****************************************************************************
192 //
197 //
198 //*****************************************************************************
200 {
201  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) |= SYS0_LPCMPCFG_WUENSB;
202 }
203 
204 //*****************************************************************************
205 //
210 //
211 //*****************************************************************************
213 {
214  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_WUENSB;
215 }
216 
217 //*****************************************************************************
218 //
231 //
232 //*****************************************************************************
234 {
235  uint32_t lpcmpcfg;
236 
237  lpcmpcfg = HWREG(SYS0_BASE + SYS0_O_LPCMPCFG);
238  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) = (lpcmpcfg & ~SYS0_LPCMPCFG_NSEL_M) | (input & SYS0_LPCMPCFG_NSEL_M);
239 }
240 
241 //*****************************************************************************
242 //
251 //
252 //*****************************************************************************
254 {
255  if (HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) & SYS0_LPCMPCFG_COUT_HIGH)
256  {
257  return true;
258  }
259  else
260  {
261  return false;
262  }
263 }
264 
265 //*****************************************************************************
266 //
279 //
280 //*****************************************************************************
282 {
283  uint32_t lpcmpcfg;
284 
285  lpcmpcfg = HWREG(SYS0_BASE + SYS0_O_LPCMPCFG);
286  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) = (lpcmpcfg & ~SYS0_LPCMPCFG_PSEL_M) | (input & SYS0_LPCMPCFG_PSEL_M);
287 }
288 
289 //*****************************************************************************
290 //
301 //
302 //*****************************************************************************
303 __STATIC_INLINE void LPCMPSetPolarity(uint32_t polarity)
304 {
305  if (polarity == LPCMP_POLARITY_FALL)
306  {
307  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) |= SYS0_LPCMPCFG_EDGCFG;
308  }
309  else
310  {
311  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_EDGCFG;
312  }
313 }
314 
315 //*****************************************************************************
316 //
330 //
331 //*****************************************************************************
332 __STATIC_INLINE void LPCMPSetDividerRatio(uint32_t divider)
333 {
334  uint32_t lpcmpcfg;
335 
336  lpcmpcfg = HWREG(SYS0_BASE + SYS0_O_LPCMPCFG);
337  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) = (lpcmpcfg & ~SYS0_LPCMPCFG_DIV_M) | (divider & SYS0_LPCMPCFG_DIV_M);
338 }
339 
340 //*****************************************************************************
341 //
352 //
353 //*****************************************************************************
355 {
356  if (path == LPCMP_DIVISION_PATH_P)
357  {
358  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) |= SYS0_LPCMPCFG_DIVPATH;
359  }
360  else
361  {
362  HWREG(SYS0_BASE + SYS0_O_LPCMPCFG) &= ~SYS0_LPCMPCFG_DIVPATH;
363  }
364 }
365 
366 //*****************************************************************************
367 //
368 // Mark the end of the C bindings section for C++ compilers.
369 //
370 //*****************************************************************************
371 #ifdef __cplusplus
372 }
373 #endif
374 
375 //*****************************************************************************
376 //
380 //
381 //*****************************************************************************
382 
383 #endif // __LPCMP_H__
__STATIC_INLINE void LPCMPSetDividerRatio(uint32_t divider)
Selects the ratio used by LPCMP voltage divider.
Definition: lpcmp.h:332
#define LPCMP_DIVISION_PATH_P
Apply voltage divider to the positive input.
Definition: lpcmp.h:72
__STATIC_INLINE void LPCMPSetPolarity(uint32_t polarity)
Selects the edge polarity of LPCMP output on which an event is triggered.
Definition: lpcmp.h:303
__STATIC_INLINE void LPCMPDisableWakeup(void)
Disables LPCMP as wakeup source from standby.
Definition: lpcmp.h:212
__STATIC_INLINE void LPCMPSelectPositiveInput(uint32_t input)
Selects the positive input of LPCMP.
Definition: lpcmp.h:281
__STATIC_INLINE bool LPCMPIsOutputHigh(void)
Verifies if the raw output of LPCMP is high.
Definition: lpcmp.h:253
__STATIC_INLINE void LPCMPSetDividerPath(uint32_t path)
Selects the input path on which the LPCMP voltage divider is applied.
Definition: lpcmp.h:354
#define LPCMP_POLARITY_FALL
Select falling edge for event generation.
Definition: lpcmp.h:92
__STATIC_INLINE void LPCMPEnable(void)
Enables LPCMP.
Definition: lpcmp.h:133
__STATIC_INLINE void LPCMPEnableWakeup(void)
Enables LPCMP as wakeup source from standby.
Definition: lpcmp.h:199
__STATIC_INLINE void LPCMPEnableEvent(void)
Enables LPCMP event generation.
Definition: lpcmp.h:161
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__STATIC_INLINE void LPCMPSelectNegativeInput(uint32_t input)
Selects the negative input of LPCMP.
Definition: lpcmp.h:233
__STATIC_INLINE void LPCMPClearEvent(void)
Clear LPCMP event flag.
Definition: lpcmp.h:186
__STATIC_INLINE void LPCMPDisableEvent(void)
Disables LPCMP event generation.
Definition: lpcmp.h:173
__STATIC_INLINE void LPCMPDisable(void)
Disables LPCMP.
Definition: lpcmp.h:145