RTEMS 6.1-rc2
Loading...
Searching...
No Matches
fsl_adc_etc.h
1/*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_ADC_ETC_H_
10#define _FSL_ADC_ETC_H_
11
12#include "fsl_common.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
23#define FSL_ADC_ETC_DRIVER_VERSION (MAKE_VERSION(2, 2, 1))
25#define ADC_ETC_DMA_CTRL_TRGn_REQ_MASK 0xFF0000U
26
31{
32 kADC_ETC_Done0StatusFlagMask = 1U << 0U,
33 kADC_ETC_Done1StatusFlagMask = 1U << 1U,
34 kADC_ETC_Done2StatusFlagMask = 1U << 2U,
35#if defined(FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN) && FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN
36 kADC_ETC_Done3StatusFlagMask = 1U << 3U,
37 kADC_ETC_ErrorStatusFlagMask = 1U << 4U,
38#else
39 kADC_ETC_ErrorStatusFlagMask = 1U << 3U,
40#endif /* FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN */
41};
42
47{
48 /* External XBAR sources. Support HW or SW mode. */
49 kADC_ETC_Trg0TriggerSource = 0U, /* External XBAR trigger0 source. */
50 kADC_ETC_Trg1TriggerSource = 1U, /* External XBAR trigger1 source. */
51 kADC_ETC_Trg2TriggerSource = 2U, /* External XBAR trigger2 source. */
52 kADC_ETC_Trg3TriggerSource = 3U, /* External XBAR trigger3 source. */
53 kADC_ETC_Trg4TriggerSource = 4U, /* External XBAR trigger4 source. */
54 kADC_ETC_Trg5TriggerSource = 5U, /* External XBAR trigger5 source. */
55 kADC_ETC_Trg6TriggerSource = 6U, /* External XBAR trigger6 source. */
56 kADC_ETC_Trg7TriggerSource = 7U, /* External XBAR trigger7 source. */
57 /* External TSC sources. Only support HW mode. */
58 kADC_ETC_TSC0TriggerSource = 8U, /* External TSC trigger0 source. */
59 kADC_ETC_TSC1TriggerSource = 9U, /* External TSC trigger1 source. */
61
66{
67#if defined(FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN) && FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN
68 kADC_ETC_Done0InterruptEnable = 0U, /* Enable the DONE0 interrupt when ADC conversions complete. */
69 kADC_ETC_Done1InterruptEnable = 1U, /* Enable the DONE1 interrupt when ADC conversions complete. */
70 kADC_ETC_Done2InterruptEnable = 2U, /* Enable the DONE2 interrupt when ADC conversions complete. */
71 kADC_ETC_Done3InterruptEnable = 3U, /* Enable the DONE3 interrupt when ADC conversions complete. */
72#else
73 kADC_ETC_InterruptDisable = 0U, /* Disable the ADC_ETC interrupt. */
74 kADC_ETC_Done0InterruptEnable = 1U, /* Enable the DONE0 interrupt when ADC conversions complete. */
75 kADC_ETC_Done1InterruptEnable = 2U, /* Enable the DONE1 interrupt when ADC conversions complete. */
76 kADC_ETC_Done2InterruptEnable = 3U, /* Enable the DONE2 interrupt when ADC conversions complete. */
77#endif /* FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN */
79
80#if defined(FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL) && FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL
84typedef enum _adc_etc_dma_mode_selection
85{
86 kADC_ETC_TrigDMAWithLatchedSignal =
87 0U, /* Trig DMA_REQ with latched signal, REQ will be cleared when ACK and source request cleared. */
88 kADC_ETC_TrigDMAWithPulsedSignal = 1U, /* Trig DMA_REQ with pulsed signal, REQ will be cleared by ACK only. */
89} adc_etc_dma_mode_selection_t;
90#endif /*FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL*/
91
95typedef struct _adc_etc_config
96{
97#if ((!(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG)) || \
98 (!(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG)))
99 bool enableTSCBypass; /* If bypass TSC, TSC would trigger ADC directly.
100 Otherwise TSC would trigger ADC through ADC_ETC. */
101#endif
102
103#if !(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG)
104 bool enableTSC0Trigger; /* Enable external TSC0 trigger. It is valid when enableTSCBypass = false. */
105#endif /* FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG */
106
107#if !(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG)
108 bool enableTSC1Trigger; /* Enable external TSC1 trigger. It is valid when enableTSCBypass = false.*/
109#endif /* FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG */
110
111#if defined(FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL) && FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL
112 adc_etc_dma_mode_selection_t dmaMode; /* Select the ADC_ETC DMA mode. */
113#endif /*FSL_FEATURE_ADC_ETC_HAS_CTRL_DMA_MODE_SEL*/
114
115#if !(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG)
116 uint32_t TSC0triggerPriority; /* External TSC0 trigger priority, 7 is highest, 0 is lowest. */
117#endif /* FSL_FEATURE_ADC_ETC_HAS_NO_TSC0_TRIG */
118
119#if !(defined(FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG) && FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG)
120 uint32_t TSC1triggerPriority; /* External TSC1 trigger priority, 7 is highest, 0 is lowest. */
121#endif /* FSL_FEATURE_ADC_ETC_HAS_NO_TSC1_TRIG */
122 uint32_t clockPreDivider; /* Pre-divider for trig delay and interval. Available range is 0-255.
123 Clock would be divided by (clockPreDivider+1). */
124 uint32_t XBARtriggerMask; /* Enable the corresponding trigger source. Available range is trigger0:0x01 to
125 trigger7:0x80
126 For example, XBARtriggerMask = 0x7U, which means trigger0, trigger1 and trigger2 is
127 enabled. */
129
134{
135 bool enableB2BMode; /* Enable ADC_ETC BackToBack mode. when not enabled B2B mode,
136 wait until interval delay is reached. */
137 uint32_t ADCHCRegisterSelect; /* Select relevant ADC_HCx register to trigger. 1U : HC0, 2U: HC1, 4U: HC2 ... */
138 uint32_t ADCChannelSelect; /* Select ADC sample channel. */
139 adc_etc_interrupt_enable_t InterruptEnable; /* Enable/disable Interrupt. */
140#if defined(FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN) && FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN
141 bool enableIrq; /* Enable IRQ for selected interrupt enable choice in "InterruptEnable" */
142#endif /* FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN */
144
149{
150 bool enableSyncMode; /* Enable the sync Mode, In SyncMode ADC1 and ADC2 are controlled by the same trigger source.
151 In AsyncMode ADC1 and ADC2 are controlled by separate trigger source. */
152 bool enableSWTriggerMode; /* Enable the sofware trigger mode. */
153 uint32_t triggerChainLength; /* TRIG chain length to the ADC. 0: Trig length is 1. ... 7: Trig length is 8. */
154 uint32_t triggerPriority; /* External trigger priority, 7 is highest, 0 is lowest. */
155 uint32_t sampleIntervalDelay; /* Set sampling interval delay. */
156 uint32_t initialDelay; /* Set trigger initial delay. */
158
159/*******************************************************************************
160 * API
161 ******************************************************************************/
162#if defined(__cplusplus)
163extern "C" {
164#endif
165
178
184void ADC_ETC_Deinit(ADC_ETC_Type *base);
185
202
210void ADC_ETC_SetTriggerConfig(ADC_ETC_Type *base, uint32_t triggerGroup, const adc_etc_trigger_config_t *config);
211
223 uint32_t triggerGroup,
224 uint32_t chainGroup,
226
236
246 uint32_t mask);
247
254static inline void ADC_ETC_EnableDMA(ADC_ETC_Type *base, uint32_t triggerGroup)
255{
256 /* Avoid clearing status flags at the same time. */
257 base->DMA_CTRL = (base->DMA_CTRL | ((uint32_t)ADC_ETC_DMA_CTRL_TRIG0_ENABLE_MASK << (uint32_t)triggerGroup)) &
258 ~ADC_ETC_DMA_CTRL_TRGn_REQ_MASK;
259}
260
267static inline void ADC_ETC_DisableDMA(ADC_ETC_Type *base, uint32_t triggerGroup)
268{
269 /* Avoid clearing status flags at the same time. */
270 base->DMA_CTRL = (base->DMA_CTRL & ~((uint32_t)ADC_ETC_DMA_CTRL_TRIG0_ENABLE_MASK << (uint32_t)triggerGroup)) &
271 ~ADC_ETC_DMA_CTRL_TRGn_REQ_MASK;
272}
273
281static inline uint32_t ADC_ETC_GetDMAStatusFlags(ADC_ETC_Type *base)
282{
283 return (((base->DMA_CTRL) & ADC_ETC_DMA_CTRL_TRGn_REQ_MASK) >> ADC_ETC_DMA_CTRL_TRIG0_REQ_SHIFT);
284}
285
293static inline void ADC_ETC_ClearDMAStatusFlags(ADC_ETC_Type *base, uint32_t mask)
294{
295 base->DMA_CTRL = ((base->DMA_CTRL) & ~ADC_ETC_DMA_CTRL_TRGn_REQ_MASK) | (mask << ADC_ETC_DMA_CTRL_TRIG0_REQ_SHIFT);
296}
297
304static inline void ADC_ETC_DoSoftwareReset(ADC_ETC_Type *base, bool enable)
305{
306 if (enable)
307 {
308 base->CTRL |= ADC_ETC_CTRL_SOFTRST_MASK;
309 }
310 else
311 {
312 base->CTRL &= ~ADC_ETC_CTRL_SOFTRST_MASK;
313 }
314}
315
325static inline void ADC_ETC_DoSoftwareTrigger(ADC_ETC_Type *base, uint32_t triggerGroup)
326{
327 assert(triggerGroup < ADC_ETC_TRIGn_CTRL_COUNT);
328
329 base->TRIG[triggerGroup].TRIGn_CTRL |= ADC_ETC_TRIGn_CTRL_SW_TRIG_MASK;
330}
331
342uint32_t ADC_ETC_GetADCConversionValue(ADC_ETC_Type *base, uint32_t triggerGroup, uint32_t chainGroup);
343
344/* @} */
345
346#if defined(__cplusplus)
347}
348#endif
349
350/* @} */
351
352#endif /* _FSL_ADC_ETC_H_ */
void ADC_ETC_ClearInterruptStatusFlags(ADC_ETC_Type *base, adc_etc_external_trigger_source_t sourceIndex, uint32_t mask)
Clears the ADC_ETC's interrupt status falgs.
Definition: fsl_adc_etc.c:373
enum _adc_etc_external_trigger_source adc_etc_external_trigger_source_t
External triggers sources.
void ADC_ETC_SetTriggerChainConfig(ADC_ETC_Type *base, uint32_t triggerGroup, uint32_t chainGroup, const adc_etc_trigger_chain_config_t *config)
Set the external XBAR trigger chain configuration. For example, if triggerGroup is set to 0U and chai...
Definition: fsl_adc_etc.c:227
enum _adc_etc_interrupt_enable adc_etc_interrupt_enable_t
Interrupt enable/disable mask.
_adc_etc_external_trigger_source
External triggers sources.
Definition: fsl_adc_etc.h:47
uint32_t ADC_ETC_GetADCConversionValue(ADC_ETC_Type *base, uint32_t triggerGroup, uint32_t chainGroup)
Get ADC conversion result from external XBAR sources. For example, if triggerGroup is set to 0U and c...
Definition: fsl_adc_etc.c:409
void ADC_ETC_SetTriggerConfig(ADC_ETC_Type *base, uint32_t triggerGroup, const adc_etc_trigger_config_t *config)
Set the external XBAR trigger configuration.
Definition: fsl_adc_etc.c:191
struct _adc_etc_config adc_etc_config_t
ADC_ETC configuration.
struct _adc_etc_trigger_chain_config adc_etc_trigger_chain_config_t
ADC_ETC trigger chain configuration.
void ADC_ETC_Init(ADC_ETC_Type *base, const adc_etc_config_t *config)
Initialize the ADC_ETC module.
Definition: fsl_adc_etc.c:66
struct _adc_etc_trigger_config adc_etc_trigger_config_t
ADC_ETC trigger configuration.
uint32_t ADC_ETC_GetInterruptStatusFlags(ADC_ETC_Type *base, adc_etc_external_trigger_source_t sourceIndex)
Gets the interrupt status flags of external XBAR and TSC triggers.
Definition: fsl_adc_etc.c:332
void ADC_ETC_GetDefaultConfig(adc_etc_config_t *config)
Gets an available pre-defined settings for the ADC_ETC's configuration. This function initializes the...
Definition: fsl_adc_etc.c:151
_adc_etc_status_flag_mask
ADC_ETC customized status flags mask.
Definition: fsl_adc_etc.h:31
#define ADC_ETC_DMA_CTRL_TRGn_REQ_MASK
The mask of status flags cleared by writing 1.
Definition: fsl_adc_etc.h:25
_adc_etc_interrupt_enable
Interrupt enable/disable mask.
Definition: fsl_adc_etc.h:66
void ADC_ETC_Deinit(ADC_ETC_Type *base)
De-Initialize the ADC_ETC module.
Definition: fsl_adc_etc.c:123
Definition: MIMXRT1052.h:1683
ADC_ETC configuration.
Definition: fsl_adc_etc.h:96
ADC_ETC trigger chain configuration.
Definition: fsl_adc_etc.h:134
ADC_ETC trigger configuration.
Definition: fsl_adc_etc.h:149
Definition: deflate.c:114