RTEMS 6.1-rc1
fsl_acmp.h
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_ACMP_H_
10#define _FSL_ACMP_H_
11
12#include "fsl_common.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
26#define FSL_ACMP_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 6U))
30#define CMP_C0_CFx_MASK (CMP_C0_CFR_MASK | CMP_C0_CFF_MASK)
31#define CMP_C1_CHNn_MASK 0xFF0000U /* C1_CHN0 - C1_CHN7. */
32#define CMP_C2_CHnF_MASK 0xFF0000U /* C2_CH0F - C2_CH7F. */
33
36{
40};
41
44{
45 kACMP_OutputRisingEventFlag = CMP_C0_CFR_MASK,
46 kACMP_OutputFallingEventFlag = CMP_C0_CFF_MASK,
47 kACMP_OutputAssertEventFlag = CMP_C0_COUT_MASK,
48};
49
50#if defined(FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT) && (FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT == 1U)
59typedef enum _acmp_offset_mode
60{
61 kACMP_OffsetLevel0 = 0U,
62 kACMP_OffsetLevel1 = 1U,
63} acmp_offset_mode_t;
64#endif /* FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT */
65
72{
78
81{
85
86#if defined(FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT) && (FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT == 1U)
88typedef enum _acmp_port_input
89{
90 kACMP_PortInputFromDAC = 0U,
91 kACMP_PortInputFromMux = 1U,
92} acmp_port_input_t;
93#endif /* FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT */
94
96typedef enum _acmp_fixed_port
97{
101
102#if defined(FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT) && (FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT == 1U)
104typedef enum _acmp_dac_work_mode
105{
106 kACMP_DACWorkLowSpeedMode = 0U,
107 kACMP_DACWorkHighSpeedMode = 1U,
108} acmp_dac_work_mode_t;
109#endif /* FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT */
110
112typedef struct _acmp_config
113{
114#if defined(FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT) && (FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT == 1U)
115 acmp_offset_mode_t offsetMode;
116#endif /* FSL_FEATURE_ACMP_HAS_C0_OFFSET_BIT */
123
131{
132#if defined(FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT) && (FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT == 1U)
133 acmp_port_input_t positivePortInput;
134#endif /* FSL_FEATURE_ACMP_HAS_C1_INPSEL_BIT */
135 uint32_t plusMuxInput;
136#if defined(FSL_FEATURE_ACMP_HAS_C1_INNSEL_BIT) && (FSL_FEATURE_ACMP_HAS_C1_INNSEL_BIT == 1U)
137 acmp_port_input_t negativePortInput;
138#endif /* FSL_FEATURE_ACMP_HAS_C1_INNSEL_BIT */
139 uint32_t minusMuxInput;
141
144{
146 uint32_t filterCount;
147 uint32_t filterPeriod;
149
151typedef struct _acmp_dac_config
152{
154 uint32_t DACValue;
156#if defined(FSL_FEATURE_ACMP_HAS_C1_DACOE_BIT) && (FSL_FEATURE_ACMP_HAS_C1_DACOE_BIT == 1U)
157 bool enableOutput;
158#endif /* FSL_FEATURE_ACMP_HAS_C1_DACOE_BIT */
159
160#if defined(FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT) && (FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT == 1U)
161 acmp_dac_work_mode_t workMode;
162#endif /* FSL_FEATURE_ACMP_HAS_C1_DMODE_BIT */
164
167{
173 uint32_t delayModulus;
175
176#if defined(FSL_FEATURE_ACMP_HAS_C3_REG) && (FSL_FEATURE_ACMP_HAS_C3_REG == 1U)
177
179typedef enum _acmp_discrete_clock_source
180{
181 kACMP_DiscreteClockSlow = 0U,
182 kACMP_DiscreteClockFast = 1U,
183} acmp_discrete_clock_source_t;
184
190typedef enum _acmp_discrete_sample_time
191{
192 kACMP_DiscreteSampleTimeAs1T = 0U,
193 kACMP_DiscreteSampleTimeAs2T = 1U,
194 kACMP_DiscreteSampleTimeAs4T = 2U,
195 kACMP_DiscreteSampleTimeAs8T = 3U,
196 kACMP_DiscreteSampleTimeAs16T = 4U,
197 kACMP_DiscreteSampleTimeAs32T = 5U,
198 kACMP_DiscreteSampleTimeAs64T = 6U,
199 kACMP_DiscreteSampleTimeAs256T = 7U,
200} acmp_discrete_sample_time_t;
201
206typedef enum _acmp_discrete_phase_time
207{
208 kACMP_DiscretePhaseTimeAlt0 = 0U,
209 kACMP_DiscretePhaseTimeAlt1 = 1U,
210 kACMP_DiscretePhaseTimeAlt2 = 2U,
211 kACMP_DiscretePhaseTimeAlt3 = 3U,
212 kACMP_DiscretePhaseTimeAlt4 = 4U,
213 kACMP_DiscretePhaseTimeAlt5 = 5U,
214 kACMP_DiscretePhaseTimeAlt6 = 6U,
215 kACMP_DiscretePhaseTimeAlt7 = 7U,
216} acmp_discrete_phase_time_t;
217
219typedef struct _acmp_discrete_mode_config
220{
221 bool enablePositiveChannelDiscreteMode;
223 bool enableNegativeChannelDiscreteMode;
225 bool enableResistorDivider;
227 acmp_discrete_clock_source_t clockSource;
229 acmp_discrete_sample_time_t sampleTime;
230 acmp_discrete_phase_time_t phase1Time;
231 acmp_discrete_phase_time_t phase2Time;
232} acmp_discrete_mode_config_t;
233
234#endif /* FSL_FEATURE_ACMP_HAS_C3_REG */
235
236#if defined(__cplusplus)
237extern "C" {
238#endif
239
240/*******************************************************************************
241 * API
242 ******************************************************************************/
243
257void ACMP_Init(CMP_Type *base, const acmp_config_t *config);
258
264void ACMP_Deinit(CMP_Type *base);
265
284
285/* @} */
286
298void ACMP_Enable(CMP_Type *base, bool enable);
299
300#if defined(FSL_FEATURE_ACMP_HAS_C0_LINKEN_BIT) && (FSL_FEATURE_ACMP_HAS_C0_LINKEN_BIT == 1U)
309void ACMP_EnableLinkToDAC(CMP_Type *base, bool enable);
310#endif /* FSL_FEATURE_ACMP_HAS_C0_LINKEN_BIT */
311
331
332/* @} */
333
345void ACMP_EnableDMA(CMP_Type *base, bool enable);
346
353void ACMP_EnableWindowMode(CMP_Type *base, bool enable);
354
375
393
411
421void ACMP_SetRoundRobinPreState(CMP_Type *base, uint32_t mask);
422
429static inline uint32_t ACMP_GetRoundRobinStatusFlags(CMP_Type *base)
430{
431 return (((base->C2) & CMP_C2_CHnF_MASK) >> CMP_C2_CH0F_SHIFT);
432}
433
440void ACMP_ClearRoundRobinStatusFlags(CMP_Type *base, uint32_t mask);
441
451static inline uint32_t ACMP_GetRoundRobinResult(CMP_Type *base)
452{
453 return ((base->C2 & CMP_C2_ACOn_MASK) >> CMP_C2_ACOn_SHIFT);
454}
455
456/* @} */
457
469void ACMP_EnableInterrupts(CMP_Type *base, uint32_t mask);
470
477void ACMP_DisableInterrupts(CMP_Type *base, uint32_t mask);
478
479/* @} */
480
492uint32_t ACMP_GetStatusFlags(CMP_Type *base);
493
500void ACMP_ClearStatusFlags(CMP_Type *base, uint32_t mask);
501
502/* @} */
503
504#if defined(FSL_FEATURE_ACMP_HAS_C3_REG) && (FSL_FEATURE_ACMP_HAS_C3_REG == 1U)
518void ACMP_SetDiscreteModeConfig(CMP_Type *base, const acmp_discrete_mode_config_t *config);
519
525void ACMP_GetDefaultDiscreteModeConfig(acmp_discrete_mode_config_t *config);
526
527/* @} */
528#endif /* FSL_FEATURE_ACMP_HAS_C3_REG */
529
530#if defined(__cplusplus)
531}
532#endif
533
536#endif /* _FSL_ACMP_H_ */
struct _acmp_channel_config acmp_channel_config_t
Configuration for channel.
_acmp_interrupt_enable
Interrupt enable/disable mask.
Definition: fsl_acmp.h:36
void ACMP_SetFilterConfig(CMP_Type *base, const acmp_filter_config_t *config)
Configures the filter.
Definition: fsl_acmp.c:315
acmp_hysteresis_mode_t hysteresisMode
Definition: fsl_acmp.h:117
bool enableSample
Definition: fsl_acmp.h:145
void ACMP_Enable(CMP_Type *base, bool enable)
Enables or disables the ACMP.
Definition: fsl_acmp.c:172
uint32_t ACMP_GetStatusFlags(CMP_Type *base)
Gets status flags.
Definition: fsl_acmp.c:560
void ACMP_SetRoundRobinPreState(CMP_Type *base, uint32_t mask)
Defines the pre-set state of channels in round robin mode.
Definition: fsl_acmp.c:454
bool enableHighSpeed
Definition: fsl_acmp.h:118
void ACMP_SetChannelConfig(CMP_Type *base, const acmp_channel_config_t *config)
Sets the channel configuration.
Definition: fsl_acmp.c:230
uint32_t minusMuxInput
Definition: fsl_acmp.h:139
enum _acmp_reference_voltage_source acmp_reference_voltage_source_t
CMP Voltage Reference source.
uint32_t checkerChannelMask
Definition: fsl_acmp.h:170
_acmp_reference_voltage_source
CMP Voltage Reference source.
Definition: fsl_acmp.h:81
_acmp_hysteresis_mode
Comparator hard block hysteresis control.
Definition: fsl_acmp.h:72
bool enableInvertOutput
Definition: fsl_acmp.h:119
bool enablePinOut
Definition: fsl_acmp.h:121
uint32_t DACValue
Definition: fsl_acmp.h:154
struct _acmp_filter_config acmp_filter_config_t
Configuration for filter.
void ACMP_Init(CMP_Type *base, const acmp_config_t *config)
Initializes the ACMP.
Definition: fsl_acmp.c:70
struct _acmp_config acmp_config_t
Configuration for ACMP.
void ACMP_EnableDMA(CMP_Type *base, bool enable)
Enables or disables DMA.
Definition: fsl_acmp.c:260
uint32_t filterPeriod
Definition: fsl_acmp.h:147
enum _acmp_hysteresis_mode acmp_hysteresis_mode_t
Comparator hard block hysteresis control.
uint32_t fixedChannelNumber
Definition: fsl_acmp.h:169
struct _acmp_dac_config acmp_dac_config_t
Configuration for DAC.
void ACMP_ClearRoundRobinStatusFlags(CMP_Type *base, uint32_t mask)
Clears the channel input changed flags in round robin mode.
Definition: fsl_acmp.c:471
void ACMP_DisableInterrupts(CMP_Type *base, uint32_t mask)
Disables interrupts.
Definition: fsl_acmp.c:523
void ACMP_Deinit(CMP_Type *base)
Deinitializes the ACMP.
Definition: fsl_acmp.c:120
uint32_t delayModulus
Definition: fsl_acmp.h:173
uint32_t plusMuxInput
Definition: fsl_acmp.h:135
_acmp_status_flags
Status flag mask.
Definition: fsl_acmp.h:44
void ACMP_SetDACConfig(CMP_Type *base, const acmp_dac_config_t *config)
Configures the internal DAC.
Definition: fsl_acmp.c:348
bool useUnfilteredOutput
Definition: fsl_acmp.h:120
_acmp_fixed_port
Fixed mux port.
Definition: fsl_acmp.h:97
void ACMP_EnableInterrupts(CMP_Type *base, uint32_t mask)
Enables interrupts.
Definition: fsl_acmp.c:486
acmp_reference_voltage_source_t referenceVoltageSource
Definition: fsl_acmp.h:153
void ACMP_EnableWindowMode(CMP_Type *base, bool enable)
Enables or disables window mode.
Definition: fsl_acmp.c:281
acmp_fixed_port_t fixedPort
Definition: fsl_acmp.h:168
uint32_t sampleClockCount
Definition: fsl_acmp.h:172
void ACMP_ClearStatusFlags(CMP_Type *base, uint32_t mask)
Clears status flags.
Definition: fsl_acmp.c:590
enum _acmp_fixed_port acmp_fixed_port_t
Fixed mux port.
struct _acmp_round_robin_config acmp_round_robin_config_t
Configuration for round robin mode.
void ACMP_GetDefaultConfig(acmp_config_t *config)
Gets the default configuration for ACMP.
Definition: fsl_acmp.c:148
void ACMP_SetRoundRobinConfig(CMP_Type *base, const acmp_round_robin_config_t *config)
Configures the round robin mode.
Definition: fsl_acmp.c:407
uint32_t filterCount
Definition: fsl_acmp.h:146
@ kACMP_RoundRobinInterruptEnable
Definition: fsl_acmp.h:39
@ kACMP_OutputFallingInterruptEnable
Definition: fsl_acmp.h:38
@ kACMP_OutputRisingInterruptEnable
Definition: fsl_acmp.h:37
@ kACMP_VrefSourceVin2
Definition: fsl_acmp.h:83
@ kACMP_VrefSourceVin1
Definition: fsl_acmp.h:82
@ kACMP_HysteresisLevel2
Definition: fsl_acmp.h:75
@ kACMP_HysteresisLevel1
Definition: fsl_acmp.h:74
@ kACMP_HysteresisLevel0
Definition: fsl_acmp.h:73
@ kACMP_HysteresisLevel3
Definition: fsl_acmp.h:76
@ kACMP_OutputAssertEventFlag
Definition: fsl_acmp.h:47
@ kACMP_OutputFallingEventFlag
Definition: fsl_acmp.h:46
@ kACMP_OutputRisingEventFlag
Definition: fsl_acmp.h:45
@ kACMP_FixedPlusPort
Definition: fsl_acmp.h:98
@ kACMP_FixedMinusPort
Definition: fsl_acmp.h:99
Definition: MIMXRT1052.h:10267
Configuration for channel.
Definition: fsl_acmp.h:131
Configuration for ACMP.
Definition: fsl_acmp.h:113
Configuration for DAC.
Definition: fsl_acmp.h:152
Configuration for filter.
Definition: fsl_acmp.h:144
Configuration for round robin mode.
Definition: fsl_acmp.h:167
Definition: deflate.c:114