1 /******************************************************************************
2 *  Filename:       aux_tdc.c
3 *
4 *  Description:    Driver for the AUX Time to Digital Converter interface.
5 *
6 *  Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 *  All rights reserved.
8 *
9 *  Redistribution and use in source and binary forms, with or without
10 *  modification, are permitted provided that the following conditions are met:
11 *
12 *  1) Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *
15 *  2) Redistributions in binary form must reproduce the above copyright notice,
16 *     this list of conditions and the following disclaimer in the documentation
17 *     and/or other materials provided with the distribution.
18 *
19 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 *     be used to endorse or promote products derived from this software without
21 *     specific prior written permission.
22 *
23 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 *  POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36 
37 #include "aux_tdc.h"
38 
39 //*****************************************************************************
40 //
41 // Handle support for DriverLib in ROM:
42 // This section will undo prototype renaming made in the header file
43 //
44 //*****************************************************************************
45 #if !defined(DOXYGEN)
46     #undef  AUXTDCConfigSet
47     #define AUXTDCConfigSet                 NOROM_AUXTDCConfigSet
48     #undef  AUXTDCMeasurementDone
49     #define AUXTDCMeasurementDone           NOROM_AUXTDCMeasurementDone
50 #endif
51 
52 //*****************************************************************************
53 //
54 // Configure the operation of the AUX TDC
55 //
56 //*****************************************************************************
57 void
AUXTDCConfigSet(uint32_t ui32Base,uint32_t ui32StartCondition,uint32_t ui32StopCondition)58 AUXTDCConfigSet(uint32_t ui32Base, uint32_t ui32StartCondition,
59                 uint32_t ui32StopCondition)
60 {
61     // Check the arguments.
62     ASSERT(AUXTDCBaseValid(ui32Base));
63 
64     // Make sure the AUX TDC is in the idle state before changing the
65     // configuration.
66     while(!((HWREG(ui32Base + AUX_TDC_O_STAT) & AUX_TDC_STAT_STATE_M) ==
67             AUX_TDC_STAT_STATE_IDLE))
68     {
69     }
70 
71     // Clear previous results.
72     HWREG(ui32Base + AUX_TDC_O_CTL) = 0x0;
73 
74     // Change the configuration.
75     HWREG(ui32Base + AUX_TDC_O_TRIGSRC) = ui32StartCondition | ui32StopCondition;
76 }
77 
78 //*****************************************************************************
79 //
80 // Check if the AUX TDC is done measuring
81 //
82 //*****************************************************************************
83 uint32_t
AUXTDCMeasurementDone(uint32_t ui32Base)84 AUXTDCMeasurementDone(uint32_t ui32Base)
85 {
86     uint32_t ui32Reg;
87     uint32_t ui32Status;
88 
89     // Check the arguments.
90     ASSERT(AUXTDCBaseValid(ui32Base));
91 
92     // Check if the AUX TDC is done measuring.
93     ui32Reg = HWREG(ui32Base + AUX_TDC_O_STAT);
94     if(ui32Reg & AUX_TDC_STAT_DONE)
95     {
96         ui32Status = AUX_TDC_DONE;
97     }
98     else if(ui32Reg & AUX_TDC_STAT_SAT)
99     {
100         ui32Status = AUX_TDC_TIMEOUT;
101     }
102     else
103     {
104         ui32Status = AUX_TDC_BUSY;
105     }
106 
107     // Return the status.
108     return (ui32Status);
109 }
110