aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/inc/fsl_pdb_driver.h
blob: a65862376a0103232b444a4d8ef690817043662c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_PDB_DRIVER_H__
#define __FSL_PDB_DRIVER_H__

#include <stdint.h>
#include <stdbool.h>
#include "fsl_pdb_hal.h"
#if FSL_FEATURE_SOC_PDB_COUNT

/*!
 * @addtogroup pdb_driver
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/
/*!
 * @brief Defines the type of structure for configuring ADC's pre_trigger.
 * @internal gui name="ADC pre-trigger configuration" id="pdbAdcTrgCfg"
 */
typedef struct PdbAdcPreTriggerConfig
{
    uint32_t adcPreTriggerIdx; /*!< Setting pre_trigger's index. */
    bool preTriggerEnable; /*!< Enable the pre_trigger. */
    bool preTriggerOutputEnable; /*!< Enable the pre_trigger output. @internal gui name="Trigger output" id="AdcTriggerOutput" */
    bool preTriggerBackToBackEnable; /*!< Enable the back to back mode for ADC pre_trigger. @internal gui name="Back-To-Back mode" id="AdcBackToBackMode" */
} pdb_adc_pretrigger_config_t;

/*!
 * @brief Defines the type of flag for PDB pre-trigger events.
 * @internal gui name="DAC trigger configuration" id="pdbDacTrgCfg"
 */
typedef struct PdbDacIntervalConfig
{
    bool intervalTriggerEnable; /*!< Enable the DAC interval trigger. */
    bool extTriggerInputEnable; /*!< Enable DAC external trigger input . @internal gui name="External trigger" id="DacExternalTrigger" */
} pdb_dac_interval_config_t;

/*! @brief Table of base addresses for PDB instances. */
extern PDB_Type * const g_pdbBase[];

/*! @brief Table to save PDB IRQ enumeration numbers defined in CMSIS header file. */
extern const IRQn_Type g_pdbIrqId[PDB_INSTANCE_COUNT];

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Initializes the PDB counter and triggers input.
 *
 * This function initializes the PDB counter and triggers the input.
 * It resets PDB registers and enables the PDB clock. Therefore, it should be 
 * called before any other operation. After it is initialized, the PDB can
 * act as a triggered timer, which enables other features in PDB module.
 *
 * @param instance PDB instance ID.
 * @param userConfigPtr Pointer to the user configuration structure. See the "pdb_user_config_t".
 * @return Execution status.
 */
pdb_status_t PDB_DRV_Init(uint32_t instance, const pdb_timer_config_t *userConfigPtr);

/*!
 * @brief De-initializes the PDB module.
 *
 * This function de-initializes the PDB module.
 * Calling this function shuts down the PDB module and reduces the power consumption.
 *
 * @param instance PDB instance ID.
 * @return Execution status.
 */
pdb_status_t PDB_DRV_Deinit(uint32_t instance);

/*!
 * @brief Triggers the PDB with a software trigger.
 *
 * This function triggers the PDB with a software trigger.
 * When the PDB is set to use the software trigger as input, calling this function
 * triggers the PDB.
 *
 * @param instance PDB instance ID.
 */
void PDB_DRV_SoftTriggerCmd(uint32_t instance);

/*!
 * @brief Gets the current counter value in the PDB module.
 *
 * This function gets the current counter value.
 *
 * @param instance PDB instance ID.
 * @return Current PDB counter value.
 */
uint32_t PDB_DRV_GetTimerValue(uint32_t instance);

/*!
 * @brief Gets the PDB interrupt flag.
 *
 * This function gets the PDB interrupt flag. It is asserted if the PDB interrupt occurs.
 *
 * @param instance PDB instance ID.
 * @return Assertion of indicated event.
 */
bool PDB_DRV_GetTimerIntFlag(uint32_t instance);

/*!
 * @brief Clears the interrupt flag.
 *
 * This function clears the interrupt flag.
 *
 * @param instance PDB instance ID.
 */
void PDB_DRV_ClearTimerIntFlag(uint32_t instance);
   
/*!
 * @brief Executes the command of loading values.
 *
 * This function executes the command of loading values.
 *
 * @param instance PDB instance ID.
 * @param value Setting value.
 */
void PDB_DRV_LoadValuesCmd(uint32_t instance);

/*!
 * @brief Sets the value of timer modulus.
 *
 * This function sets the value of timer modulus.
 *
 * @param instance PDB instance ID.
 * @param value Setting value.
 */
void PDB_DRV_SetTimerModulusValue(uint32_t instance, uint32_t value);

/*!
 * @brief Sets the value for the timer interrupt.
 *
 * This function sets the value for the timer interrupt.
 *
 * @param instance PDB instance ID.
 * @param value Setting value.
 */
void PDB_DRV_SetValueForTimerInterrupt(uint32_t instance, uint32_t value);

/*!
 * @brief Configures the ADC pre_trigger in the PDB module.
 *
 * This function configures the ADC pre_trigger in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param configPtr Pointer to the user configuration structure. See the "pdb_adc_pretrigger_config_t".
 * @return Execution status.
 */
pdb_status_t PDB_DRV_ConfigAdcPreTrigger(uint32_t instance, uint32_t chn, const pdb_adc_pretrigger_config_t *configPtr);

/*!
 * @brief Gets the ADC pre_trigger flag in the PDB module.
 *
 * This function gets the ADC pre_trigger flags in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param preChnMask ADC pre_trigger channels mask.
 * @return Assertion of indicated flag.
 */    
uint32_t PDB_DRV_GetAdcPreTriggerFlags(uint32_t instance, uint32_t chn, uint32_t preChnMask);

/*!
 * @brief Clears the ADC pre_trigger flag in the PDB module.
 *
 * This function clears the ADC pre_trigger flags in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param preChnMask ADC pre_trigger channels mask.
 */    
void PDB_DRV_ClearAdcPreTriggerFlags(uint32_t instance, uint32_t chn, uint32_t preChnMask);

/*!
 * @brief Gets the ADC pre_trigger flag in the PDB module.
 *
 * This function gets the ADC pre_trigger flags in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param preChnMask ADC pre_trigger channels mask.
 * @return Assertion of indicated flag.
 */  
uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags(uint32_t instance, uint32_t chn, uint32_t preChnMask);

/*!
 * @brief Clears the ADC pre_trigger flag in the PDB module.
 *
 * This function clears the ADC pre_trigger sequence error flags in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param preChnMask ADC pre_trigger channels mask.
 */ 
void PDB_DRV_ClearAdcPreTriggerSeqErrFlags(uint32_t instance, uint32_t chn, uint32_t preChnMask);

/*!
 * @brief Sets the ADC pre_trigger delay value in the PDB module.
 *
 * This function sets Set the ADC pre_trigger delay value in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param chn ADC channel.
 * @param preChn ADC pre_channel.
 * @param value Setting value.
 */
void PDB_DRV_SetAdcPreTriggerDelayValue(uint32_t instance, uint32_t chn, uint32_t preChn, uint32_t value);

/*!
 * @brief Configures the DAC interval in the PDB module.
 *
 * This function configures the DAC interval in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param dacChn DAC channel.
 * @param configPtr Pointer to the user configuration structure. See the "pdb_dac_interval_config_t".
 * @return Execution status.
 */
pdb_status_t PDB_DRV_ConfigDacInterval(uint32_t instance, uint32_t dacChn, const pdb_dac_interval_config_t *configPtr);

/*!
 * @brief Sets the DAC interval value in the PDB module.
 *
 * This function sets the DAC interval value in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param dacChn DAC channel.
 * @param value Setting value.
 */
void PDB_DRV_SetDacIntervalValue(uint32_t instance, uint32_t dacChn, uint32_t value);

/*!
 * @brief Switches on/off the CMP pulse out in the PDB module.
 *
 * This function switches the CMP pulse on/off in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param pulseChnMask Pulse channel mask.
 * @param enable Switcher to assert the feature.
 */
void PDB_DRV_SetCmpPulseOutEnable(uint32_t instance, uint32_t pulseChnMask, bool enable);

/*!
 * @brief Sets the CMP pulse out delay value for high in the PDB module.
 *
 * This function sets the CMP pulse out delay value for high in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param pulseChn Pulse channel.
 * @param value Setting value.
 */
void PDB_DRV_SetCmpPulseOutDelayForHigh(uint32_t instance, uint32_t pulseChn, uint32_t value);

/*!
 * @brief Sets the CMP pulse out delay value for low in the PDB module.
 *
 * This function sets the CMP pulse out delay value for low in the PDB module.
 *
 * @param instance PDB instance ID.
 * @param pulseChn Pulse channel.
 * @param value Setting value.
 */
void PDB_DRV_SetCmpPulseOutDelayForLow(uint32_t instance, uint32_t pulseChn, uint32_t value);

#if defined(__cplusplus)
}
#endif

/*!
 *@}
 */

#endif
#endif /* __FSL_PDB_DRIVER_H__ */
/*******************************************************************************
 * EOF
 ******************************************************************************/