onewire.c 25 KB

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