1 //*****************************************************************************
2 //
3 // onewire.h - Prototypes for the OneWire Driver.
4 //
5 // Copyright (c) 2012-2020 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __DRIVERLIB_ONEWIRE_H__
41 #define __DRIVERLIB_ONEWIRE_H__
42 
43 //*****************************************************************************
44 //
45 //! \addtogroup onewire_api
46 //! @{
47 //
48 //*****************************************************************************
49 
50 //*****************************************************************************
51 //
52 // If building with a C++ compiler, make all of the definitions in this header
53 // have a C binding.
54 //
55 //*****************************************************************************
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60 
61 //*****************************************************************************
62 //
63 // Defines used in the OneWireInit() function call.
64 //
65 //*****************************************************************************
66 
67 //
68 // This define is used in initialization to request standard speed bus
69 // timings.  This is the default.
70 //
71 #define ONEWIRE_INIT_SPD_STD    0x00000000
72 
73 //
74 // This define is used in initialization to request overdrive speed bus
75 // timings.
76 //
77 #define ONEWIRE_INIT_SPD_OD     0x00000020
78 
79 //
80 // This define is used in initialization to request standard read sampling
81 // timing (2us for ONEWIRE_INIT_SPD_OD and 16us for ONEWIRE_INIT_SPD_STD).
82 // This is the default.
83 //
84 #define ONEWIRE_INIT_READ_STD   0x00000000
85 
86 //
87 // This define is used in initialization to request late read sampling
88 // timing (7us for ONEWIRE_INIT_SPD_OD and 50us for ONEWIRE_INIT_SPD_STD).
89 //
90 #define ONEWIRE_INIT_READ_LATE  0x00000040
91 
92 //
93 // This define is used in initialization to request a standard
94 // Answer-to-Reset (presence detect) monitor.  This is the default.
95 //
96 #define ONEWIRE_INIT_ATR        0x00000000
97 
98 //
99 // This define is used in initialization to request no Answer-to-Reset
100 // (presence detect) monitor.  The module will delay operations after a bus
101 // reset for the expected presence detect period in this case.
102 //
103 #define ONEWIRE_INIT_NO_ATR     0x00000080
104 
105 //
106 // This define is used in initialization to request standard signal polarity
107 // on the 1-Wire bus (pin is driven low to drive bus low).  This is the
108 // default.
109 //
110 #define ONEWIRE_INIT_STD_POL    0x00000000
111 
112 //
113 // This define is used in initialization to request alternate signal polarity
114 // on the 1-Wire bus (pin is driven high to drive bus low).
115 //
116 #define ONEWIRE_INIT_ALT_POL    0x40000000
117 
118 //
119 // This define is used in initialization to request normal 1-Wire operational
120 // mode.  This is the default.
121 //
122 #define ONEWIRE_INIT_1_WIRE_CFG 0x00000000
123 
124 //
125 // This define is used in initialization to request a 2 pin operational
126 // mode where one pin is used exclusively for TX operations and the other
127 // for RX.
128 //
129 #define ONEWIRE_INIT_2_WIRE_CFG 0x80000000
130 
131 //*****************************************************************************
132 //
133 // Defines for bus status conditions.  These values can be returned by
134 // OneWireBusStatus().
135 //
136 //*****************************************************************************
137 
138 //
139 // This will be set if the bus is busy handling a Read, Write or
140 // Reset activity.
141 //
142 #define ONEWIRE_BUS_STATUS_BUSY 0x00000100
143 
144 //
145 // This will be set if the module did not detect any slave presence pulses
146 // after a bus reset.
147 //
148 #define ONEWIRE_BUS_STATUS_NO_SLAVE                                           \
149                                 0x00000200
150 
151 //
152 // This will be set if the bus is being held low outside of a normal Read,
153 // Write or Reset activity.
154 //
155 #define ONEWIRE_BUS_STATUS_STUCK                                              \
156                                 0x00000400
157 
158 //*****************************************************************************
159 //
160 // OneWire operation modes used with OneWireTransaction().
161 //
162 //*****************************************************************************
163 
164 //
165 // This mode flag indicates a single reset should be issued prior to a write
166 // and/or read operation.
167 //
168 #define ONEWIRE_OP_RESET        0x00000001
169 
170 //
171 // This mode flag indicates a read operation.
172 //
173 #define ONEWIRE_OP_READ         0x00000002
174 
175 //
176 // This mode flag indicates a write operation.
177 //
178 #define ONEWIRE_OP_WRITE        0x00000004
179 
180 //*****************************************************************************
181 //
182 // OneWire DMA used with OneWireDMAEnable().
183 //
184 //*****************************************************************************
185 
186 //
187 // This indicates the DMA should issue a 1-Wire bus reset before starting.
188 //
189 #define ONEWIRE_DMA_BUS_RESET   0x00000001
190 
191 //
192 // The DMA operation will be a single Read after each module transaction.
193 //
194 #define ONEWIRE_DMA_OP_READ     0x00000002
195 
196 //
197 // The DMA will write values to the 1-Wire interface as each previous DMA
198 // write operation completes.
199 //
200 #define ONEWIRE_DMA_OP_MULTI_WRITE                                            \
201                                 0x00000004
202 
203 //
204 // The DMA will read values from the 1-Wire interface as each previous DMA
205 // read operation completes.
206 //
207 #define ONEWIRE_DMA_OP_MULTI_READ                                             \
208                                 0x00000006
209 
210 //
211 // This Scatter Gather DMA mode is paired with ONEWIRE_DMA_OP_READ to instruct
212 // the 1-Wire DMA to initiate an operation at the start of and then on each
213 // transition completion thereafter.
214 //
215 #define ONEWIRE_DMA_MODE_SG     0x00000008
216 
217 //
218 // DMA expects a Read/Write bus operation size of 8 bits.  This should match
219 // the uDMA channel setup.
220 //
221 #define ONEWIRE_DMA_OP_SZ_8     0x00000000
222 
223 //
224 // DMA expects a Read/Write bus operation size of 16 bits.  This should match
225 // the uDMA channel setup.
226 //
227 #define ONEWIRE_DMA_OP_SZ_16    0x00000800
228 
229 //
230 // DMA expects a Read/Write bus operation size of 32 bits.  This should match
231 // the uDMA channel setup.
232 //
233 #define ONEWIRE_DMA_OP_SZ_32    0x00001800
234 
235 //*****************************************************************************
236 //
237 // OneWire interrupt defines.  Use in calls to OneWireIntEnable(),
238 // OneWireIntDisable(), OneWireIntClear() and returned by OneWireIntStatus().
239 //
240 //*****************************************************************************
241 
242 //
243 // This interrupt indicates a bus reset has just completed.
244 //
245 #define ONEWIRE_INT_RESET_DONE  0x00000001
246 
247 //
248 // The interrupt indicates a Read or Write master initiated operation
249 // has just completed.
250 //
251 #define ONEWIRE_INT_OP_DONE     0x00000002
252 
253 //
254 // This interrupt indicates that no presence detect was signaled by a slave
255 // on the bus after a reset.
256 //
257 #define ONEWIRE_INT_NO_SLAVE    0x00000004
258 
259 //
260 // This interrupt indicates the bus is being held low outside of normal
261 // operations.
262 //
263 #define ONEWIRE_INT_STUCK       0x00000008
264 
265 //
266 // This interrupt indicates a OneWire DMA operation has completed.
267 //
268 #define ONEWIRE_INT_DMA_DONE    0x00000010
269 
270 //*****************************************************************************
271 //
272 // Close the Doxygen group.
273 //! @}
274 //
275 //*****************************************************************************
276 
277 //*****************************************************************************
278 //
279 // Prototypes for the APIs.
280 //
281 //*****************************************************************************
282 extern void OneWireBusReset(uint32_t ui32Base);
283 extern uint32_t OneWireBusStatus(uint32_t ui32Base);
284 extern void OneWireDataGet(uint32_t u3i2Base, uint32_t *pui32Data);
285 extern bool OneWireDataGetNonBlocking(uint32_t ui32Base, uint32_t *pui32Data);
286 extern void OneWireDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags);
287 extern void OneWireDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags);
288 extern void OneWireInit(uint32_t ui32Base, uint32_t ui32InitFlags);
289 extern void OneWireIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
290 extern void OneWireIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
291 extern void OneWireIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
292 extern void OneWireIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
293 extern void OneWireIntUnregister(uint32_t ui32Base);
294 extern uint32_t OneWireIntStatus(uint32_t ui32Base, bool bMasked);
295 extern void OneWireTransaction(uint32_t ui32Base, uint32_t ui32OpFlags,
296                                uint32_t ui32Data, uint32_t ui32BitCnt);
297 
298 //*****************************************************************************
299 //
300 // Mark the end of the C bindings section for C++ compilers.
301 //
302 //*****************************************************************************
303 #ifdef __cplusplus
304 }
305 #endif
306 
307 #endif // __DRIVERLIB_ONEWIRE_H__
308