CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
aux_tdc.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: aux_tdc.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
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 //
43 //
44 //*****************************************************************************
45 
46 #ifndef __AUX_TDC_H__
47 #define __AUX_TDC_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_memmap.h>
64 #include <inc/hw_ints.h>
65 #include <inc/hw_aux_tdc.h>
66 #include <driverlib/debug.h>
67 
68 //*****************************************************************************
69 //
70 // Support for DriverLib in ROM:
71 // This section renames all functions that are not "static inline", so that
72 // calling these functions will default to implementation in flash. At the end
73 // of this file a second renaming will change the defaults to implementation in
74 // ROM for available functions.
75 //
76 // To force use of the implementation in flash, e.g. for debugging:
77 // - Globally: Define DRIVERLIB_NOROM at project level
78 // - Per function: Use prefix "NOROM_" when calling the function
79 //
80 // Do not define DRIVERLIB_GENERATE_ROM!
81 //
82 //*****************************************************************************
83 #ifndef DRIVERLIB_GENERATE_ROM
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 AUXTDCConfig().
126 //
127 //*****************************************************************************
128 #define AUXTDC_STOPPOL_RIS 0x00000000 // Rising edge polarity for stop
129  // event
130 #define AUXTDC_STOPPOL_FALL 0x00002000 // Falling edge polarity for stop
131  // event
132 #define AUXTDC_STOP_AON_WUC 0x00000000
133 #define AUXTDC_STOP_CMP_A 0x00000100
134 #define AUXTDC_STOP_CMP_B 0x00000200
135 #define AUXTDC_STOP_CS_RESET 0x00000300
136 #define AUXTDC_STOP_TIMER0 0x00000400
137 #define AUXTDC_STOP_TIMER1 0x00000500
138 #define AUXTDC_STOP_ADC_DONE 0x00000700
139 #define AUXTDC_STOP_AIO0 0x00000D00
140 #define AUXTDC_STOP_AIO1 0x00000E00
141 #define AUXTDC_STOP_AIO2 0x00000F00
142 #define AUXTDC_STOP_AIO3 0x00001000
143 #define AUXTDC_STOP_AIO4 0x00001100
144 #define AUXTDC_STOP_AIO5 0x00001200
145 #define AUXTDC_STOP_AIO6 0x00001300
146 #define AUXTDC_STOP_AIO7 0x00001400
147 #define AUXTDC_STOP_AIO8 0x00001500
148 #define AUXTDC_STOP_AIO9 0x00001600
149 #define AUXTDC_STOP_AIO10 0x00001700
150 #define AUXTDC_STOP_AIO11 0x00001800
151 #define AUXTDC_STOP_AIO12 0x00001900
152 #define AUXTDC_STOP_AIO13 0x00001A00
153 #define AUXTDC_STOP_AIO14 0x00001B00
154 #define AUXTDC_STOP_AIO15 0x00001C00
155 #define AUXTDC_STOP_ACLK 0x00001D00
156 #define AUXTDC_STOP_MCU_EVT 0x00001E00
157 #define AUXTDC_STOP_PRESCALER 0x00001F00
158 
159 #define AUXTDC_STARTPOL_RIS 0x00000000 // Rising edge polarity for start
160  // event
161 #define AUXTDC_STARTPOL_FALL 0x00002000 // Falling edge polarity for start
162  // event
163 #define AUXTDC_START_AON_WUC 0x00000000
164 #define AUXTDC_START_CMP_A 0x00000001
165 #define AUXTDC_START_CMP_B 0x00000002
166 #define AUXTDC_START_CS_RESET 0x00000003
167 #define AUXTDC_START_TIMER0 0x00000004
168 #define AUXTDC_START_TIMER1 0x00000005
169 #define AUXTDC_START_ADC_DONE 0x00000007
170 #define AUXTDC_START_AIO0 0x0000000D
171 #define AUXTDC_START_AIO1 0x0000000E
172 #define AUXTDC_START_AIO2 0x0000000F
173 #define AUXTDC_START_AIO3 0x00000010
174 #define AUXTDC_START_AIO4 0x00000011
175 #define AUXTDC_START_AIO5 0x00000012
176 #define AUXTDC_START_AIO6 0x00000013
177 #define AUXTDC_START_AIO7 0x00000014
178 #define AUXTDC_START_AIO8 0x00000015
179 #define AUXTDC_START_AIO9 0x00000016
180 #define AUXTDC_START_AIO10 0x00000017
181 #define AUXTDC_START_AIO11 0x00000018
182 #define AUXTDC_START_AIO12 0x00000019
183 #define AUXTDC_START_AIO13 0x0000001A
184 #define AUXTDC_START_AIO14 0x0000001B
185 #define AUXTDC_START_AIO15 0x0000001C
186 #define AUXTDC_START_ACLK 0x0000001D
187 #define AUXTDC_START_MCU_EVT 0x0000001E
188 #define AUXTDC_START_PRESCALER 0x0000001F
189 
190 //*****************************************************************************
191 //
192 // Defines for the possible saturation values set using AUXTDCLimitSet().
193 //
194 //*****************************************************************************
195 #define AUXTDC_SAT_512 0x00000000
196 #define AUXTDC_SAT_1024 0x00000001
197 #define AUXTDC_SAT_2048 0x00000002
198 #define AUXTDC_SAT_4096 0x00000003
199 #define AUXTDC_SAT_8192 0x00000004
200 #define AUXTDC_SAT_16384 0x00000005
201 #define AUXTDC_SAT_32768 0x00000006
202 #define AUXTDC_SAT_65536 0x00000007
203 #define AUXTDC_SAT_131072 0x00000008
204 #define AUXTDC_SAT_262144 0x00000009
205 #define AUXTDC_SAT_524288 0x0000000A
206 #define AUXTDC_SAT_1048576 0x0000000B
207 #define AUXTDC_SAT_2097152 0x0000000C
208 #define AUXTDC_SAT_4194304 0x0000000D
209 #define AUXTDC_SAT_8388608 0x0000000E
210 #define AUXTDC_SAT_WRAP_AROUND 0x0000000F
211 #define AUXTDC_NUM_SAT_VALS 16
212 
213 //*****************************************************************************
214 //
215 // API Functions and prototypes
216 //
217 //*****************************************************************************
218 
219 #ifdef DRIVERLIB_DEBUG
220 //*****************************************************************************
221 //
231 //
232 //*****************************************************************************
233 static bool
234 AUXTDCBaseValid(uint32_t ui32Base)
235 {
236  return(ui32Base == AUX_TDCIF_BASE);
237 }
238 #endif
239 
240 //*****************************************************************************
241 //
261 //
262 //*****************************************************************************
263 __STATIC_INLINE uint32_t
264 AUXTDCStatusGet(uint32_t ui32Base)
265 {
266  //
267  // Check the arguments.
268  //
269  ASSERT(AUXTDCBaseValid(ui32Base));
270 
271  //
272  // Return the status value for the correct ADI Slave.
273  //
274  return((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) >>
275  AUX_TDC_STAT_STATE_S);
276 }
277 
278 //*****************************************************************************
279 //
360 //
361 //*****************************************************************************
362 extern void AUXTDCConfigSet(uint32_t ui32Base, uint32_t ui32StartCondition,
363  uint32_t ui32StopCondition);
364 
365 //*****************************************************************************
366 //
377 //
378 //*****************************************************************************
379 __STATIC_INLINE bool
380 AUXTDCIdle(uint32_t ui32Base)
381 {
382  //
383  // Check the arguments.
384  //
385  ASSERT(AUXTDCBaseValid(ui32Base));
386 
387  //
388  // Check if the AUX TDC is in the Idle state.
389  //
390  return (((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
391  AUX_TDC_STAT_STATE_IDLE) ? true : false);
392 }
393 
394 //*****************************************************************************
395 //
421 //
422 //*****************************************************************************
423 __STATIC_INLINE void
424 AUXTDCEnable(uint32_t ui32Base, uint32_t ui32RunMode)
425 {
426  //
427  // Check the arguments.
428  //
429  ASSERT(AUXTDCBaseValid(ui32Base));
430  ASSERT((ui32RunMode == AUX_TDC_RUN) ||
431  (ui32RunMode == AUX_TDC_RUNSYNC));
432 
433  //
434  // Enable the AUX TDC.
435  //
436  HWREG(ui32Base + AUX_TDC_O_CTL) = ui32RunMode;
437 }
438 
439 //*****************************************************************************
440 //
453 //
454 //*****************************************************************************
455 __STATIC_INLINE void
456 AUXTDCIdleForce(uint32_t ui32Base)
457 {
458  //
459  // Check the arguments
460  //
461  ASSERT(AUXTDCBaseValid(ui32Base));
462 
463  //
464  // Abort operation of AUX TDC and force into Idle mode.
465  //
466  HWREG(ui32Base + AUX_TDC_O_CTL) = AUX_TDC_CTL_CMD_ABORT;
467 }
468 
469 //*****************************************************************************
470 //
485 //
486 //*****************************************************************************
487 extern uint32_t AUXTDCMeasurementDone(uint32_t ui32Base);
488 
489 //*****************************************************************************
490 //
499 //
500 //*****************************************************************************
501 __STATIC_INLINE uint32_t
502 AUXTDCMeasurementGet(uint32_t ui32Base)
503 {
504  //
505  // Check the arguments.
506  //
507  ASSERT(AUXTDCBaseValid(ui32Base));
508 
509  //
510  // Return the measurement.
511  //
512  return (HWREG(ui32Base + AUX_TDC_O_RESULT));
513 }
514 
515 //*****************************************************************************
516 //
542 //
543 //*****************************************************************************
544 __STATIC_INLINE void
545 AUXTDCLimitSet(uint32_t ui32Base, uint32_t ui32Limit)
546 {
547  //
548  // Check the arguments.
549  //
550  ASSERT(AUXTDCBaseValid(ui32Base));
551  ASSERT(ui32Limit < AUXTDC_NUM_SAT_VALS);
552 
553  //
554  // Set the saturation limit.
555  //
556  HWREG(ui32Base + AUX_TDC_O_SATCFG) = ui32Limit;
557 }
558 
559 //*****************************************************************************
560 //
584 //
585 //*****************************************************************************
586 __STATIC_INLINE uint32_t
587 AUXTDCLimitGet(uint32_t ui32Base)
588 {
589  //
590  // Check the arguments.
591  //
592  ASSERT(AUXTDCBaseValid(ui32Base));
593 
594  //
595  // Return the saturation limit.
596  //
597  return (HWREG(ui32Base + AUX_TDC_O_SATCFG));
598 }
599 
600 //*****************************************************************************
601 //
619 //
620 //*****************************************************************************
621 __STATIC_INLINE bool
622 AUXTDCCounterEnable(uint32_t ui32Base)
623 {
624  //
625  // Check the arguments.
626  //
627  ASSERT(AUXTDCBaseValid(ui32Base));
628 
629  //
630  // Check if the AUX TDC is in idle mode. If not in Idle mode, the counter
631  // will not be enabled.
632  //
633  if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
634  AUX_TDC_STAT_STATE_IDLE))
635  {
636  return false;
637  }
638 
639  //
640  // Enable the counter.
641  //
642  HWREG(ui32Base + AUX_TDC_O_TRIGCNTCFG) = AUX_TDC_TRIGCNTCFG_EN;
643 
644  //
645  // Counter succesfully enabled.
646  //
647  return true;
648 }
649 
650 //*****************************************************************************
651 //
663 //
664 //*****************************************************************************
665 __STATIC_INLINE bool
666 AUXTDCCounterDisable(uint32_t ui32Base)
667 {
668  //
669  // Check the arguments.
670  //
671  ASSERT(AUXTDCBaseValid(ui32Base));
672 
673  //
674  // Check if the AUX TDC is in Idle mode. If not in Idle mode, the counter
675  // will not be disabled.
676  //
677  if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
678  AUX_TDC_STAT_STATE_IDLE))
679  {
680  return false;
681  }
682 
683  //
684  // Disable the counter.
685  //
686  HWREG(ui32Base + AUX_TDC_O_TRIGCNTCFG) = 0;
687 
688  //
689  // Counter succesfull disabled.
690  //
691  return true;
692 }
693 
694 //*****************************************************************************
695 //
712 //
713 //*****************************************************************************
714 __STATIC_INLINE bool
715 AUXTDCCounterSet(uint32_t ui32Base, uint32_t ui32Events)
716 {
717  //
718  // Check the arguments.
719  //
720  ASSERT(AUXTDCBaseValid(ui32Base));
721 
722  //
723  // Check if the AUX TDC is in idle mode. If not in idle mode, the counter
724  // will not be disabled.
725  //
726  if(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
727  AUX_TDC_STAT_STATE_IDLE))
728  {
729  return false;
730  }
731 
732  //
733  // Update the reset counter value.
734  //
735  HWREG(ui32Base + AUX_TDC_O_TRIGCNTLOAD) = ui32Events;
736 
737  //
738  // Counter succesfully updated.
739  //
740  return true;
741 }
742 
743 //*****************************************************************************
744 //
759 //
760 //*****************************************************************************
761 __STATIC_INLINE uint32_t
762 AUXTDCCounterGet(uint32_t ui32Base)
763 {
764  //
765  // Check the arguments.
766  //
767  ASSERT(AUXTDCBaseValid(ui32Base));
768 
769  //
770  // Return the current counter value.
771  //
772  return (HWREG(ui32Base + AUX_TDC_O_TRIGCNT));
773 }
774 
775 //*****************************************************************************
776 //
777 // Support for DriverLib in ROM:
778 // Redirect to implementation in ROM when available.
779 //
780 //*****************************************************************************
781 #ifndef DRIVERLIB_NOROM
782  #include <driverlib/rom.h>
783  #ifdef ROM_AUXTDCConfigSet
784  #undef AUXTDCConfigSet
785  #define AUXTDCConfigSet ROM_AUXTDCConfigSet
786  #endif
787  #ifdef ROM_AUXTDCMeasurementDone
788  #undef AUXTDCMeasurementDone
789  #define AUXTDCMeasurementDone ROM_AUXTDCMeasurementDone
790  #endif
791 #endif
792 
793 //*****************************************************************************
794 //
795 // Mark the end of the C bindings section for C++ compilers.
796 //
797 //*****************************************************************************
798 #ifdef __cplusplus
799 }
800 #endif
801 
802 #endif // __AUX_TDC_H__
803 
804 //*****************************************************************************
805 //
808 //
809 //*****************************************************************************
__STATIC_INLINE uint32_t AUXTDCLimitGet(uint32_t ui32Base)
Get the saturation limit of the measurement.
Definition: aux_tdc.h:587
#define AUX_TDC_RUNSYNC
Definition: aux_tdc.h:102
__STATIC_INLINE uint32_t AUXTDCMeasurementGet(uint32_t ui32Base)
Get the value of the latest measurement.
Definition: aux_tdc.h:502
#define ASSERT(expr)
Definition: debug.h:65
void AUXTDCConfigSet(uint32_t ui32Base, uint32_t ui32StartCondition, uint32_t ui32StopCondition)
Configure the operation of the AUX TDC.
Definition: aux_tdc.c:60
__STATIC_INLINE void AUXTDCLimitSet(uint32_t ui32Base, uint32_t ui32Limit)
Set the saturation limit of the measurement.
Definition: aux_tdc.h:545
__STATIC_INLINE uint32_t AUXTDCCounterGet(uint32_t ui32Base)
Get the current number of counter compare/stop event to ignore before taking a measurement.
Definition: aux_tdc.h:762
#define AUXTDC_NUM_SAT_VALS
Definition: aux_tdc.h:211
__STATIC_INLINE uint32_t AUXTDCStatusGet(uint32_t ui32Base)
Get the status of the AUX TDC internal state machine.
Definition: aux_tdc.h:264
__STATIC_INLINE bool AUXTDCCounterEnable(uint32_t ui32Base)
Enables the counter if possible.
Definition: aux_tdc.h:622
__STATIC_INLINE void AUXTDCIdleForce(uint32_t ui32Base)
Force the AUX TDC back to Idle mode.
Definition: aux_tdc.h:456
#define AUX_TDC_RUN
Definition: aux_tdc.h:103
__STATIC_INLINE bool AUXTDCIdle(uint32_t ui32Base)
Check if the AUX TDC is in idle mode.
Definition: aux_tdc.h:380
uint32_t AUXTDCMeasurementDone(uint32_t ui32Base)
Check if the AUX TDC is done measuring.
Definition: aux_tdc.c:94
__STATIC_INLINE bool AUXTDCCounterDisable(uint32_t ui32Base)
Disables the counter if possible.
Definition: aux_tdc.h:666
__STATIC_INLINE bool AUXTDCCounterSet(uint32_t ui32Base, uint32_t ui32Events)
Set the reset number of counter compare/stop event to ignore before taking a measurement.
Definition: aux_tdc.h:715
__STATIC_INLINE void AUXTDCEnable(uint32_t ui32Base, uint32_t ui32RunMode)
Enable the AUX TDC for a measurement.
Definition: aux_tdc.h:424