1 //*****************************************************************************
2 //
3 // onewire.c - Driver for OneWire master module.
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 //*****************************************************************************
41 //
42 //! \addtogroup onewire_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include <stdint.h>
48 #include <stdbool.h>
49 #include <stdint.h>
50 #include "inc/hw_ints.h"
51 #include "inc/hw_memmap.h"
52 #include "inc/hw_onewire.h"
53 #include "inc/hw_sysctl.h"
54 #include "inc/hw_types.h"
55 #include "driverlib/debug.h"
56 #include "driverlib/interrupt.h"
57 #include "driverlib/onewire.h"
58 #include "driverlib/sysctl.h"
59
60 //*****************************************************************************
61 //
62 // A bit mask for all transaction related fields in the 1-Wire control
63 // register.
64 //
65 //*****************************************************************************
66 #define ONEWIRE_TXN_MASK (ONEWIRE_CS_OP_M | ONEWIRE_CS_SZ_M | \
67 ONEWIRE_CS_BSIZE_M)
68
69 //*****************************************************************************
70 //
71 // Left-shift value for the control register's transaction size.
72 //
73 //*****************************************************************************
74 #define ONEWIRE_TXN_SIZE_LSHIFT 3
75
76 //*****************************************************************************
77 //
78 // Left-shift value for the control register's last byte bit size.
79 //
80 //*****************************************************************************
81 #define ONEWIRE_TXN_BSIZE_LSHIFT \
82 16
83
84 //*****************************************************************************
85 //
86 //! Initializes the 1-Wire module.
87 //!
88 //! \param ui32Base specifies the base address of the 1-Wire module.
89 //! \param ui32InitFlags provides the initialization flags.
90 //!
91 //! This function configures and initializes the 1-Wire interface for use.
92 //!
93 //! The \e ui32InitFlags parameter is a combination of the following:
94 //!
95 //! - \b ONEWIRE_INIT_SPD_STD - standard speed bus timings
96 //! - \b ONEWIRE_INIT_SPD_OD - overdrive speed bus timings
97 //! - \b ONEWIRE_INIT_READ_STD - standard read sampling timing
98 //! - \b ONEWIRE_INIT_READ_LATE - late read sampling timing
99 //! - \b ONEWIRE_INIT_ATR - standard answer-to-reset presence detect
100 //! - \b ONEWIRE_INIT_NO_ATR - no answer-to-reset presence detect
101 //! - \b ONEWIRE_INIT_STD_POL - normal signal polarity
102 //! - \b ONEWIRE_INIT_ALT_POL - alternate (reverse) signal polarity
103 //! - \b ONEWIRE_INIT_1_WIRE_CFG - standard 1-Wire (1 data pin) setup
104 //! - \b ONEWIRE_INIT_2_WIRE_CFG - alternate 2-Wire (2 data pin) setup
105 //!
106 //! \return None.
107 //
108 //*****************************************************************************
109 void
OneWireInit(uint32_t ui32Base,uint32_t ui32InitFlags)110 OneWireInit(uint32_t ui32Base, uint32_t ui32InitFlags)
111 {
112 //
113 // Check the arguments.
114 //
115 ASSERT(ui32Base == ONEWIRE0_BASE);
116
117 //
118 // Initialize control register.
119 //
120 HWREG(ui32Base + ONEWIRE_O_CS) = ui32InitFlags;
121 }
122
123 //*****************************************************************************
124 //
125 //! Issues a reset on the 1-Wire bus.
126 //!
127 //! \param ui32Base specifies the base address of the 1-Wire module.
128 //!
129 //! This function causes the 1-Wire module to generate a reset signal on the
130 //! 1-Wire bus.
131 //!
132 //! \return None.
133 //
134 //*****************************************************************************
135 void
OneWireBusReset(uint32_t ui32Base)136 OneWireBusReset(uint32_t ui32Base)
137 {
138 //
139 // Check the argument.
140 //
141 ASSERT(ui32Base == ONEWIRE0_BASE);
142
143 //
144 // Issue a bus reset.
145 //
146 HWREG(ui32Base + ONEWIRE_O_CS) |= ONEWIRE_CS_RST;
147 }
148
149 //*****************************************************************************
150 //
151 //! Retrieves the 1-Wire bus condition status.
152 //!
153 //! \param ui32Base specifies the base address of the 1-Wire module.
154 //!
155 //! This function returns the 1-Wire bus conditions reported by the 1-Wire
156 //! module. These conditions could be a logical OR of any of the following:
157 //!
158 //! - \b ONEWIRE_BUS_STATUS_BUSY - A read, write, or reset is active.
159 //! - \b ONEWIRE_BUS_STATUS_NO_SLAVE - No slave presence pulses detected.
160 //! - \b ONEWIRE_BUS_STATUS_STUCK - The bus is being held low by non-master.
161 //!
162 //! \return Returns the 1-Wire bus conditions if detected else zero.
163 //
164 //*****************************************************************************
165 uint32_t
OneWireBusStatus(uint32_t ui32Base)166 OneWireBusStatus(uint32_t ui32Base)
167 {
168 //
169 // Check the argument.
170 //
171 ASSERT(ui32Base == ONEWIRE0_BASE);
172
173 //
174 // Return the status bits from control and status register.
175 //
176 return(HWREG(ui32Base + ONEWIRE_O_CS) & (ONEWIRE_CS_BUSY |
177 ONEWIRE_CS_NOATR |
178 ONEWIRE_CS_STUCK));
179 }
180
181 //*****************************************************************************
182 //
183 //! Retrieves data from the 1-Wire interface.
184 //!
185 //! \param ui32Base specifies the base address of the 1-Wire module.
186 //! \param pui32Data is a pointer to storage to hold the read data.
187 //!
188 //! This function reads data from the 1-Wire module once all active bus
189 //! operations are completed. By protocol definition, bit data defaults to
190 //! a 1. Thus if a slave did not signal any 0-bit data, this read returns
191 //! 0xffffffff.
192 //!
193 //! \return None.
194 //
195 //*****************************************************************************
196 void
OneWireDataGet(uint32_t ui32Base,uint32_t * pui32Data)197 OneWireDataGet(uint32_t ui32Base, uint32_t *pui32Data)
198 {
199 //
200 // Check the arguments.
201 //
202 ASSERT(ui32Base == ONEWIRE0_BASE);
203 ASSERT(pui32Data);
204
205 //
206 // Wait for any active operations to complete.
207 //
208 while(HWREG(ui32Base + ONEWIRE_O_CS) & ONEWIRE_CS_BUSY)
209 {
210 }
211
212 //
213 // Copy the data into the provided storage.
214 //
215 *pui32Data = HWREG(ui32Base + ONEWIRE_O_DATR);
216 }
217
218 //*****************************************************************************
219 //
220 //! Retrieves data from the 1-Wire interface.
221 //!
222 //! \param ui32Base specifies the base address of the 1-Wire module.
223 //! \param pui32Data is a pointer to storage to hold the read data.
224 //!
225 //! This function reads data from the 1-Wire module if there are no active
226 //! operations on the bus. Otherwise it returns without reading the data from
227 //! the module.
228 //!
229 //! By protocol definition, bit data defaults to a 1. Thus if a slave did
230 //! not signal any 0-bit data, this read returns 0xffffffff.
231 //!
232 //! \return Returns \b true if a data read was performed, or \b false if the
233 //! bus was not idle and no data was read.
234 //
235 //*****************************************************************************
236 bool
OneWireDataGetNonBlocking(uint32_t ui32Base,uint32_t * pui32Data)237 OneWireDataGetNonBlocking(uint32_t ui32Base, uint32_t *pui32Data)
238 {
239 //
240 // Check the arguments.
241 //
242 ASSERT(ui32Base == ONEWIRE0_BASE);
243 ASSERT(pui32Data);
244
245 //
246 // If the bus is busy, return without reading.
247 //
248 if(HWREG(ui32Base + ONEWIRE_O_CS) & ONEWIRE_CS_BUSY)
249 {
250 return(false);
251 }
252
253 //
254 // Copy the data into the provided storage.
255 //
256 *pui32Data = HWREG(ui32Base + ONEWIRE_O_DATR);
257
258 //
259 // Notify the caller data was read from the read register.
260 //
261 return(true);
262 }
263
264 //*****************************************************************************
265 //
266 //! Clears the 1-Wire module interrupt sources.
267 //!
268 //! \param ui32Base specifies the base address of the 1-Wire module.
269 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
270 //!
271 //! This function clears the specified 1-Wire interrupt sources so that they no
272 //! longer assert. This function must be called in the interrupt handler to
273 //! keep the interrupts from being triggered again immediately upon exit. The
274 //! \e ui32IntFlags parameter can be a logical OR of any of the following:
275 //!
276 //! - \b ONEWIRE_INT_RESET_DONE - Bus reset has just completed.
277 //! - \b ONEWIRE_INT_OP_DONE - Read or write operation completed. If a
278 //! combined write and read operation was set up, the interrupt signals the
279 //! read is done.
280 //! - \b ONEWIRE_INT_NO_SLAVE - No presence detect was signaled by a slave.
281 //! - \b ONEWIRE_INT_STUCK - Bus is being held low by non-master.
282 //! - \b ONEWIRE_INT_DMA_DONE - DMA operation has completed.
283 //!
284 //! \note Because there is a write buffer in the Cortex-M processor, it may
285 //! take several clock cycles before the interrupt source is actually cleared.
286 //! Therefore, it is recommended that the interrupt source be cleared early in
287 //! the interrupt handler (as opposed to the very last action) to avoid
288 //! returning from the interrupt handler before the interrupt source is
289 //! actually cleared. Failure to do so may result in the interrupt handler
290 //! being immediately reentered (because the interrupt controller still sees
291 //! the interrupt source asserted).
292 //!
293 //! \return None.
294 //
295 //*****************************************************************************
296 void
OneWireIntClear(uint32_t ui32Base,uint32_t ui32IntFlags)297 OneWireIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
298 {
299 //
300 // Check the argument.
301 //
302 ASSERT(ui32Base == ONEWIRE0_BASE);
303 ASSERT((ui32IntFlags & ~(ONEWIRE_IM_RST | ONEWIRE_IM_OPC | ONEWIRE_IM_DMA |
304 ONEWIRE_IM_NOATR | ONEWIRE_IM_STUCK)) == 0);
305
306 //
307 // Clear the requested interrupts.
308 //
309 HWREG(ui32Base + ONEWIRE_O_ICR) = ui32IntFlags;
310 }
311
312 //*****************************************************************************
313 //
314 //! Disables individual 1-Wire module interrupt sources.
315 //!
316 //! \param ui32Base specifies the base address of the 1-Wire module.
317 //! \param ui32IntFlags is a bit mask of the interrupt sources to be disabled.
318 //!
319 //! This function disables the indicated 1-Wire interrupt sources. The
320 //! \e ui32IntFlags parameter can be a logical OR of any of the following:
321 //!
322 //! - \b ONEWIRE_INT_RESET_DONE - Bus reset has just completed.
323 //! - \b ONEWIRE_INT_OP_DONE - Read or write operation completed. If a
324 //! combined write and read operation was set up, the interrupt signals the
325 //! read is done.
326 //! - \b ONEWIRE_INT_NO_SLAVE - No presence detect was signaled by a slave.
327 //! - \b ONEWIRE_INT_STUCK - Bus is being held low by non-master.
328 //! - \b ONEWIRE_INT_DMA_DONE - DMA operation has completed
329 //!
330 //! \return None.
331 //
332 //*****************************************************************************
333 void
OneWireIntDisable(uint32_t ui32Base,uint32_t ui32IntFlags)334 OneWireIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
335 {
336 //
337 // Check the arguments.
338 //
339 ASSERT(ui32Base == ONEWIRE0_BASE);
340 ASSERT((ui32IntFlags & ~(ONEWIRE_IM_RST | ONEWIRE_IM_OPC | ONEWIRE_IM_DMA |
341 ONEWIRE_IM_NOATR | ONEWIRE_IM_STUCK)) == 0);
342
343 //
344 // Disable the requested interrupts.
345 //
346 HWREG(ui32Base + ONEWIRE_O_IM) &= ~ui32IntFlags;
347 }
348
349 //*****************************************************************************
350 //
351 //! Enables individual 1-Wire module interrupt sources.
352 //!
353 //! \param ui32Base specifies the base address of the 1-Wire module.
354 //! \param ui32IntFlags is a bit mask of the interrupt sources to be enabled.
355 //!
356 //! This function enables the indicated 1-Wire interrupt sources. Only the
357 //! sources that are enabled can be reflected to the processor interrupt;
358 //! disabled sources have no effect on the processor. The \e ui32IntFlags
359 //! parameter can be a logical OR of any of the following:
360 //!
361 //! - \b ONEWIRE_INT_RESET_DONE - Bus reset has just completed.
362 //! - \b ONEWIRE_INT_OP_DONE - Read or write operation completed. If a
363 //! combined write and read operation was set up, the interrupt signals the
364 //! read is done.
365 //! - \b ONEWIRE_INT_NO_SLAVE - No presence detect was signaled by a slave.
366 //! - \b ONEWIRE_INT_STUCK - Bus is being held low by non-master.
367 //! - \b ONEWIRE_INT_DMA_DONE - DMA operation has completed
368 //!
369 //! \return None.
370 //
371 //*****************************************************************************
372 void
OneWireIntEnable(uint32_t ui32Base,uint32_t ui32IntFlags)373 OneWireIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
374 {
375 //
376 // Check the arguments.
377 //
378 ASSERT(ui32Base == ONEWIRE0_BASE);
379 ASSERT((ui32IntFlags & ~(ONEWIRE_IM_RST | ONEWIRE_IM_OPC | ONEWIRE_IM_DMA |
380 ONEWIRE_IM_NOATR | ONEWIRE_IM_STUCK)) == 0);
381
382 //
383 // Enable the requested interrupts.
384 //
385 HWREG(ui32Base + ONEWIRE_O_IM) |= ui32IntFlags;
386 }
387
388 //*****************************************************************************
389 //
390 //! Gets the current 1-Wire interrupt status.
391 //!
392 //! \param ui32Base specifies the base address of the 1-Wire module.
393 //! \param bMasked is \b false if the raw interrupt status is required or
394 //! \b true if the masked interrupt status is required.
395 //!
396 //! This function returns the interrupt status for the 1-Wire module. Either
397 //! the raw interrupt status or the status of interrupts that are allowed to
398 //! reflect to the processor can be returned.
399 //!
400 //! \return Returns the masked or raw 1-Wire interrupt status, as a bit field
401 //! of any of the following values:
402 //!
403 //! - \b ONEWIRE_INT_RESET_DONE - Bus reset has just completed.
404 //! - \b ONEWIRE_INT_OP_DONE - Read or write operation completed.
405 //! - \b ONEWIRE_INT_NO_SLAVE - No presence detect was signaled by a slave.
406 //! - \b ONEWIRE_INT_STUCK - Bus is being held low by non-master.
407 //! - \b ONEWIRE_INT_DMA_DONE - DMA operation has completed
408 //
409 //*****************************************************************************
410 uint32_t
OneWireIntStatus(uint32_t ui32Base,bool bMasked)411 OneWireIntStatus(uint32_t ui32Base, bool bMasked)
412 {
413 //
414 // Check the argument.
415 //
416 ASSERT(ui32Base == ONEWIRE0_BASE);
417
418 //
419 // Return either the interrupt status or the raw interrupt status as
420 // requested.
421 //
422 if(bMasked)
423 {
424 return(HWREG(ui32Base + ONEWIRE_O_MIS));
425 }
426 else
427 {
428 return(HWREG(ui32Base + ONEWIRE_O_RIS));
429 }
430 }
431
432 //*****************************************************************************
433 //
434 //! Returns the 1-Wire controller interrupt number.
435 //!
436 //! \param ui32Base specifies the 1-Wire module base address.
437 //!
438 //! This function returns the interrupt number for the 1-Wire module with the
439 //! base address passed in the \e ui32Base parameter.
440 //!
441 //! \return Returns a 1-Wire interrupt number or 0 if the interrupt does not
442 //! exist.
443 //
444 //*****************************************************************************
445 static uint32_t
_OneWireIntNumberGet(uint32_t ui32Base)446 _OneWireIntNumberGet(uint32_t ui32Base)
447 {
448 uint32_t ui32Int;
449
450 ASSERT(ui32Base == ONEWIRE0_BASE);
451
452 ui32Int = 0;
453
454 //
455 // Find the valid interrupt number for the 1-Wire module.
456 //
457 if(CLASS_IS_TM4C129)
458 {
459 ui32Int = INT_ONEWIRE0_TM4C129;
460 }
461
462 return(ui32Int);
463 }
464
465 //*****************************************************************************
466 //
467 //! Registers an interrupt handler for the 1-Wire module.
468 //!
469 //! \param ui32Base is the base address of the 1-Wire module.
470 //! \param pfnHandler is a pointer to the function to be called when the
471 //! 1-Wire interrupt occurs.
472 //!
473 //! This function sets the handler to be called when a 1-Wire interrupt occurs.
474 //! This function enables the global interrupt in the interrupt controller;
475 //! specific 1-Wire interrupts must be enabled via OneWireIntEnable(). If
476 //! necessary, it is the interrupt handler's responsibility to clear the
477 //! interrupt source via OneWireIntClear().
478 //!
479 //! \sa IntRegister() for important information about registering interrupt
480 //! handlers.
481 //!
482 //! \return None.
483 //
484 //*****************************************************************************
485 void
OneWireIntRegister(uint32_t ui32Base,void (* pfnHandler)(void))486 OneWireIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
487 {
488 uint32_t ui32Int;
489
490 //
491 // Check the argument.
492 //
493 ASSERT(ui32Base == ONEWIRE0_BASE);
494 ASSERT(pfnHandler);
495
496 //
497 // Get the actual interrupt number for the 1-Wire module.
498 //
499 ui32Int = _OneWireIntNumberGet(ui32Base);
500
501 ASSERT(ui32Int != 0);
502
503 //
504 // Register the interrupt handler.
505 //
506 IntRegister(ui32Int, pfnHandler);
507
508 //
509 // Enable the 1-Wire peripheral interrupt.
510 //
511 IntEnable(ui32Int);
512 }
513
514 //*****************************************************************************
515 //
516 //! Unregisters an interrupt handler for the 1-Wire module.
517 //!
518 //! \param ui32Base is the base address of the 1-Wire module.
519 //!
520 //! This function clears the handler to be called when an 1-Wire interrupt
521 //! occurs. This function also masks off the interrupt in the interrupt
522 //! controller so that the interrupt handler no longer is called.
523 //!
524 //! \sa IntRegister() for important information about registering interrupt
525 //! handlers.
526 //!
527 //! \return None.
528 //
529 //*****************************************************************************
530 void
OneWireIntUnregister(uint32_t ui32Base)531 OneWireIntUnregister(uint32_t ui32Base)
532 {
533 uint32_t ui32Int;
534
535 //
536 // Check the argument.
537 //
538 ASSERT(ui32Base == ONEWIRE0_BASE);
539
540 //
541 // Get the actual interrupt number for the 1-Wire module.
542 //
543 ui32Int = _OneWireIntNumberGet(ui32Base);
544 ASSERT(ui32Int != 0);
545
546 //
547 // Disable the 1-Wire peripheral interrupt.
548 //
549 IntDisable(ui32Int);
550
551 //
552 // Unregister the interrupt handler.
553 //
554 IntUnregister(ui32Int);
555 }
556
557 //*****************************************************************************
558 //
559 //! Disables 1-Wire DMA operations.
560 //!
561 //! \param ui32Base is the base address of the 1-Wire module.
562 //! \param ui32DMAFlags is a bit mask of the DMA features to disable.
563 //!
564 //! This function is used to disable 1-Wire DMA features that were enabled
565 //! by OneWireDMAEnable(). The specified 1-Wire DMA features are disabled.
566 //! The \e ui32DMAFlags parameter is a combination of the following:
567 //!
568 //! - \b ONEWIRE_DMA_BUS_RESET - Issue a 1-Wire bus reset before starting
569 //! - \b ONEWIRE_DMA_OP_READ - Read after each module transaction
570 //! - \b ONEWIRE_DMA_OP_MULTI_WRITE - Write after each previous write
571 //! - \b ONEWIRE_DMA_OP_MULTI_READ - Read after each previous read
572 //! - \b ONEWIRE_DMA_MODE_SG - Start DMA on enable then repeat on each
573 //! completion
574 //! - \b ONEWIRE_DMA_OP_SZ_8 - Bus read/write of 8 bits
575 //! - \b ONEWIRE_DMA_OP_SZ_16 - Bus read/write of 16 bits
576 //! - \b ONEWIRE_DMA_OP_SZ_32 - Bus read/write of 32 bits
577 //!
578 //! \return None.
579 //
580 //*****************************************************************************
581 void
OneWireDMADisable(uint32_t ui32Base,uint32_t ui32DMAFlags)582 OneWireDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
583 {
584 //
585 // Check the arguments.
586 //
587 ASSERT(ui32Base == ONEWIRE0_BASE);
588 ASSERT(ui32DMAFlags > 0);
589
590 //
591 // Clear the transaction size bits
592 //
593 HWREG(ui32Base + ONEWIRE_O_CS) = (HWREG(ui32Base + ONEWIRE_O_CS) &
594 ~(ONEWIRE_TXN_MASK));
595
596 //
597 // Disable the DMA features as requested.
598 //
599 HWREG(ui32Base + ONEWIRE_O_DMA) &= ~(ui32DMAFlags & 0xff);
600 }
601
602 //*****************************************************************************
603 //
604 //! Enables 1-Wire DMA operations.
605 //!
606 //! \param ui32Base is the base address of the 1-Wire module.
607 //! \param ui32DMAFlags is a bit mask of the DMA features to enable.
608 //!
609 //! This function enables the specified 1-Wire DMA features. The 1-Wire module
610 //! can be configured for write operations, read operations, small write and
611 //! read operations, and scatter-gather support of mixed operations.
612 //!
613 //! The \e ui32DMAFlags parameter is a combination of the following:
614 //!
615 //! - \b ONEWIRE_DMA_BUS_RESET - Issue a 1-Wire bus reset before starting
616 //! - \b ONEWIRE_DMA_OP_READ - Read after each module transaction
617 //! - \b ONEWIRE_DMA_OP_MULTI_WRITE - Write after each previous write
618 //! - \b ONEWIRE_DMA_OP_MULTI_READ - Read after each previous read
619 //! - \b ONEWIRE_DMA_MODE_SG - Start DMA on enable then repeat on each
620 //! completion
621 //! - \b ONEWIRE_DMA_OP_SZ_8 - Bus read/write of 8 bits
622 //! - \b ONEWIRE_DMA_OP_SZ_16 - Bus read/write of 16 bits
623 //! - \b ONEWIRE_DMA_OP_SZ_32 - Bus read/write of 32 bits
624 //!
625 //! \note The uDMA controller must be properly configured before DMA can be
626 //! used with the 1-Wire module.
627 //!
628 //! \return None.
629 //
630 //*****************************************************************************
631 void
OneWireDMAEnable(uint32_t ui32Base,uint32_t ui32DMAFlags)632 OneWireDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
633 {
634 //
635 // Check the arguments.
636 //
637 ASSERT(ui32Base == ONEWIRE0_BASE);
638 ASSERT(ui32DMAFlags > 0);
639
640 //
641 // set up the transaction size.
642 //
643 HWREG(ui32Base + ONEWIRE_O_CS) = ((HWREG(ui32Base + ONEWIRE_O_CS) &
644 ~(ONEWIRE_TXN_MASK)) |
645 (ui32DMAFlags >> 8));
646
647 //
648 // Enable DMA with the parameters provided.
649 //
650 HWREG(ui32Base + ONEWIRE_O_DMA) = (ui32DMAFlags & 0xf);
651
652 //
653 // If a read transaction was requested, seed the write data register. This
654 // will trigger the DMA reads to start. This should not be done for
655 // scatter-gather operations.
656 //
657 if((ui32DMAFlags & (ONEWIRE_DMA_DMAOP_RDSNG | ONEWIRE_DMA_DMAOP_RDMUL)) &&
658 !(ui32DMAFlags & ONEWIRE_DMA_SG))
659 {
660 //
661 // Workaround for Snowflake DMA receive trigger errata.
662 //
663 if(CLASS_IS_TM4C129)
664 {
665 SysCtlDelay(9);
666 }
667
668 //
669 // Write DATW to trigger DMA receive start.
670 //
671 HWREG(ui32Base + ONEWIRE_O_DATW) = 0xffffffff;
672 }
673 }
674
675 //*****************************************************************************
676 //
677 //! Performs a 1-Wire protocol transaction on the bus.
678 //!
679 //! \param ui32Base specifies the base address of the 1-Wire module.
680 //! \param ui32OpMode sets the transaction type.
681 //! \param ui32Data is the data for a write operation.
682 //! \param ui32BitCnt specifies the number of valid bits (1-32) for the
683 //! operation.
684 //!
685 //! This function performs a 1-Wire protocol transaction, read and/or write, on
686 //! the bus. The application should confirm the bus is idle before starting a
687 //! read or write transaction.
688 //!
689 //! The \e ui32OpMode defines the activity for the bus operations and is a
690 //! logical OR of the following:
691 //!
692 //! - \b ONEWIRE_OP_RESET - Indicates the operation should be started with
693 //! a bus reset.
694 //! - \b ONEWIRE_OP_WRITE - A write operation
695 //! - \b ONEWIRE_OP_READ - A read operation
696 //!
697 //! \note If both a read and write operation are requested, the write will be
698 //! performed prior to the read.
699 //!
700 //! \return None.
701 //
702 //*****************************************************************************
703 void
OneWireTransaction(uint32_t ui32Base,uint32_t ui32OpMode,uint32_t ui32Data,uint32_t ui32BitCnt)704 OneWireTransaction(uint32_t ui32Base, uint32_t ui32OpMode, uint32_t ui32Data,
705 uint32_t ui32BitCnt)
706 {
707 uint32_t ui32Transaction;
708
709 //
710 // Check the arguments.
711 //
712 ASSERT(ui32Base == ONEWIRE0_BASE);
713 ASSERT((ui32OpMode & (ONEWIRE_OP_RESET | ONEWIRE_OP_WRITE |
714 ONEWIRE_OP_READ)) > 0);
715 ASSERT((ui32BitCnt >= 1) && (ui32BitCnt <= 32));
716
717 //
718 // Read the control register and clear any transaction related
719 // bit fields.
720 //
721 ui32Transaction = HWREG(ui32Base + ONEWIRE_O_CS) & ~(ONEWIRE_TXN_MASK);
722
723 //
724 // Add the user specified operation flags.
725 //
726 ui32Transaction |= (ui32OpMode & (ONEWIRE_OP_RESET | ONEWIRE_OP_WRITE |
727 ONEWIRE_OP_READ));
728
729 //
730 // set up for a read or write transaction.
731 //
732 if(ui32Transaction & (ONEWIRE_CS_OP_WR | ONEWIRE_CS_OP_RD))
733 {
734 //
735 // Configure the 1-Wire module for the transaction size. This is
736 // specified as 1-4 bytes and the specific bit size for the last
737 // byte therein.
738 //
739 ui32Transaction |= ((((ui32BitCnt % 8) ? (ui32BitCnt / 8) + 1 :
740 (ui32BitCnt / 8)) - 1) <<
741 ONEWIRE_TXN_SIZE_LSHIFT);
742 ui32Transaction |= ((ui32BitCnt % 8) << ONEWIRE_TXN_BSIZE_LSHIFT);
743
744 //
745 // Write specific setup.
746 //
747 if(ui32Transaction & ONEWIRE_CS_OP_WR)
748 {
749 //
750 // Load the data into the write register.
751 //
752 HWREG(ui32Base + ONEWIRE_O_DATW) = ui32Data;
753 }
754 }
755
756 //
757 // Start the transaction.
758 //
759 HWREG(ui32Base + ONEWIRE_O_CS) = ui32Transaction;
760 }
761
762 //*****************************************************************************
763 //
764 // Close the Doxygen group.
765 //! @}
766 //
767 //*****************************************************************************
768