IxI2cDrv.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /**
  2. * @file IxI2cDrv.h
  3. *
  4. * @brief Header file for the IXP400 I2C Driver (IxI2cDrv)
  5. *
  6. * @version $Revision: 0.1 $
  7. *
  8. * @par
  9. * IXP400 SW Release version 2.0
  10. *
  11. * -- Copyright Notice --
  12. *
  13. * @par
  14. * Copyright 2001-2005, Intel Corporation.
  15. * All rights reserved.
  16. *
  17. * @par
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted provided that the following conditions
  20. * are met:
  21. * 1. Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright
  24. * notice, this list of conditions and the following disclaimer in the
  25. * documentation and/or other materials provided with the distribution.
  26. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  27. * may be used to endorse or promote products derived from this software
  28. * without specific prior written permission.
  29. *
  30. * @par
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  32. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  35. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  40. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  41. * SUCH DAMAGE.
  42. *
  43. * @par
  44. * -- End of Copyright Notice --
  45. */
  46. /**
  47. * @defgroup IxI2cDrv IXP400 I2C Driver(IxI2cDrv) API
  48. *
  49. * @brief IXP400 I2C Driver Public API
  50. *
  51. * @{
  52. */
  53. #ifndef IXI2CDRV_H
  54. #define IXI2CDRV_H
  55. #ifdef __ixp46X
  56. #include "IxOsal.h"
  57. /*
  58. * Section for #define
  59. */
  60. /**
  61. * @ingroup IxI2cDrv
  62. * @brief The interval of micro/mili seconds the IXP will wait before it polls for
  63. * status from the ixI2cIntrXferStatus; Every 20us is 1 byte @
  64. * 400Kbps and 4 bytes @ 100Kbps. This is dependent on delay type selected
  65. * through the API ixI2cDrvDelayTypeSelect.
  66. */
  67. #define IX_I2C_US_POLL_FOR_XFER_STATUS 20
  68. /**
  69. * @ingroup IxI2cDrv
  70. * @brief The number of tries that will be attempted to call a callback
  71. * function if the callback does not or is unable to resolve the
  72. * issue it is called to resolve
  73. */
  74. #define IX_I2C_NUM_OF_TRIES_TO_CALL_CALLBACK_FUNC 10
  75. /**
  76. * @ingroup IxI2cDrv
  77. * @brief Number of tries slave will poll the IDBR Rx full bit before it
  78. * gives up
  79. */
  80. #define IX_I2C_NUM_TO_POLL_IDBR_RX_FULL 0x100
  81. /**
  82. * @ingroup IxI2cDrv
  83. * @brief Number of tries slave will poll the IDBR Tx empty bit before it
  84. * gives up
  85. */
  86. #define IX_I2C_NUM_TO_POLL_IDBR_TX_EMPTY 0x100
  87. /*
  88. * Section for enum
  89. */
  90. /**
  91. * @ingroup IxI2cDrv
  92. *
  93. * @enum IxI2cMasterStatus
  94. *
  95. * @brief The master status - transfer complete, bus error or arbitration loss
  96. */
  97. typedef enum
  98. {
  99. IX_I2C_MASTER_XFER_COMPLETE = IX_SUCCESS,
  100. IX_I2C_MASTER_XFER_BUS_ERROR,
  101. IX_I2C_MASTER_XFER_ARB_LOSS
  102. } IxI2cMasterStatus;
  103. /**
  104. * @ingroup IxI2cDrv
  105. *
  106. * @enum IX_I2C_STATUS
  107. *
  108. * @brief The status that can be returned in a I2C driver initialization
  109. */
  110. typedef enum
  111. {
  112. IX_I2C_SUCCESS = IX_SUCCESS, /**< Success status */
  113. IX_I2C_FAIL, /**< Fail status */
  114. IX_I2C_NOT_SUPPORTED, /**< hardware does not have dedicated I2C hardware */
  115. IX_I2C_NULL_POINTER, /**< parameter passed in is NULL */
  116. IX_I2C_INVALID_SPEED_MODE_ENUM_VALUE, /**< speed mode selected is invalid */
  117. IX_I2C_INVALID_FLOW_MODE_ENUM_VALUE, /**< flow mode selected is invalid */
  118. IX_I2C_SLAVE_ADDR_CB_MISSING, /**< slave callback is NULL */
  119. IX_I2C_GEN_CALL_CB_MISSING, /**< general callback is NULL */
  120. IX_I2C_INVALID_SLAVE_ADDR, /**< invalid slave address specified */
  121. IX_I2C_INT_BIND_FAIL, /**< interrupt bind fail */
  122. IX_I2C_INT_UNBIND_FAIL, /**< interrupt unbind fail */
  123. IX_I2C_NOT_INIT, /**< I2C is not initialized yet */
  124. IX_I2C_MASTER_BUS_BUSY, /**< master detected a I2C bus busy */
  125. IX_I2C_MASTER_ARB_LOSS, /**< master experienced arbitration loss */
  126. IX_I2C_MASTER_XFER_ERROR, /**< master experienced a transfer error */
  127. IX_I2C_MASTER_BUS_ERROR, /**< master detected a I2C bus error */
  128. IX_I2C_MASTER_NO_BUFFER, /**< no buffer provided for master transfer */
  129. IX_I2C_MASTER_INVALID_XFER_MODE, /**< xfer mode selected is invalid */
  130. IX_I2C_SLAVE_ADDR_NOT_DETECTED, /**< polled slave addr not detected */
  131. IX_I2C_GEN_CALL_ADDR_DETECTED, /**< polling detected general call */
  132. IX_I2C_SLAVE_READ_DETECTED, /**< polling detected slave read request */
  133. IX_I2C_SLAVE_WRITE_DETECTED, /**< polling detected slave write request */
  134. IX_I2C_SLAVE_NO_BUFFER, /**< no buffer provided for slave transfers */
  135. IX_I2C_DATA_SIZE_ZERO, /**< data size transfer is zero - invalid */
  136. IX_I2C_SLAVE_WRITE_BUFFER_EMPTY, /**< slave buffer is used till empty */
  137. IX_I2C_SLAVE_WRITE_ERROR, /**< slave write experienced an error */
  138. IX_I2C_SLAVE_OR_GEN_READ_BUFFER_FULL, /**< slave buffer is filled up */
  139. IX_I2C_SLAVE_OR_GEN_READ_ERROR /**< slave read experienced an error */
  140. } IX_I2C_STATUS;
  141. /**
  142. * @ingroup IxI2cDrv
  143. *
  144. * @enum IxI2cSpeedMode
  145. *
  146. * @brief Type of speed modes supported by the I2C hardware.
  147. */
  148. typedef enum
  149. {
  150. IX_I2C_NORMAL_MODE = 0x0,
  151. IX_I2C_FAST_MODE
  152. } IxI2cSpeedMode;
  153. /**
  154. * @ingroup IxI2cDrv
  155. *
  156. * @enum IxI2cXferMode
  157. *
  158. * @brief Used for indicating it is a repeated start or normal transfer
  159. */
  160. typedef enum
  161. {
  162. IX_I2C_NORMAL = 0x0,
  163. IX_I2C_REPEATED_START
  164. } IxI2cXferMode;
  165. /**
  166. * @ingroup IxI2cDrv
  167. *
  168. * @enum IxI2cFlowMode
  169. *
  170. * @brief Used for indicating it is a poll or interrupt mode
  171. */
  172. typedef enum
  173. {
  174. IX_I2C_POLL_MODE = 0x0,
  175. IX_I2C_INTERRUPT_MODE
  176. } IxI2cFlowMode;
  177. /**
  178. * @ingroup IxI2cDrv
  179. *
  180. * @enum IxI2cDelayMode
  181. *
  182. * @brief Used for selecting looping delay or OS scheduler delay
  183. */
  184. typedef enum
  185. {
  186. IX_I2C_LOOP_DELAY = 1, /**< delay in microseconds */
  187. IX_I2C_SCHED_DELAY /**< delay in miliseconds */
  188. } IxI2cDelayMode;
  189. /**
  190. * @ingroup IxI2cDrv
  191. *
  192. * @brief The pointer to the function that will be called when the master
  193. * has completed its receive. The parameter that is passed will
  194. * provide the status of the read (success, arb loss, or bus
  195. * error), the transfer mode (normal or repeated start, the
  196. * buffer pointer and number of bytes transferred.
  197. */
  198. typedef void (*IxI2cMasterReadCallbackP)(IxI2cMasterStatus, IxI2cXferMode, char*, UINT32);
  199. /**
  200. * @ingroup IxI2cDrv
  201. *
  202. * @brief The pointer to the function that will be called when the master
  203. * has completed its transmit. The parameter that is passed will
  204. * provide the status of the write (success, arb loss, or buss
  205. * error), the transfer mode (normal or repeated start), the
  206. * buffer pointer and number of bytes transferred.
  207. */
  208. typedef void (*IxI2cMasterWriteCallbackP)(IxI2cMasterStatus, IxI2cXferMode, char*, UINT32);
  209. /**
  210. * @ingroup IxI2cDrv
  211. *
  212. * @brief The pointer to the function that will be called when a slave
  213. * address detected in interrupt mode for a read. The parameters
  214. * that is passed will provide the read status, buffer pointer,
  215. * buffer size, and the bytes received. When a start of a read
  216. * is initiated there will be no buffer allocated and this callback
  217. * will be called to request for a buffer. While receiving, if the
  218. * buffer gets filled, this callback will be called to request for
  219. * a new buffer while sending the filled buffer's pointer and size,
  220. * and data size received. When the receive is complete, this
  221. * callback will be called to process the data and free the memory
  222. * by passing the buffer's pointer and size, and data size received.
  223. */
  224. typedef void (*IxI2cSlaveReadCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32);
  225. /**
  226. * @ingroup IxI2cDrv
  227. *
  228. * @brief The pointer to the function that will be called when a slave
  229. * address detected in interrupt mode for a write. The parameters
  230. * that is passed will provide the write status, buffer pointer,
  231. * buffer size, and the bytes received. When a start of a write is
  232. * initiated there will be no buffer allocated and this callback
  233. * will be called to request for a buffer and to fill it with data.
  234. * While transmitting, if the data in the buffer empties, this
  235. * callback will be called to request for more data to be filled in
  236. * the same or new buffer. When the transmit is complete, this
  237. * callback will be called to free the memory or other actions to
  238. * be taken.
  239. */
  240. typedef void (*IxI2cSlaveWriteCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32);
  241. /**
  242. * @ingroup IxI2cDrv
  243. *
  244. * @brief The pointer to the function that will be called when a general
  245. * call detected in interrupt mode for a read. The parameters that
  246. * is passed will provide the read status, buffer pointer, buffer
  247. * size, and the bytes received. When a start of a read is
  248. * initiated there will be no buffer allocated and this callback
  249. * will be called to request for a buffer. While receiving, if the
  250. * buffer gets filled, this callback will be called to request for
  251. * a new buffer while sending the filled buffer's pointer and size,
  252. * and data size received. When the receive is complete, this
  253. * callback will be called to process the data and free the memory
  254. * by passing the buffer's pointer and size, and data size received.
  255. */
  256. typedef void (*IxI2cGenCallCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32);
  257. /*
  258. * Section for struct
  259. */
  260. /**
  261. * @brief contains all the variables required to initialize the I2C unit
  262. *
  263. * Structure to be filled and used for calling initialization
  264. */
  265. typedef struct
  266. {
  267. IxI2cSpeedMode I2cSpeedSelect; /**<Select either normal (100kbps)
  268. or fast mode (400kbps)*/
  269. IxI2cFlowMode I2cFlowSelect; /**<Select interrupt or poll mode*/
  270. IxI2cMasterReadCallbackP MasterReadCBP;
  271. /**<The master read callback pointer */
  272. IxI2cMasterWriteCallbackP MasterWriteCBP;
  273. /**<The master write callback pointer */
  274. IxI2cSlaveReadCallbackP SlaveReadCBP;
  275. /**<The slave read callback pointer */
  276. IxI2cSlaveWriteCallbackP SlaveWriteCBP;
  277. /**<The slave write callback pointer */
  278. IxI2cGenCallCallbackP GenCallCBP;
  279. /**<The general call callback pointer */
  280. BOOL I2cGenCallResponseEnable; /**<Enable/disable the unit to
  281. respond to generall calls.*/
  282. BOOL I2cSlaveAddrResponseEnable;/**<Enable/disable the unit to
  283. respond to the slave address set in
  284. ISAR*/
  285. BOOL SCLEnable; /**<Enable/disable the unit from
  286. driving the SCL line during master
  287. mode operation*/
  288. UINT8 I2cHWAddr; /**<The address the unit will
  289. response to as a slave device*/
  290. } IxI2cInitVars;
  291. /**
  292. * @brief contains results of counters and their overflow
  293. *
  294. * Structure contains all values of counters and associated overflows.
  295. */
  296. typedef struct
  297. {
  298. UINT32 ixI2cMasterXmitCounter; /**<Total bytes transmitted as
  299. master.*/
  300. UINT32 ixI2cMasterFailedXmitCounter; /**<Total bytes failed for
  301. transmission as master.*/
  302. UINT32 ixI2cMasterRcvCounter; /**<Total bytes received as
  303. master.*/
  304. UINT32 ixI2cMasterFailedRcvCounter; /**<Total bytes failed for
  305. receival as master.*/
  306. UINT32 ixI2cSlaveXmitCounter; /**<Total bytes transmitted as
  307. slave.*/
  308. UINT32 ixI2cSlaveFailedXmitCounter; /**<Total bytes failed for
  309. transmission as slave.*/
  310. UINT32 ixI2cSlaveRcvCounter; /**<Total bytes received as
  311. slave.*/
  312. UINT32 ixI2cSlaveFailedRcvCounter; /**<Total bytes failed for
  313. receival as slave.*/
  314. UINT32 ixI2cGenAddrCallSucceedCounter; /**<Total bytes successfully
  315. transmitted for general address.*/
  316. UINT32 ixI2cGenAddrCallFailedCounter; /**<Total bytes failed transmission
  317. for general address.*/
  318. UINT32 ixI2cArbLossCounter; /**<Total instances of arbitration
  319. loss has occured.*/
  320. } IxI2cStatsCounters;
  321. /*
  322. * Section for prototypes interface functions
  323. */
  324. /**
  325. * @ingroup IxI2cDrv
  326. *
  327. * @fn ixI2cDrvInit(
  328. IxI2cInitVars *InitVarsSelected)
  329. *
  330. * @brief Initializes the I2C Driver.
  331. *
  332. * @param "IxI2cInitVars [in] *InitVarsSelected" - struct containing required
  333. * variables for initialization
  334. *
  335. * Global Data :
  336. * - None.
  337. *
  338. * This API will check if the hardware supports this I2C driver and the validity
  339. * of the parameters passed in. It will continue to process the parameters
  340. * passed in by setting the speed of the I2C unit (100kbps or 400kbps), setting
  341. * the flow to either interrupt or poll mode, setting the address of the I2C unit,
  342. * enabling/disabling the respond to General Calls, enabling/disabling the respond
  343. * to Slave Address and SCL line driving. If it is interrupt mode, then it will
  344. * register the callback routines for master, slavetransfer and general call receive.
  345. *
  346. * @return
  347. * - IX_I2C_SUCCESS - Successfully initialize and enable the I2C
  348. * hardware.
  349. * - IX_I2C_NOT_SUPPORTED - The hardware does not support or have a
  350. * dedicated I2C unit to support this driver
  351. * - IX_I2C_NULL_POINTER - The parameter passed in is a NULL pointed
  352. * - IX_I2C_INVALID_SPEED_MODE_ENUM_VALUE - The speed mode selected in the
  353. * InitVarsSelected is invalid
  354. * - IX_I2C_INVALID_FLOW_MODE_ENUM_VALUE - The flow mode selected in the
  355. * InitVarsSelected is invalid
  356. * - IX_I2C_INVALID_SLAVE_ADDR - The address 0x0 is reserved for
  357. * general call.
  358. * - IX_I2C_SLAVE_ADDR_CB_MISSING - interrupt mode is selected but
  359. * slave address callback pointer is NULL
  360. * - IX_I2C_GEN_CALL_CB_MISSING - interrupt mode is selected but
  361. * general call callback pointer is NULL
  362. * - IX_I2C_INT_BIND_FAIL - The ISR for the I2C failed to bind
  363. * - IX_I2C_INT_UNBIND_FAIL - The ISR for the I2C failed to unbind
  364. *
  365. * @li Reentrant : yes
  366. * @li ISR Callable : yes
  367. *
  368. */
  369. PUBLIC IX_I2C_STATUS
  370. ixI2cDrvInit(IxI2cInitVars *InitVarsSelected);
  371. /**
  372. * @ingroup IxI2cDrv
  373. *
  374. * @fn ixI2cDrvUninit(
  375. void)
  376. *
  377. * @brief Disables the I2C hardware
  378. *
  379. * @param - None
  380. *
  381. * Global Data :
  382. * - None.
  383. *
  384. * This API will disable the I2C hardware, unbind interrupt, and unmap memory.
  385. *
  386. * @return
  387. * - IX_I2C_SUCCESS - successfully un-initialized I2C
  388. * - IX_I2C_INT_UNBIND_FAIL - failed to unbind the I2C interrupt
  389. * - IX_I2C_NOT_INIT - I2C not init yet.
  390. *
  391. * @li Reentrant : yes
  392. * @li ISR Callable : yes
  393. *
  394. */
  395. PUBLIC IX_I2C_STATUS
  396. ixI2cDrvUninit(void);
  397. /**
  398. * @ingroup IxI2cDrv
  399. *
  400. * @fn ixI2cDrvSlaveAddrSet(
  401. UINT8 SlaveAddrSet)
  402. *
  403. * @brief Sets the I2C Slave Address
  404. *
  405. * @param "UINT8 [in] SlaveAddrSet" - Slave Address to be inserted into ISAR
  406. *
  407. * Global Data :
  408. * - None.
  409. *
  410. * This API will insert the SlaveAddrSet into the ISAR.
  411. *
  412. * @return
  413. * - IX_I2C_SUCCESS - successfuly set the slave addr
  414. * - IX_I2C_INVALID_SLAVE_ADDR - invalid slave address (zero) specified
  415. * - IX_I2C_NOT_INIT - I2C not init yet.
  416. *
  417. * @li Reentrant : yes
  418. * @li ISR Callable : yes
  419. *
  420. */
  421. PUBLIC IX_I2C_STATUS
  422. ixI2cDrvSlaveAddrSet(UINT8 SlaveAddrSet);
  423. /**
  424. * @ingroup IxI2cDrv
  425. *
  426. * @fn ixI2cDrvBusScan(
  427. void)
  428. *
  429. * @brief scans the I2C bus for slave devices
  430. *
  431. * @param - None
  432. *
  433. * Global Data :
  434. * - None.
  435. *
  436. * This API will prompt all slave addresses for a reply except its own
  437. *
  438. * @return
  439. * - IX_I2C_SUCCESS - found at least one slave device
  440. * - IX_I2C_FAIL - Fail to find even one slave device
  441. * - IX_I2C_BUS_BUSY - The I2C bus is busy (held by another I2C master)
  442. * - IX_I2C_ARB_LOSS - The I2C bus was loss to another I2C master
  443. * - IX_I2C_NOT_INIT - I2C not init yet.
  444. *
  445. * @li Reentrant : yes
  446. * @li ISR Callable : yes
  447. *
  448. */
  449. PUBLIC IX_I2C_STATUS
  450. ixI2cDrvBusScan(void);
  451. /**
  452. * @ingroup IxI2cDrv
  453. *
  454. * @fn ixI2cDrvWriteTransfer(
  455. UINT8 SlaveAddr,
  456. char *bufP,
  457. UINT32 dataSize,
  458. IxI2cXferMode XferModeSelect)
  459. *
  460. * @param "UINT8 [in] SlaveAddr" - The slave address to request data from.
  461. * @param "char [in] *bufP" - The pointer to the data to be transmitted.
  462. * @param "UINT32 [in] dataSize" - The number of bytes requested.
  463. * @param "IxI2cXferMode [in] XferModeSelect" - the transfer mode selected,
  464. * either repeated start (ends w/o stop) or normal (start and stop)
  465. *
  466. * Global Data :
  467. * - None.
  468. *
  469. * This API will try to obtain master control of the I2C bus and transmit the
  470. * number of bytes, specified by dataSize, to the user specified slave
  471. * address from the buffer pointer. It will use either interrupt or poll mode
  472. * depending on the method selected.
  473. *
  474. * If in interrupt mode and IxI2cMasterWriteCallbackP is not NULL, the driver
  475. * will initiate the transfer and return immediately. The function pointed to
  476. * by IxI2cMasterWriteCallbackP will be called in the interrupt service
  477. * handlers when the operation is complete.
  478. *
  479. * If in interrupt mode and IxI2cMasterWriteCallbackP is NULL, then the driver
  480. * will wait for the operation to complete, and then return.
  481. *
  482. * And if the repeated start transfer mode is selected, then it will not send a
  483. * stop signal at the end of all the transfers.
  484. * *NOTE*: If repeated start transfer mode is selected, it has to end with a
  485. * normal mode transfer mode else the bus will continue to be held
  486. * by the IXP.
  487. *
  488. * @return
  489. * - IX_I2C_SUCCESS - Successfuuly wrote data to slave.
  490. * - IX_I2C_MASTER_BUS_BUSY - The I2C bus is busy (held by another I2C master)
  491. * - IX_I2C_MASTER_ARB_LOSS - The I2C bus was loss to another I2C master
  492. * - IX_I2C_MASTER_XFER_ERROR - There was a transfer error
  493. * - IX_I2C_MASTER_BUS_ERROR - There was a bus error during transfer
  494. * - IX_I2C_MASTER_NO_BUFFER - buffer pointer is NULL
  495. * - IX_I2C_MASTER_INVALID_XFER_MODE - Xfer mode selected is invalid
  496. * - IX_I2C_DATA_SIZE_ZERO - dataSize passed in is zero, which is invalid
  497. * - IX_I2C_NOT_INIT - I2C not init yet.
  498. *
  499. * @li Reentrant : no
  500. * @li ISR Callable : no
  501. *
  502. */
  503. PUBLIC IX_I2C_STATUS
  504. ixI2cDrvWriteTransfer(
  505. UINT8 SlaveAddr,
  506. char *bufP,
  507. UINT32 dataSize,
  508. IxI2cXferMode XferModeSelect);
  509. /**
  510. * @ingroup IxI2cDrv
  511. *
  512. * @fn ixI2cDrvReadTransfer(
  513. UINT8 SlaveAddr,
  514. char *bufP,
  515. UINT32 dataSize,
  516. IxI2cXferMode XferModeSelect)
  517. *
  518. * @brief Initiates a transfer to receive bytes of data from a slave
  519. * device through the I2C bus.
  520. *
  521. * @param "UINT8 [in] SlaveAddr" - The slave address to request data from.
  522. * @param "char [out] *bufP" - The pointer to the buffer to store the
  523. * requested data.
  524. * @param "UINT32 [in] dataSize" - The number of bytes requested.
  525. * @param "IxI2cXferMode [in] XferModeSelect" - the transfer mode selected,
  526. * either repeated start (ends w/o stop) or normal (start and stop)
  527. *
  528. * Global Data :
  529. * - None.
  530. *
  531. * This API will try to obtain master control of the I2C bus and receive the
  532. * number of bytes, specified by dataSize, from the user specified address
  533. * into the receive buffer. It will use either interrupt or poll mode depending
  534. * on the mode selected.
  535. *
  536. * If in interrupt mode and IxI2cMasterReadCallbackP is not NULL, the driver
  537. * will initiate the transfer and return immediately. The function pointed to
  538. * by IxI2cMasterReadCallbackP will be called in the interrupt service
  539. * handlers when the operation is complete.
  540. *
  541. * If in interrupt mode and IxI2cMasterReadCallbackP is NULL, then the driver will
  542. * wait for the operation to complete, and then return.
  543. *
  544. * And if the repeated start transfer mode is selected, then it will not send a
  545. * stop signal at the end of all the transfers.
  546. * *NOTE*: If repeated start transfer mode is selected, it has to end with a
  547. * normal mode transfer mode else the bus will continue to be held
  548. * by the IXP.
  549. *
  550. * @return
  551. * - IX_I2C_SUCCESS - Successfuuly read slave data
  552. * - IX_I2C_MASTER_BUS_BUSY - The I2C bus is busy (held by another I2C master)
  553. * - IX_I2C_MASTER_ARB_LOSS - The I2C bus was loss to another I2C master
  554. * - IX_I2C_MASTER_XFER_ERROR - There was a bus error during transfer
  555. * - IX_I2C_MASTER_BUS_ERROR - There was a bus error during transfer
  556. * - IX_I2C_MASTER_NO_BUFFER - buffer pointer is NULL
  557. * - IX_I2C_MASTER_INVALID_XFER_MODE - Xfer mode selected is invalid
  558. * - IX_I2C_INVALID_SLAVE_ADDR - invalid slave address (zero) specified
  559. * - IX_I2C_DATA_SIZE_ZERO - dataSize passed in is zero, which is invalid
  560. * - IX_I2C_NOT_INIT - I2C not init yet.
  561. *
  562. * @li Reentrant : no
  563. * @li ISR Callable : no
  564. *
  565. */
  566. PUBLIC IX_I2C_STATUS
  567. ixI2cDrvReadTransfer(
  568. UINT8 SlaveAddr,
  569. char *bufP,
  570. UINT32 dataSize,
  571. IxI2cXferMode XferModeSelect);
  572. /**
  573. * @ingroup IxI2cDrv
  574. *
  575. * @fn ixI2cDrvSlaveAddrAndGenCallDetectedCheck(
  576. void)
  577. *
  578. * @brief Checks the I2C Status Register to determine if a slave address is
  579. * detected
  580. *
  581. * @param - None
  582. *
  583. * Global Data :
  584. * - None.
  585. *
  586. * This API is used in polled mode to determine if the I2C unit is requested
  587. * for a slave or general call transfer. If it is requested for a slave
  588. * transfer then it will determine if it is a general call (read only), read,
  589. * or write transfer requested.
  590. *
  591. * @return
  592. * - IX_I2C_SLAVE_ADDR_NOT_DETECTED - The I2C unit is not requested for slave
  593. * transfer
  594. * - IX_I2C_GEN_CALL_ADDR_DETECTED - The I2C unit is not requested for slave
  595. * transfer but for general call
  596. * - IX_I2C_SLAVE_READ_DETECTED - The I2C unit is requested for a read
  597. * - IX_I2C_SLAVE_WRITE_DETECTED - The I2C unit is requested for a write
  598. * - IX_I2C_NOT_INIT - I2C not init yet.
  599. *
  600. * @li Reentrant : no
  601. * @li ISR Callable : no
  602. *
  603. */
  604. PUBLIC IX_I2C_STATUS
  605. ixI2cDrvSlaveAddrAndGenCallDetectedCheck(void);
  606. /**
  607. * @ingroup IxI2cDrv
  608. *
  609. * @fn ixI2cDrvSlaveOrGenDataReceive(
  610. char *bufP,
  611. UINT32 bufSize,
  612. UINT32 *dataSizeRcvd)
  613. *
  614. * @brief Performs the slave receive or general call receive data transfer
  615. *
  616. * @param "char [in] *bufP" - the pointer to the buffer to store data
  617. * "UINT32 [in] bufSize" - the buffer size allocated
  618. * "UINT32 [in] *dataSizeRcvd" - the length of data received in bytes
  619. *
  620. * Global Data :
  621. * - None.
  622. *
  623. * This API is only used in polled mode to perform the slave read or general call
  624. * receive data. It will continuously store the data received into bufP until
  625. * complete or until bufP is full in which it will return
  626. * IX_I2C_SLAVE_OR_GEN_READ_BUFFER_FULL. If in interrupt mode, the callback will be
  627. * used.
  628. *
  629. * @return
  630. * - IX_I2C_SUCCESS - The I2C driver transferred the data successfully.
  631. * - IX_I2C_SLAVE_OR_GEN_READ_BUFFER_FULL - The I2C driver has ran out of
  632. * space to store the received data.
  633. * - IX_I2C_SLAVE_OR_GEN_READ_ERROR - The I2C driver didn't manage to
  634. * detect the IDBR Rx Full bit
  635. * - IX_I2C_DATA_SIZE_ZERO - bufSize passed in is zero, which is invalid
  636. * - IX_I2C_SLAVE_NO_BUFFER - buffer pointer is NULL
  637. * - IX_I2C_NULL_POINTER - dataSizeRcvd is NULL
  638. * - IX_I2C_NOT_INIT - I2C not init yet.
  639. *
  640. * @li Reentrant : no
  641. * @li ISR Callable : no
  642. *
  643. */
  644. PUBLIC IX_I2C_STATUS
  645. ixI2cDrvSlaveOrGenDataReceive(
  646. char *bufP,
  647. UINT32 bufSize,
  648. UINT32 *dataSizeRcvd);
  649. /**
  650. * @ingroup IxI2cDrv
  651. *
  652. * @fn ixI2cDrvSlaveDataTransmit(
  653. char *bufP,
  654. UINT32 dataSize,
  655. UINT32 *dataSizeXmtd)
  656. *
  657. * @brief Performs the slave write data transfer
  658. *
  659. * @param "char [in] *bufP" - the pointer to the buffer for data to be
  660. * transmitted
  661. * "UINT32 [in] bufSize" - the buffer size allocated
  662. * "UINT32 [in] *dataSizeRcvd" - the length of data trasnmitted in
  663. * bytes
  664. *
  665. * Global Data :
  666. * - None.
  667. *
  668. * This API is only used in polled mode to perform the slave transmit data. It
  669. * will continuously transmit the data from bufP until complete or until bufP
  670. * is empty in which it will return IX_I2C_SLAVE_WRITE_BUFFER_EMPTY. If in
  671. * interrupt mode, the callback will be used.
  672. *
  673. * @return
  674. * - IX_I2C_SUCCESS - The I2C driver transferred the data successfully.
  675. * - IX_I2C_SLAVE_WRITE_BUFFER_EMPTY - The I2C driver needs more data to
  676. * transmit.
  677. * - IX_I2C_SLAVE_WRITE_ERROR -The I2C driver didn't manage to detect the
  678. * IDBR Tx empty bit or the slave stop bit.
  679. * - IX_I2C_DATA_SIZE_ZERO - dataSize passed in is zero, which is invalid
  680. * - IX_I2C_SLAVE_NO_BUFFER - buffer pointer is NULL
  681. * - IX_I2C_NULL_POINTER - dataSizeXmtd is NULL
  682. * - IX_I2C_NOT_INIT - I2C not init yet.
  683. *
  684. * @li Reentrant : no
  685. * @li ISR Callable : no
  686. *
  687. */
  688. PUBLIC IX_I2C_STATUS
  689. ixI2cDrvSlaveDataTransmit(
  690. char *bufP,
  691. UINT32 dataSize,
  692. UINT32 *dataSizeXmtd);
  693. /**
  694. * @ingroup IxI2cDrv
  695. *
  696. * @fn ixI2cDrvSlaveOrGenCallBufReplenish(
  697. char *bufP,
  698. UINT32 bufSize)
  699. *
  700. * @brief Replenishes the buffer which stores buffer info for both slave and
  701. * general call
  702. *
  703. * @param "char [in] *bufP" - pointer to the buffer allocated
  704. * "UINT32 [in] bufSize" - size of the buffer
  705. *
  706. * Global Data :
  707. * - None.
  708. *
  709. * This API is only used in interrupt mode for replenishing the same buffer
  710. * that is used by both slave and generall call by updating the buffer info
  711. * with new info and clearing previous offsets set by previous transfers.
  712. *
  713. * @return
  714. * - None
  715. *
  716. * @li Reentrant : no
  717. * @li ISR Callable : no
  718. *
  719. */
  720. PUBLIC void
  721. ixI2cDrvSlaveOrGenCallBufReplenish(
  722. char *bufP,
  723. UINT32 bufSize);
  724. /**
  725. * @ingroup IxI2cDrv
  726. *
  727. * @fn ixI2cDrvStatsGet(IxI2cStatsCounters *I2cStats)
  728. *
  729. * @brief Returns the I2C Statistics through the pointer passed in
  730. *
  731. * @param - "IxI2cStatsCounters [out] *I2cStats" - I2C statistics counter will
  732. * be read and written to the location pointed by this pointer.
  733. *
  734. * Global Data :
  735. * - None.
  736. *
  737. * This API will return the statistics counters of the I2C driver.
  738. *
  739. * @return
  740. * - IX_I2C_NULL_POINTER - pointer passed in is NULL
  741. * - IX_I2C_SUCCESS - successfully obtained I2C statistics
  742. *
  743. * @li Reentrant : yes
  744. * @li ISR Callable : no
  745. *
  746. */
  747. PUBLIC IX_I2C_STATUS
  748. ixI2cDrvStatsGet(IxI2cStatsCounters *I2cStats);
  749. /**
  750. * @ingroup IxI2cDrv
  751. *
  752. * @fn ixI2cDrvStatsReset(void)
  753. *
  754. * @brief Reset I2C statistics counters.
  755. *
  756. * @param - None
  757. *
  758. * Global Data :
  759. * - None.
  760. *
  761. * This API will reset the statistics counters of the I2C driver.
  762. *
  763. * @return
  764. * - None
  765. *
  766. * @li Reentrant : yes
  767. * @li ISR Callable : no
  768. *
  769. */
  770. PUBLIC void
  771. ixI2cDrvStatsReset(void);
  772. /**
  773. * @ingroup IxI2cDrv
  774. *
  775. * @fn ixI2cDrvShow(void)
  776. *
  777. * @brief Displays the I2C status register and the statistics counter.
  778. *
  779. * @param - None
  780. *
  781. * Global Data :
  782. * - None.
  783. *
  784. * This API will display the I2C Status register and is useful if any error
  785. * occurs. It displays the detection of bus error, slave address, general call,
  786. * address, IDBR receive full, IDBR transmit empty, arbitration loss, slave
  787. * STOP signal, I2C bus busy, unit busy, ack/nack, and read/write mode. It will
  788. * also call the ixI2cDrvGetStats and then display the statistics counter.
  789. *
  790. * @return
  791. * - IX_I2C_SUCCESS - successfully displayed statistics and status register
  792. * - IX_I2C_NOT_INIT - I2C not init yet.
  793. *
  794. * @li Reentrant : yes
  795. * @li ISR Callable : no
  796. *
  797. */
  798. PUBLIC IX_I2C_STATUS
  799. ixI2cDrvShow(void);
  800. /**
  801. * @ingroup IxI2cDrv
  802. *
  803. * @fn ixI2cDrvDelayTypeSelect (IxI2cDelayMode delayMechanismSelect)
  804. *
  805. * @brief Sets the delay type of either looping delay or OS scheduler delay
  806. * according to the argument provided.
  807. *
  808. * @param - "IxI2cDelayMode [in] delayTypeSelect" - the I2C delay type selected
  809. *
  810. * Global Data :
  811. * - None.
  812. *
  813. * This API will set the delay type used by the I2C Driver to either looping
  814. * delay or OS scheduler delay.
  815. *
  816. * @return
  817. * - None
  818. *
  819. * @li Reentrant : yes
  820. * @li ISR Callable : no
  821. *
  822. */
  823. PUBLIC void
  824. ixI2cDrvDelayTypeSelect (IxI2cDelayMode delayTypeSelect);
  825. #endif /* __ixp46X */
  826. #endif /* IXI2CDRV_H */