onewire.h 10 KB

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