1 /******************************************************************************
2 * Filename: aux_tdc.h
3 * Revised: 2015-11-03 09:54:47 +0100 (Tue, 03 Nov 2015)
4 * Revision: 44933
5 *
6 * Description: Defines and prototypes for the AUX Time-to-Digital Converter
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38
39 //*****************************************************************************
40 //
41 //! \addtogroup aux_group
42 //! @{
43 //! \addtogroup auxtdc_api
44 //! @{
45 //
46 //*****************************************************************************
47
48 #ifndef __AUX_TDC_H__
49 #define __AUX_TDC_H__
50
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_ints.h>
67 #include <inc/hw_aux_tdc.h>
68 #include <driverlib/debug.h>
69
70 //*****************************************************************************
71 //
72 // Support for DriverLib in ROM:
73 // This section renames all functions that are not "static inline", so that
74 // calling these functions will default to implementation in flash. At the end
75 // of this file a second renaming will change the defaults to implementation in
76 // ROM for available functions.
77 //
78 // To force use of the implementation in flash, e.g. for debugging:
79 // - Globally: Define DRIVERLIB_NOROM at project level
80 // - Per function: Use prefix "NOROM_" when calling the function
81 //
82 //*****************************************************************************
83 #if !defined(DOXYGEN)
84 #define AUXTDCConfigSet NOROM_AUXTDCConfigSet
85 #define AUXTDCMeasurementDone NOROM_AUXTDCMeasurementDone
86 #endif
87
88 //*****************************************************************************
89 //
90 // Defines for the status of a AUX TDC measurement.
91 //
92 //*****************************************************************************
93 #define AUX_TDC_BUSY 0x00000001
94 #define AUX_TDC_TIMEOUT 0x00000002
95 #define AUX_TDC_DONE 0x00000004
96
97 //*****************************************************************************
98 //
99 // Defines for the control of a AUX TDC.
100 //
101 //*****************************************************************************
102 #define AUX_TDC_RUNSYNC 0x00000001
103 #define AUX_TDC_RUN 0x00000002
104 #define AUX_TDC_ABORT 0x00000003
105
106 //*****************************************************************************
107 //
108 // Defines for possible states of the TDC internal state machine.
109 //
110 //*****************************************************************************
111 #define AUXTDC_WAIT_START (AUX_TDC_STAT_STATE_WAIT_START)
112 #define AUXTDC_WAIT_START_CNTEN (AUX_TDC_STAT_STATE_WAIT_START_STOP_CNT_EN)
113 #define AUXTDC_IDLE (AUX_TDC_STAT_STATE_IDLE)
114 #define AUXTDC_CLRCNT (AUX_TDC_STAT_STATE_CLR_CNT)
115 #define AUXTDC_WAIT_STOP (AUX_TDC_STAT_STATE_WAIT_STOP)
116 #define AUXTDC_WAIT_STOP_CNTDOWN (AUX_TDC_STAT_STATE_WAIT_STOP_CNTDWN)
117 #define AUXTDC_GETRESULTS (AUX_TDC_STAT_STATE_GET_RESULT)
118 #define AUXTDC_POR (AUX_TDC_STAT_STATE_POR)
119 #define AUXTDC_WAIT_CLRCNT_DONE (AUX_TDC_STAT_STATE_WAIT_CLR_CNT_DONE)
120 #define AUXTDC_START_FALL (AUX_TDC_STAT_STATE_START_FALL)
121 #define AUXTDC_FORCE_STOP (AUX_TDC_STAT_STATE_FORCE_STOP)
122
123 //*****************************************************************************
124 //
125 // Defines for controlling the AUX TDC. Values can be passed to AUXTDCConfigSet().
126 //
127 //*****************************************************************************
128 #define AUXTDC_STOPPOL_RIS (AUX_TDC_TRIGSRC_STOP_POL_HIGH) // Rising edge polarity for stop event
129 #define AUXTDC_STOPPOL_FALL (AUX_TDC_TRIGSRC_STOP_POL_LOW) // Falling edge polarity for stop event
130
131 #define AUXTDC_STOP_AON_RTC_CH2 (AUX_TDC_TRIGSRC_STOP_SRC_AON_RTC_CH2)
132 #define AUXTDC_STOP_AUX_COMPA (AUX_TDC_TRIGSRC_STOP_SRC_AUX_COMPA)
133 #define AUXTDC_STOP_AUX_COMPB (AUX_TDC_TRIGSRC_STOP_SRC_AUX_COMPB)
134 #define AUXTDC_STOP_ISRC_RESET (AUX_TDC_TRIGSRC_STOP_SRC_ISRC_RESET)
135 #define AUXTDC_STOP_TIMER0_EV (AUX_TDC_TRIGSRC_STOP_SRC_TIMER0_EV)
136 #define AUXTDC_STOP_TIMER1_EV (AUX_TDC_TRIGSRC_STOP_SRC_TIMER1_EV)
137 #define AUXTDC_STOP_SMPH_AUTOTAKE_DONE (AUX_TDC_TRIGSRC_STOP_SRC_SMPH_AUTOTAKE_DONE)
138 #define AUXTDC_STOP_ADC_DONE (AUX_TDC_TRIGSRC_STOP_SRC_ADC_DONE)
139 #define AUXTDC_STOP_ADC_FIFO_ALMOST_FULL (AUX_TDC_TRIGSRC_STOP_SRC_ADC_FIFO_ALMOST_FULL)
140 #define AUXTDC_STOP_OBSMUX0 (AUX_TDC_TRIGSRC_STOP_SRC_OBSMUX0)
141 #define AUXTDC_STOP_OBSMUX1 (AUX_TDC_TRIGSRC_STOP_SRC_OBSMUX1)
142 #define AUXTDC_STOP_AON_SW (AUX_TDC_TRIGSRC_STOP_SRC_AON_SW)
143 #define AUXTDC_STOP_AON_PROG_WU (AUX_TDC_TRIGSRC_STOP_SRC_AON_PROG_WU)
144 #define AUXTDC_STOP_AUXIO0 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO0)
145 #define AUXTDC_STOP_AUXIO1 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO1)
146 #define AUXTDC_STOP_AUXIO2 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO2)
147 #define AUXTDC_STOP_AUXIO3 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO3)
148 #define AUXTDC_STOP_AUXIO4 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO4)
149 #define AUXTDC_STOP_AUXIO5 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO5)
150 #define AUXTDC_STOP_AUXIO6 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO6)
151 #define AUXTDC_STOP_AUXIO7 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO7)
152 #define AUXTDC_STOP_AUXIO8 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO8)
153 #define AUXTDC_STOP_AUXIO9 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO9)
154 #define AUXTDC_STOP_AUXIO10 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO10)
155 #define AUXTDC_STOP_AUXIO11 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO11)
156 #define AUXTDC_STOP_AUXIO12 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO12)
157 #define AUXTDC_STOP_AUXIO13 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO13)
158 #define AUXTDC_STOP_AUXIO14 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO14)
159 #define AUXTDC_STOP_AUXIO15 (AUX_TDC_TRIGSRC_STOP_SRC_AUXIO15)
160 #define AUXTDC_STOP_ACLK_REF (AUX_TDC_TRIGSRC_STOP_SRC_ACLK_REF)
161 #define AUXTDC_STOP_MCU_EV (AUX_TDC_TRIGSRC_STOP_SRC_MCU_EV)
162 #define AUXTDC_STOP_TDC_PRE (AUX_TDC_TRIGSRC_STOP_SRC_TDC_PRE)
163
164 #define AUXTDC_STARTPOL_RIS (AUX_TDC_TRIGSRC_START_POL_HIGH) // Rising edge polarity for start event
165 #define AUXTDC_STARTPOL_FALL (AUX_TDC_TRIGSRC_START_POL_LOW) // Falling edge polarity for start event
166
167 #define AUXTDC_START_AON_RTC_CH2 (AUX_TDC_TRIGSRC_START_SRC_AON_RTC_CH2)
168 #define AUXTDC_START_AUX_COMPA (AUX_TDC_TRIGSRC_START_SRC_AUX_COMPA)
169 #define AUXTDC_START_AUX_COMPB (AUX_TDC_TRIGSRC_START_SRC_AUX_COMPB)
170 #define AUXTDC_START_ISRC_RESET (AUX_TDC_TRIGSRC_START_SRC_ISRC_RESET)
171 #define AUXTDC_START_TIMER0_EV (AUX_TDC_TRIGSRC_START_SRC_TIMER0_EV)
172 #define AUXTDC_START_TIMER1_EV (AUX_TDC_TRIGSRC_START_SRC_TIMER1_EV)
173 #define AUXTDC_START_SMPH_AUTOTAKE_DONE (AUX_TDC_TRIGSRC_START_SRC_SMPH_AUTOTAKE_DONE)
174 #define AUXTDC_START_ADC_DONE (AUX_TDC_TRIGSRC_START_SRC_ADC_DONE)
175 #define AUXTDC_START_ADC_FIFO_ALMOST_FULL (AUX_TDC_TRIGSRC_START_SRC_ADC_FIFO_ALMOST_FULL)
176 #define AUXTDC_START_OBSMUX0 (AUX_TDC_TRIGSRC_START_SRC_OBSMUX0)
177 #define AUXTDC_START_OBSMUX1 (AUX_TDC_TRIGSRC_START_SRC_OBSMUX1)
178 #define AUXTDC_START_AON_SW (AUX_TDC_TRIGSRC_START_SRC_AON_SW)
179 #define AUXTDC_START_AON_PROG_WU (AUX_TDC_TRIGSRC_START_SRC_AON_PROG_WU)
180 #define AUXTDC_START_AUXIO0 (AUX_TDC_TRIGSRC_START_SRC_AUXIO0)
181 #define AUXTDC_START_AUXIO1 (AUX_TDC_TRIGSRC_START_SRC_AUXIO1)
182 #define AUXTDC_START_AUXIO2 (AUX_TDC_TRIGSRC_START_SRC_AUXIO2)
183 #define AUXTDC_START_AUXIO3 (AUX_TDC_TRIGSRC_START_SRC_AUXIO3)
184 #define AUXTDC_START_AUXIO4 (AUX_TDC_TRIGSRC_START_SRC_AUXIO4)
185 #define AUXTDC_START_AUXIO5 (AUX_TDC_TRIGSRC_START_SRC_AUXIO5)
186 #define AUXTDC_START_AUXIO6 (AUX_TDC_TRIGSRC_START_SRC_AUXIO6)
187 #define AUXTDC_START_AUXIO7 (AUX_TDC_TRIGSRC_START_SRC_AUXIO7)
188 #define AUXTDC_START_AUXIO8 (AUX_TDC_TRIGSRC_START_SRC_AUXIO8)
189 #define AUXTDC_START_AUXIO9 (AUX_TDC_TRIGSRC_START_SRC_AUXIO9)
190 #define AUXTDC_START_AUXIO10 (AUX_TDC_TRIGSRC_START_SRC_AUXIO10)
191 #define AUXTDC_START_AUXIO11 (AUX_TDC_TRIGSRC_START_SRC_AUXIO11)
192 #define AUXTDC_START_AUXIO12 (AUX_TDC_TRIGSRC_START_SRC_AUXIO12)
193 #define AUXTDC_START_AUXIO13 (AUX_TDC_TRIGSRC_START_SRC_AUXIO13)
194 #define AUXTDC_START_AUXIO14 (AUX_TDC_TRIGSRC_START_SRC_AUXIO14)
195 #define AUXTDC_START_AUXIO15 (AUX_TDC_TRIGSRC_START_SRC_AUXIO15)
196 #define AUXTDC_START_ACLK_REF (AUX_TDC_TRIGSRC_START_SRC_ACLK_REF)
197 #define AUXTDC_START_MCU_EV (AUX_TDC_TRIGSRC_START_SRC_MCU_EV)
198 #define AUXTDC_START_TDC_PRE (AUX_TDC_TRIGSRC_START_SRC_TDC_PRE)
199
200 //*****************************************************************************
201 //
202 // Defines for the possible saturation values set using AUXTDCLimitSet().
203 //
204 //*****************************************************************************
205 #define AUXTDC_SAT_4096 (AUX_TDC_SATCFG_LIMIT_R12)
206 #define AUXTDC_SAT_8192 (AUX_TDC_SATCFG_LIMIT_R13)
207 #define AUXTDC_SAT_16384 (AUX_TDC_SATCFG_LIMIT_R14)
208 #define AUXTDC_SAT_32768 (AUX_TDC_SATCFG_LIMIT_R15)
209 #define AUXTDC_SAT_65536 (AUX_TDC_SATCFG_LIMIT_R16)
210 #define AUXTDC_SAT_131072 (AUX_TDC_SATCFG_LIMIT_R17)
211 #define AUXTDC_SAT_262144 (AUX_TDC_SATCFG_LIMIT_R18)
212 #define AUXTDC_SAT_524288 (AUX_TDC_SATCFG_LIMIT_R19)
213 #define AUXTDC_SAT_1048576 (AUX_TDC_SATCFG_LIMIT_R20)
214 #define AUXTDC_SAT_2097152 (AUX_TDC_SATCFG_LIMIT_R21)
215 #define AUXTDC_SAT_4194304 (AUX_TDC_SATCFG_LIMIT_R22)
216 #define AUXTDC_SAT_8388608 (AUX_TDC_SATCFG_LIMIT_R23)
217 #define AUXTDC_SAT_16777216 (AUX_TDC_SATCFG_LIMIT_R24)
218 #define AUXTDC_NUM_SAT_VALS 16
219
220 //*****************************************************************************
221 //
222 // API Functions and prototypes
223 //
224 //*****************************************************************************
225
226 #ifdef DRIVERLIB_DEBUG
227 //*****************************************************************************
228 //
229 //! \internal
230 //! \brief Checks an AUX TDC base address.
231 //!
232 //! This function determines if a AUX TDC port base address is valid.
233 //!
234 //! \param ui32Base is the base address of the AUX TDC port.
235 //!
236 //! \return Returns \c true if the base address is valid and \c false
237 //! otherwise.
238 //
239 //*****************************************************************************
240 static bool
AUXTDCBaseValid(uint32_t ui32Base)241 AUXTDCBaseValid(uint32_t ui32Base)
242 {
243 return(ui32Base == AUX_TDC_BASE);
244 }
245 #endif
246
247 //*****************************************************************************
248 //
249 //! \brief Get the status of the AUX TDC internal state machine.
250 //!
251 //! This function will return the current state of the AUX TDC internal state
252 //! machine.
253 //! \param ui32Base is base address of the AUX TDC
254 //!
255 //! \return Returns the current state of the state machine.
256 //! Possible states for the state machine are:
257 //! - \ref AUXTDC_WAIT_START
258 //! - \ref AUXTDC_WAIT_START_CNTEN
259 //! - \ref AUXTDC_IDLE
260 //! - \ref AUXTDC_CLRCNT
261 //! - \ref AUXTDC_WAIT_STOP
262 //! - \ref AUXTDC_WAIT_STOP_CNTDOWN
263 //! - \ref AUXTDC_GETRESULTS
264 //! - \ref AUXTDC_POR
265 //! - \ref AUXTDC_WAIT_CLRCNT_DONE
266 //! - \ref AUXTDC_START_FALL
267 //! - \ref AUXTDC_FORCE_STOP.
268 //
269 //*****************************************************************************
270 __STATIC_INLINE uint32_t
AUXTDCStatusGet(uint32_t ui32Base)271 AUXTDCStatusGet(uint32_t ui32Base)
272 {
273 //
274 // Check the arguments.
275 //
276 ASSERT(AUXTDCBaseValid(ui32Base));
277
278 //
279 // Return the status value for the correct ADI Slave.
280 //
281 return((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) >>
282 AUX_TDC_STAT_STATE_S);
283 }
284
285 //*****************************************************************************
286 //
287 //! \brief Configure the operation of the AUX TDC.
288 //!
289 //! Use this function to configure the start and stop event for the AUX TDC.
290 //!
291 //! The \c ui32StartCondition must be a bitwise OR of the start event and the
292 //! polarity of the start event. The start events are:
293 //! - \ref AUXTDC_START_AON_RTC_CH2
294 //! - \ref AUXTDC_START_AUX_COMPA
295 //! - \ref AUXTDC_START_AUX_COMPB
296 //! - \ref AUXTDC_START_ISRC_RESET
297 //! - \ref AUXTDC_START_TIMER0_EV
298 //! - \ref AUXTDC_START_TIMER1_EV
299 //! - \ref AUXTDC_START_SMPH_AUTOTAKE_DONE
300 //! - \ref AUXTDC_START_ADC_DONE
301 //! - \ref AUXTDC_START_ADC_FIFO_ALMOST_FULL
302 //! - \ref AUXTDC_START_OBSMUX0
303 //! - \ref AUXTDC_START_OBSMUX1
304 //! - \ref AUXTDC_START_AON_SW
305 //! - \ref AUXTDC_START_AON_PROG_WU
306 //! - \ref AUXTDC_START_AUXIO0
307 //! - \ref AUXTDC_START_AUXIO1
308 //! - \ref AUXTDC_START_AUXIO2
309 //! - \ref AUXTDC_START_AUXIO3
310 //! - \ref AUXTDC_START_AUXIO4
311 //! - \ref AUXTDC_START_AUXIO5
312 //! - \ref AUXTDC_START_AUXIO6
313 //! - \ref AUXTDC_START_AUXIO7
314 //! - \ref AUXTDC_START_AUXIO8
315 //! - \ref AUXTDC_START_AUXIO9
316 //! - \ref AUXTDC_START_AUXIO10
317 //! - \ref AUXTDC_START_AUXIO11
318 //! - \ref AUXTDC_START_AUXIO12
319 //! - \ref AUXTDC_START_AUXIO13
320 //! - \ref AUXTDC_START_AUXIO14
321 //! - \ref AUXTDC_START_AUXIO15
322 //! - \ref AUXTDC_START_ACLK_REF
323 //! - \ref AUXTDC_START_MCU_EV
324 //! - \ref AUXTDC_START_TDC_PRE
325 //!
326 //! The polarity of the start event is either rising \ref AUXTDC_STARTPOL_RIS
327 //! or falling \ref AUXTDC_STARTPOL_FALL.
328 //!
329 //! The \c ui32StopCondition must be a bitwise OR of the stop event and the
330 //! polarity of the stop event. The stop events are:
331 //! - \ref AUXTDC_STOP_AON_RTC_CH2
332 //! - \ref AUXTDC_STOP_AUX_COMPA
333 //! - \ref AUXTDC_STOP_AUX_COMPB
334 //! - \ref AUXTDC_STOP_ISRC_RESET
335 //! - \ref AUXTDC_STOP_TIMER0_EV
336 //! - \ref AUXTDC_STOP_TIMER1_EV
337 //! - \ref AUXTDC_STOP_SMPH_AUTOTAKE_DONE
338 //! - \ref AUXTDC_STOP_ADC_DONE
339 //! - \ref AUXTDC_STOP_ADC_FIFO_ALMOST_FULL
340 //! - \ref AUXTDC_STOP_OBSMUX0
341 //! - \ref AUXTDC_STOP_OBSMUX1
342 //! - \ref AUXTDC_STOP_AON_SW
343 //! - \ref AUXTDC_STOP_AON_PROG_WU
344 //! - \ref AUXTDC_STOP_AUXIO0
345 //! - \ref AUXTDC_STOP_AUXIO1
346 //! - \ref AUXTDC_STOP_AUXIO2
347 //! - \ref AUXTDC_STOP_AUXIO3
348 //! - \ref AUXTDC_STOP_AUXIO4
349 //! - \ref AUXTDC_STOP_AUXIO5
350 //! - \ref AUXTDC_STOP_AUXIO6
351 //! - \ref AUXTDC_STOP_AUXIO7
352 //! - \ref AUXTDC_STOP_AUXIO8
353 //! - \ref AUXTDC_STOP_AUXIO9
354 //! - \ref AUXTDC_STOP_AUXIO10
355 //! - \ref AUXTDC_STOP_AUXIO11
356 //! - \ref AUXTDC_STOP_AUXIO12
357 //! - \ref AUXTDC_STOP_AUXIO13
358 //! - \ref AUXTDC_STOP_AUXIO14
359 //! - \ref AUXTDC_STOP_AUXIO15
360 //! - \ref AUXTDC_STOP_ACLK_REF
361 //! - \ref AUXTDC_STOP_MCU_EV
362 //! - \ref AUXTDC_STOP_TDC_PRE
363 //!
364 //! The polarity of the stop event is either rising \ref AUXTDC_STOPPOL_RIS
365 //! or falling \ref AUXTDC_STOPPOL_FALL.
366 //!
367 //! \note The AUX TDC should only be configured when the AUX TDC is in the Idle
368 //! state. To ensure that software does not lock up, it is recommended to
369 //! ensure that the AUX TDC is actually in idle when calling \ref AUXTDCConfigSet().
370 //! This can be tested using \ref AUXTDCIdle().
371 //!
372 //! \param ui32Base is base address of the AUX TDC.
373 //! \param ui32StartCondition is AUX TDC a bitwise OR of a start event and polarity.
374 //! \param ui32StopCondition is AUX TDC a bitwise OR of a stop event and polarity.
375 //!
376 //! \return None
377 //!
378 //! \sa \ref AUXTDCConfigSet(), \ref AUXTDCIdle()
379 //
380 //*****************************************************************************
381 extern void AUXTDCConfigSet(uint32_t ui32Base, uint32_t ui32StartCondition,
382 uint32_t ui32StopCondition);
383
384 //*****************************************************************************
385 //
386 //! \brief Check if the AUX TDC is in idle mode.
387 //!
388 //! This function can be used to check whether the AUX TDC internal state
389 //! machine is in idle mode. This is required before setting the polarity
390 //! of the start and stop event.
391 //!
392 //! \param ui32Base is the base address of the AUX TDC.
393 //!
394 //! \return Returns \c true if state machine is in idle and returns \c false
395 //! if the state machine is in any other state.
396 //
397 //*****************************************************************************
398 __STATIC_INLINE bool
AUXTDCIdle(uint32_t ui32Base)399 AUXTDCIdle(uint32_t ui32Base)
400 {
401 //
402 // Check the arguments.
403 //
404 ASSERT(AUXTDCBaseValid(ui32Base));
405
406 //
407 // Check if the AUX TDC is in the Idle state.
408 //
409 return (((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
410 AUX_TDC_STAT_STATE_IDLE) ? true : false);
411 }
412
413 //*****************************************************************************
414 //
415 //! \brief Enable the AUX TDC for a measurement.
416 //!
417 //! This function is used for arming the AUX TDC to begin a measurement as
418 //! soon as the start condition is met. There are two run modes:
419 //! - \ref AUX_TDC_RUNSYNC will wait for a falling event of the start pulse before
420 //! starting measurement on next rising edge of start. This guarantees an edge
421 //! triggered start and is recommended for frequency measurements. If the
422 //! first falling edge is close to the start command it may be missed, but
423 //! the TDC shall catch later falling edges and in any case guarantee a
424 //! measurement start synchronous to the rising edge of the start event.
425 //! - The \ref AUX_TDC_RUN is asynchronous start and asynchronous stop mode. Using
426 //! this a TDC measurement may start immediately if start is high and hence it
427 //! may not give precise edge to edge measurements. This mode is only
428 //! recommended when start pulse is guaranteed to arrive at least 7 clock
429 //! periods after command.
430 //!
431 //! \note The AUX TDC should be configured and in Idle mode before calling this
432 //! function.
433 //!
434 //! \param ui32Base is the base address of the AUX TDC.
435 //! \param ui32RunMode is the run mode for the AUX TDC.
436 //! - \ref AUX_TDC_RUNSYNC : Synchronous run mode.
437 //! - \ref AUX_TDC_RUN : Asynchronous run mode.
438 //!
439 //! \return None
440 //
441 //*****************************************************************************
442 __STATIC_INLINE void
AUXTDCEnable(uint32_t ui32Base,uint32_t ui32RunMode)443 AUXTDCEnable(uint32_t ui32Base, uint32_t ui32RunMode)
444 {
445 //
446 // Check the arguments.
447 //
448 ASSERT(AUXTDCBaseValid(ui32Base));
449 ASSERT((ui32RunMode == AUX_TDC_RUN) ||
450 (ui32RunMode == AUX_TDC_RUNSYNC));
451
452 //
453 // Enable the AUX TDC.
454 //
455 HWREG(ui32Base + AUX_TDC_O_CTL) = ui32RunMode;
456 }
457
458 //*****************************************************************************
459 //
460 //! \brief Force the AUX TDC back to Idle mode.
461 //!
462 //! This function will force the AUX TDC in Idle mode. The internal state
463 //! machine will not go directly to Idle mode, so it is left to the programmer to
464 //! ensure that the state machine is in Idle mode before doing any new
465 //! configuration. This can be checked using \ref AUXTDCIdle().
466 //!
467 //! \param ui32Base is the base address of the AUX TDC.
468 //!
469 //! \return None
470 //!
471 //! \sa \ref AUXTDCIdle()
472 //
473 //*****************************************************************************
474 __STATIC_INLINE void
AUXTDCIdleForce(uint32_t ui32Base)475 AUXTDCIdleForce(uint32_t ui32Base)
476 {
477 //
478 // Check the arguments
479 //
480 ASSERT(AUXTDCBaseValid(ui32Base));
481
482 //
483 // Abort operation of AUX TDC and force into Idle mode.
484 //
485 HWREG(ui32Base + AUX_TDC_O_CTL) = AUX_TDC_CTL_CMD_ABORT;
486 }
487
488 //*****************************************************************************
489 //
490 //! \brief Check if the AUX TDC is done measuring.
491 //!
492 //! This function can be used to check whether the AUX TDC has finished a
493 //! measurement. The AUX TDC may have completed a measurement for two reasons.
494 //! Either it finish successfully \ref AUX_TDC_DONE or it failed due to a timeout
495 //! \ref AUX_TDC_TIMEOUT. If the AUX TDC is still measuring it this function
496 //! will return \ref AUX_TDC_BUSY.
497 //!
498 //! \param ui32Base is the base address of the AUX TDC.
499 //!
500 //! \return Returns the current status of a measurement:
501 //! - \ref AUX_TDC_DONE : An AUX TDC measurement finished successfully.
502 //! - \ref AUX_TDC_TIMEOUT : An AUX TDC measurement failed due to timeout.
503 //! - \ref AUX_TDC_BUSY : An AUX TDC measurement is being performed.
504 //
505 //*****************************************************************************
506 extern uint32_t AUXTDCMeasurementDone(uint32_t ui32Base);
507
508 //*****************************************************************************
509 //
510 //! \brief Get the value of the latest measurement.
511 //!
512 //! This function is used for retrieving the value of the latest measurement
513 //! performed by the AUX TDC.
514 //!
515 //! \param ui32Base is the base address of the AUX TDC.
516 //!
517 //! \return Returns the result of the latest measurement.
518 //
519 //*****************************************************************************
520 __STATIC_INLINE uint32_t
AUXTDCMeasurementGet(uint32_t ui32Base)521 AUXTDCMeasurementGet(uint32_t ui32Base)
522 {
523 //
524 // Check the arguments.
525 //
526 ASSERT(AUXTDCBaseValid(ui32Base));
527
528 //
529 // Return the measurement.
530 //
531 return (HWREG(ui32Base + AUX_TDC_O_RESULT));
532 }
533
534 //*****************************************************************************
535 //
536 //! \brief Set the saturation limit of the measurement.
537 //!
538 //! This function is used to set a saturation limit for the event accumulation
539 //! register. The saturation limit is defined as a bit width of the
540 //! accumulation register and therefore increases in power of 2.
541 //!
542 //! \param ui32Base is base address of the AUX TDC.
543 //! \param ui32Limit is the saturation limit.
544 //! - \ref AUXTDC_SAT_4096
545 //! - \ref AUXTDC_SAT_8192
546 //! - \ref AUXTDC_SAT_16384
547 //! - \ref AUXTDC_SAT_32768
548 //! - \ref AUXTDC_SAT_65536
549 //! - \ref AUXTDC_SAT_131072
550 //! - \ref AUXTDC_SAT_262144
551 //! - \ref AUXTDC_SAT_524288
552 //! - \ref AUXTDC_SAT_1048576
553 //! - \ref AUXTDC_SAT_2097152
554 //! - \ref AUXTDC_SAT_4194304
555 //! - \ref AUXTDC_SAT_8388608
556 //! - \ref AUXTDC_SAT_16777216 (default)
557 //!
558 //! \return None
559 //!
560 //! \note The actual value of the accumulation register might increase slightly beyond
561 //! the saturation value before the saturation takes effect.
562 //!
563 //! \sa \ref AUXTDCLimitGet()
564 //
565 //*****************************************************************************
566 __STATIC_INLINE void
AUXTDCLimitSet(uint32_t ui32Base,uint32_t ui32Limit)567 AUXTDCLimitSet(uint32_t ui32Base, uint32_t ui32Limit)
568 {
569 //
570 // Check the arguments.
571 //
572 ASSERT(AUXTDCBaseValid(ui32Base));
573 ASSERT(ui32Limit < AUXTDC_NUM_SAT_VALS);
574
575 //
576 // Set the saturation limit.
577 //
578 HWREG(ui32Base + AUX_TDC_O_SATCFG) = ui32Limit;
579 }
580
581 //*****************************************************************************
582 //
583 //! \brief Get the saturation limit of the measurement.
584 //!
585 //! This function is used to retrieve the current saturation for the
586 //! accumulator register.
587 //!
588 //! \param ui32Base is base address of the AUX TDC.
589 //!
590 //! \return Returns the saturation limit.
591 //! - \ref AUXTDC_SAT_4096
592 //! - \ref AUXTDC_SAT_8192
593 //! - \ref AUXTDC_SAT_16384
594 //! - \ref AUXTDC_SAT_32768
595 //! - \ref AUXTDC_SAT_65536
596 //! - \ref AUXTDC_SAT_131072
597 //! - \ref AUXTDC_SAT_262144
598 //! - \ref AUXTDC_SAT_524288
599 //! - \ref AUXTDC_SAT_1048576
600 //! - \ref AUXTDC_SAT_2097152
601 //! - \ref AUXTDC_SAT_4194304
602 //! - \ref AUXTDC_SAT_8388608
603 //! - \ref AUXTDC_SAT_16777216
604 //!
605 //! \sa \ref AUXTDCLimitSet()
606 //
607 //*****************************************************************************
608 __STATIC_INLINE uint32_t
AUXTDCLimitGet(uint32_t ui32Base)609 AUXTDCLimitGet(uint32_t ui32Base)
610 {
611 //
612 // Check the arguments.
613 //
614 ASSERT(AUXTDCBaseValid(ui32Base));
615
616 //
617 // Return the saturation limit.
618 //
619 return (HWREG(ui32Base + AUX_TDC_O_SATCFG));
620 }
621
622 //*****************************************************************************
623 //
624 //! \brief Enables the counter if possible.
625 //!
626 //! This function can be used to enable the AUX TDC stop/compare event counter.
627 //! The counter can be used to measure multiple periods of a clock signal.
628 //! For each stop/compare event the counter will be decremented by one and
629 //! the measurement will continue running until the value of the counter
630 //! reaches 0. The current value of the counter can be read using
631 //! \ref AUXTDCCounterGet(). The reset value of the counter can be set using
632 //! \ref AUXTDCCounterSet().
633 //!
634 //! \param ui32Base is base address of the AUX TDC.
635 //!
636 //! \return Returns \c true if the counter was successfully enabled. If the
637 //! AUX TDC is not in Idle mode, the counter can not be enabled, and the
638 //! return value will be \c false.
639 //!
640 //! \sa \ref AUXTDCCounterGet(), \ref AUXTDCCounterSet()
641 //
642 //*****************************************************************************
643 __STATIC_INLINE bool
AUXTDCCounterEnable(uint32_t ui32Base)644 AUXTDCCounterEnable(uint32_t ui32Base)
645 {
646 //
647 // Check the arguments.
648 //
649 ASSERT(AUXTDCBaseValid(ui32Base));
650
651 //
652 // Check if the AUX TDC is in idle mode. If not in Idle mode, the counter
653 // will not be enabled.
654 //
655 if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
656 AUX_TDC_STAT_STATE_IDLE))
657 {
658 return false;
659 }
660
661 //
662 // Enable the counter.
663 //
664 HWREG(ui32Base + AUX_TDC_O_TRIGCNTCFG) = AUX_TDC_TRIGCNTCFG_EN;
665
666 //
667 // Counter successfully enabled.
668 //
669 return true;
670 }
671
672 //*****************************************************************************
673 //
674 //! \brief Disables the counter if possible.
675 //!
676 //! This function can be used to disable the AUX TDC stop/compare event counter.
677 //!
678 //! \param ui32Base is base address of the AUX TDC.
679 //!
680 //! \return Returns \c true if the counter was successfully disabled. If the
681 //! AUX TDC is not in Idle mode, the counter can not be disabled, and the
682 //! return value will be \c false.
683 //!
684 //! \sa \ref AUXTDCCounterEnable() for more information on how to use the counter.
685 //
686 //*****************************************************************************
687 __STATIC_INLINE bool
AUXTDCCounterDisable(uint32_t ui32Base)688 AUXTDCCounterDisable(uint32_t ui32Base)
689 {
690 //
691 // Check the arguments.
692 //
693 ASSERT(AUXTDCBaseValid(ui32Base));
694
695 //
696 // Check if the AUX TDC is in Idle mode. If not in Idle mode, the counter
697 // will not be disabled.
698 //
699 if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
700 AUX_TDC_STAT_STATE_IDLE))
701 {
702 return false;
703 }
704
705 //
706 // Disable the counter.
707 //
708 HWREG(ui32Base + AUX_TDC_O_TRIGCNTCFG) = 0;
709
710 //
711 // Counter successfully disabled.
712 //
713 return true;
714 }
715
716 //*****************************************************************************
717 //
718 //! \brief Set the reset number of counter compare/stop event to ignore before taking
719 //! a measurement.
720 //!
721 //! This function loads the reset value of the counter with the specified
722 //! number of events to ignore. A reset in this context means the counter
723 //! has been disabled and then enabled.
724 //!
725 //! \param ui32Base is base address of the AUX TDC.
726 //! \param ui32Events is the number of compare/stop events to load into the
727 //! counter.
728 //!
729 //! \return Returns \c true if the counter was successfully updated. If the
730 //! AUX TDC is not in Idle mode, the counter can not be updated, and the
731 //! return value will be \c false.
732 //!
733 //! \sa \ref AUXTDCCounterEnable()
734 //
735 //*****************************************************************************
736 __STATIC_INLINE bool
AUXTDCCounterSet(uint32_t ui32Base,uint32_t ui32Events)737 AUXTDCCounterSet(uint32_t ui32Base, uint32_t ui32Events)
738 {
739 //
740 // Check the arguments.
741 //
742 ASSERT(AUXTDCBaseValid(ui32Base));
743
744 //
745 // Check if the AUX TDC is in idle mode. If not in idle mode, the counter
746 // will not be disabled.
747 //
748 if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
749 AUX_TDC_STAT_STATE_IDLE))
750 {
751 return false;
752 }
753
754 //
755 // Update the reset counter value.
756 //
757 HWREG(ui32Base + AUX_TDC_O_TRIGCNTLOAD) = ui32Events;
758
759 //
760 // Counter successfully updated.
761 //
762 return true;
763 }
764
765 //*****************************************************************************
766 //
767 //! \brief Get the current number of counter compare/stop event to ignore before
768 //! taking a measurement.
769 //!
770 //! This function returns the current value of compare/stop events before
771 //! a measurement is registered. This value is decremented by one for each
772 //! registered compare/stop event and will always be less than or equal the
773 //! reset value of the counter set using \ref AUXTDCCounterSet().
774 //!
775 //! \param ui32Base is base address of the AUX TDC.
776 //!
777 //! \return Returns the current value of compare/stop events ignored before a
778 //! measurement is performed.
779 //!
780 //! \sa \ref AUXTDCCounterEnable().
781 //
782 //*****************************************************************************
783 __STATIC_INLINE uint32_t
AUXTDCCounterGet(uint32_t ui32Base)784 AUXTDCCounterGet(uint32_t ui32Base)
785 {
786 //
787 // Check the arguments.
788 //
789 ASSERT(AUXTDCBaseValid(ui32Base));
790
791 //
792 // Return the current counter value.
793 //
794 return (HWREG(ui32Base + AUX_TDC_O_TRIGCNT));
795 }
796
797 //*****************************************************************************
798 //
799 // Support for DriverLib in ROM:
800 // Redirect to implementation in ROM when available.
801 //
802 //*****************************************************************************
803 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
804 #include <driverlib/rom.h>
805 #ifdef ROM_AUXTDCConfigSet
806 #undef AUXTDCConfigSet
807 #define AUXTDCConfigSet ROM_AUXTDCConfigSet
808 #endif
809 #ifdef ROM_AUXTDCMeasurementDone
810 #undef AUXTDCMeasurementDone
811 #define AUXTDCMeasurementDone ROM_AUXTDCMeasurementDone
812 #endif
813 #endif
814
815 //*****************************************************************************
816 //
817 // Mark the end of the C bindings section for C++ compilers.
818 //
819 //*****************************************************************************
820 #ifdef __cplusplus
821 }
822 #endif
823
824 #endif // __AUX_TDC_H__
825
826 //*****************************************************************************
827 //
828 //! Close the Doxygen group.
829 //! @}
830 //! @}
831 //
832 //*****************************************************************************
833