onewire.c 25 KB

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