onewire.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. //*****************************************************************************
  2. //
  3. // onewire.c - Driver for OneWire master module.
  4. //
  5. // Copyright (c) 2012-2014 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.1.0.12573 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_TM4E111)
  428. {
  429. ui32Int = INT_ONEWIRE0_TM4E111;
  430. }
  431. if(CLASS_IS_TM4C129)
  432. {
  433. ui32Int = INT_ONEWIRE0_TM4C129;
  434. }
  435. return(ui32Int);
  436. }
  437. //*****************************************************************************
  438. //
  439. //! Registers an interrupt handler for the 1-Wire module.
  440. //!
  441. //! \param ui32Base is the base address of the 1-Wire module.
  442. //! \param pfnHandler is a pointer to the function to be called when the
  443. //! 1-Wire interrupt occurs.
  444. //!
  445. //! This function sets the handler to be called when a 1-Wire interrupt occurs.
  446. //! This function enables the global interrupt in the interrupt controller;
  447. //! specific 1-Wire interrupts must be enabled via OneWireIntEnable(). If
  448. //! necessary, it is the interrupt handler's responsibility to clear the
  449. //! interrupt source via OneWireIntClear().
  450. //!
  451. //! \sa IntRegister() for important information about registering interrupt
  452. //! handlers.
  453. //!
  454. //! \return None.
  455. //
  456. //*****************************************************************************
  457. void
  458. OneWireIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  459. {
  460. uint32_t ui32Int;
  461. //
  462. // Check the argument.
  463. //
  464. ASSERT(ui32Base == ONEWIRE0_BASE);
  465. ASSERT(pfnHandler);
  466. //
  467. // Get the actual interrupt number for the 1-Wire module.
  468. //
  469. ui32Int = _OneWireIntNumberGet(ui32Base);
  470. ASSERT(ui32Int != 0);
  471. //
  472. // Register the interrupt handler.
  473. //
  474. IntRegister(ui32Int, pfnHandler);
  475. //
  476. // Enable the 1-Wire peripheral interrupt.
  477. //
  478. IntEnable(ui32Int);
  479. }
  480. //*****************************************************************************
  481. //
  482. //! Unregisters an interrupt handler for the 1-Wire module.
  483. //!
  484. //! \param ui32Base is the base address of the 1-Wire module.
  485. //!
  486. //! This function clears the handler to be called when an 1-Wire interrupt
  487. //! occurs. This function also masks off the interrupt in the interrupt
  488. //! controller so that the interrupt handler no longer is called.
  489. //!
  490. //! \sa IntRegister() for important information about registering interrupt
  491. //! handlers.
  492. //!
  493. //! \return None.
  494. //
  495. //*****************************************************************************
  496. void
  497. OneWireIntUnregister(uint32_t ui32Base)
  498. {
  499. uint32_t ui32Int;
  500. //
  501. // Check the argument.
  502. //
  503. ASSERT(ui32Base == ONEWIRE0_BASE);
  504. //
  505. // Get the actual interrupt number for the 1-Wire module.
  506. //
  507. ui32Int = _OneWireIntNumberGet(ui32Base);
  508. ASSERT(ui32Int != 0);
  509. //
  510. // Disable the 1-Wire peripheral interrupt.
  511. //
  512. IntDisable(ui32Int);
  513. //
  514. // Unregister the interrupt handler.
  515. //
  516. IntUnregister(ui32Int);
  517. }
  518. //*****************************************************************************
  519. //
  520. //! Disables 1-Wire DMA operations.
  521. //!
  522. //! \param ui32Base is the base address of the 1-Wire module.
  523. //! \param ui32DMAFlags is a bit mask of the DMA features to disable.
  524. //!
  525. //! This function is used to disable 1-Wire DMA features that were enabled
  526. //! by OneWireDMAEnable(). The specified 1-Wire DMA features are disabled.
  527. //! The \e ui32DMAFlags parameter is a combination of the following:
  528. //!
  529. //! - \b ONEWIRE_DMA_BUS_RESET - Issue a 1-Wire bus reset before starting
  530. //! - \b ONEWIRE_DMA_OP_READ - Read after each module transaction
  531. //! - \b ONEWIRE_DMA_OP_MULTI_WRITE - Write after each previous write
  532. //! - \b ONEWIRE_DMA_OP_MULTI_READ - Read after each previous read
  533. //! - \b ONEWIRE_DMA_MODE_SG - Start DMA on enable then repeat on each
  534. //! completion
  535. //! - \b ONEWIRE_DMA_OP_SZ_8 - Bus read/write of 8 bits
  536. //! - \b ONEWIRE_DMA_OP_SZ_16 - Bus read/write of 16 bits
  537. //! - \b ONEWIRE_DMA_OP_SZ_32 - Bus read/write of 32 bits
  538. //!
  539. //! \return None.
  540. //
  541. //*****************************************************************************
  542. void
  543. OneWireDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags)
  544. {
  545. //
  546. // Check the arguments.
  547. //
  548. ASSERT(ui32Base == ONEWIRE0_BASE);
  549. ASSERT(ui32DMAFlags > 0);
  550. //
  551. // Clear the transaction size bits
  552. //
  553. HWREG(ui32Base + ONEWIRE_O_CS) = (HWREG(ui32Base + ONEWIRE_O_CS) &
  554. ~(ONEWIRE_TXN_MASK));
  555. //
  556. // Disable the DMA features as requested.
  557. //
  558. HWREG(ui32Base + ONEWIRE_O_DMA) &= ~(ui32DMAFlags & 0xff);
  559. }
  560. //*****************************************************************************
  561. //
  562. //! Enables 1-Wire DMA operations.
  563. //!
  564. //! \param ui32Base is the base address of the 1-Wire module.
  565. //! \param ui32DMAFlags is a bit mask of the DMA features to enable.
  566. //!
  567. //! This function enables the specified 1-Wire DMA features. The 1-Wire module
  568. //! can be configured for write operations, read operations, small write and
  569. //! read operations, and scatter-gather support of mixed operations.
  570. //!
  571. //! The \e ui32DMAFlags parameter is a combination of the following:
  572. //!
  573. //! - \b ONEWIRE_DMA_BUS_RESET - Issue a 1-Wire bus reset before starting
  574. //! - \b ONEWIRE_DMA_OP_READ - Read after each module transaction
  575. //! - \b ONEWIRE_DMA_OP_MULTI_WRITE - Write after each previous write
  576. //! - \b ONEWIRE_DMA_OP_MULTI_READ - Read after each previous read
  577. //! - \b ONEWIRE_DMA_MODE_SG - Start DMA on enable then repeat on each
  578. //! completion
  579. //! - \b ONEWIRE_DMA_OP_SZ_8 - Bus read/write of 8 bits
  580. //! - \b ONEWIRE_DMA_OP_SZ_16 - Bus read/write of 16 bits
  581. //! - \b ONEWIRE_DMA_OP_SZ_32 - Bus read/write of 32 bits
  582. //!
  583. //! \note The uDMA controller must be properly configured before DMA can be
  584. //! used with the 1-Wire module.
  585. //!
  586. //! \return None.
  587. //
  588. //*****************************************************************************
  589. void
  590. OneWireDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags)
  591. {
  592. //
  593. // Check the arguments.
  594. //
  595. ASSERT(ui32Base == ONEWIRE0_BASE);
  596. ASSERT(ui32DMAFlags > 0);
  597. //
  598. // set up the transaction size.
  599. //
  600. HWREG(ui32Base + ONEWIRE_O_CS) = ((HWREG(ui32Base + ONEWIRE_O_CS) &
  601. ~(ONEWIRE_TXN_MASK)) |
  602. (ui32DMAFlags >> 8));
  603. //
  604. // Enable DMA with the parameters provided.
  605. //
  606. HWREG(ui32Base + ONEWIRE_O_DMA) = (ui32DMAFlags & 0xf);
  607. //
  608. // If a read transaction was requested, seed the write data register. This
  609. // will trigger the DMA reads to start. This should not be done for
  610. // scatter-gather operations.
  611. //
  612. if((ui32DMAFlags & (ONEWIRE_DMA_DMAOP_RDSNG | ONEWIRE_DMA_DMAOP_RDMUL)) &&
  613. !(ui32DMAFlags & ONEWIRE_DMA_SG))
  614. {
  615. //
  616. // Workaround for Snowflake DMA receive trigger errata.
  617. //
  618. if(CLASS_IS_TM4C129)
  619. {
  620. SysCtlDelay(9);
  621. }
  622. //
  623. // Write DATW to trigger DMA receive start.
  624. //
  625. HWREG(ui32Base + ONEWIRE_O_DATW) = 0xffffffff;
  626. }
  627. }
  628. //*****************************************************************************
  629. //
  630. //! Performs a 1-Wire protocol transaction on the bus.
  631. //!
  632. //! \param ui32Base specifies the base address of the 1-Wire module.
  633. //! \param ui32OpMode sets the transaction type.
  634. //! \param ui32Data is the data for a write operation.
  635. //! \param ui32BitCnt specifies the number of valid bits (1-32) for the
  636. //! operation.
  637. //!
  638. //! This function performs a 1-Wire protocol transaction, read and/or write, on
  639. //! the bus. The application should confirm the bus is idle before starting a
  640. //! read or write transaction.
  641. //!
  642. //! The \e ui32OpMode defines the activity for the bus operations and is a
  643. //! logical OR of the following:
  644. //!
  645. //! - \b ONEWIRE_OP_RESET - Indicates the operation should be started with
  646. //! a bus reset.
  647. //! - \b ONEWIRE_OP_WRITE - A write operation
  648. //! - \b ONEWIRE_OP_READ - A read operation
  649. //!
  650. //! \note If both a read and write operation are requested, the write will be
  651. //! performed prior to the read.
  652. //!
  653. //! \return None.
  654. //
  655. //*****************************************************************************
  656. void
  657. OneWireTransaction(uint32_t ui32Base, uint32_t ui32OpMode, uint32_t ui32Data,
  658. uint32_t ui32BitCnt)
  659. {
  660. uint32_t ui32Transaction;
  661. //
  662. // Check the arguments.
  663. //
  664. ASSERT(ui32Base == ONEWIRE0_BASE);
  665. ASSERT((ui32OpMode & (ONEWIRE_OP_RESET | ONEWIRE_OP_WRITE |
  666. ONEWIRE_OP_READ)) > 0);
  667. ASSERT((ui32BitCnt >= 1) && (ui32BitCnt <= 32));
  668. //
  669. // Read the control register and clear any transaction related
  670. // bit fields.
  671. //
  672. ui32Transaction = HWREG(ui32Base + ONEWIRE_O_CS) & ~(ONEWIRE_TXN_MASK);
  673. //
  674. // Add the user specified operation flags.
  675. //
  676. ui32Transaction |= (ui32OpMode & (ONEWIRE_OP_RESET | ONEWIRE_OP_WRITE |
  677. ONEWIRE_OP_READ));
  678. //
  679. // set up for a read or write transaction.
  680. //
  681. if(ui32Transaction & (ONEWIRE_CS_OP_WR | ONEWIRE_CS_OP_RD))
  682. {
  683. //
  684. // Configure the 1-Wire module for the transaction size. This is
  685. // specified as 1-4 bytes and the specific bit size for the last
  686. // byte therein.
  687. //
  688. ui32Transaction |= ((((ui32BitCnt % 8) ? (ui32BitCnt / 8) + 1 :
  689. (ui32BitCnt / 8)) - 1) <<
  690. ONEWIRE_TXN_SIZE_LSHIFT);
  691. ui32Transaction |= ((ui32BitCnt % 8) << ONEWIRE_TXN_BSIZE_LSHIFT);
  692. //
  693. // Write specific setup.
  694. //
  695. if(ui32Transaction & ONEWIRE_CS_OP_WR)
  696. {
  697. //
  698. // Load the data into the write register.
  699. //
  700. HWREG(ui32Base + ONEWIRE_O_DATW) = ui32Data;
  701. }
  702. }
  703. //
  704. // Start the transaction.
  705. //
  706. HWREG(ui32Base + ONEWIRE_O_CS) = ui32Transaction;
  707. }
  708. //*****************************************************************************
  709. //
  710. // Close the Doxygen group.
  711. //! @}
  712. //
  713. //*****************************************************************************