am_hal_iom.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. //*****************************************************************************
  2. //
  3. // am_hal_iom.h
  4. //! @file
  5. //!
  6. //! @brief Functions for accessing and configuring the IO Master module
  7. //!
  8. //! @addtogroup iom2 IO Master (SPI/I2C)
  9. //! @ingroup apollo2hal
  10. //! @{
  11. //*****************************************************************************
  12. //*****************************************************************************
  13. //
  14. // Copyright (c) 2017, Ambiq Micro
  15. // All rights reserved.
  16. //
  17. // Redistribution and use in source and binary forms, with or without
  18. // modification, are permitted provided that the following conditions are met:
  19. //
  20. // 1. Redistributions of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  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. //
  27. // 3. Neither the name of the copyright holder nor the names of its
  28. // contributors may be used to endorse or promote products derived from this
  29. // software without specific prior written permission.
  30. //
  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 HOLDER OR CONTRIBUTORS BE
  35. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  36. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  38. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  39. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. // POSSIBILITY OF SUCH DAMAGE.
  42. //
  43. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  44. //
  45. //*****************************************************************************
  46. #ifndef AM_HAL_IOM_H
  47. #define AM_HAL_IOM_H
  48. //*****************************************************************************
  49. //
  50. // Macro definitions
  51. //
  52. //*****************************************************************************
  53. //*****************************************************************************
  54. //
  55. //! @name IOM Clock Frequencies
  56. //! @brief Macro definitions for common SPI and I2C clock frequencies.
  57. //!
  58. //! These macros may be used with the ui32ClockFrequency member of the
  59. //! am_hal_iom_config_t structure to set the clock frequency of the serial
  60. //! interfaces.
  61. //!
  62. //! This list of frequencies is not exhaustive by any means. If your desired
  63. //! frequency is not in this list, simply set ui32ClockFrequency to the
  64. //! desired frequency (in Hz) when calling am_hal_iom_config().
  65. //
  66. //*****************************************************************************
  67. #define AM_HAL_IOM_24MHZ 24000000
  68. #define AM_HAL_IOM_16MHZ 16000000
  69. #define AM_HAL_IOM_12MHZ 12000000
  70. #define AM_HAL_IOM_8MHZ 8000000
  71. #define AM_HAL_IOM_6MHZ 6000000
  72. #define AM_HAL_IOM_4MHZ 4000000
  73. #define AM_HAL_IOM_3MHZ 3000000
  74. #define AM_HAL_IOM_2MHZ 2000000
  75. #define AM_HAL_IOM_1_5MHZ 1500000
  76. #define AM_HAL_IOM_1MHZ 1000000
  77. #define AM_HAL_IOM_800KHZ 800000
  78. #define AM_HAL_IOM_750KHZ 750000
  79. #define AM_HAL_IOM_500KHZ 500000
  80. #define AM_HAL_IOM_400KHZ 400000
  81. #define AM_HAL_IOM_375KHZ 375000
  82. #define AM_HAL_IOM_250KHZ 250000
  83. #define AM_HAL_IOM_200KHZ 200000
  84. #define AM_HAL_IOM_125KHZ 125000
  85. #define AM_HAL_IOM_100KHZ 100000
  86. #define AM_HAL_IOM_50KHZ 50000
  87. #define AM_HAL_IOM_10KHZ 10000
  88. // Hardware FIFO Size
  89. #define AM_HAL_IOM_MAX_FIFO_SIZE 128
  90. //*****************************************************************************
  91. //
  92. //! @name IOM Physical Protocols
  93. //! @brief Macro Definitions for general IOM configuration.
  94. //!
  95. //! These macros may be used with the am_hal_iom_config_t structure to set the
  96. //! operating parameters of each serial IO master module. Choose SPIMODE to
  97. //! select the SPI interface, or I2CMODE to select the I2C interface.
  98. //!
  99. //! @{
  100. //
  101. //*****************************************************************************
  102. #define AM_HAL_IOM_SPIMODE AM_REG_IOMSTR_CFG_IFCSEL(1)
  103. #define AM_HAL_IOM_I2CMODE AM_REG_IOMSTR_CFG_IFCSEL(0)
  104. //! @}
  105. //*****************************************************************************
  106. //
  107. //! @name IOM Operations
  108. //! @brief Macro definitions used for ui32Operation parameters.
  109. //!
  110. //! These macros may be used to specify which action an IOM command will
  111. //! execute. The 'OFFSET' operations will cause the IOM hardware to transmit the
  112. //! provided 1-byte 'offset' before executing the rest of the command.
  113. //!
  114. //! @{
  115. //
  116. //*****************************************************************************
  117. #define AM_HAL_IOM_WRITE 0x00000000
  118. #define AM_HAL_IOM_READ 0x80000000
  119. //! @}
  120. //*****************************************************************************
  121. //
  122. //! @name Command Options
  123. //! @brief Macro definitions used for ui32Options parameters.
  124. //!
  125. //! These macros are all related to SPI or I2C command words. They can be used
  126. //! to set specific options on a per-transaction basis.
  127. //!
  128. //! - CS_LOW - Do not raise the CS signal at the end of this SPI command.
  129. //! - NO_STOP - Do not release the I2C bus with a STOP bit after this command.
  130. //! - LSB_FIRST - Reverse the payload bits of this command.
  131. //! - 10BIT_ADDRESS - (I2C only) use a 10-bit I2C address protocol.
  132. //! - RAW - Don't use an offset byte.
  133. //! - OFFSET() - Send this 1-byte offset as the first byte of the transaction.
  134. //! This can be used to access "registers" in external I2C devices, or add a
  135. //! 1-byte write to the beginning of a SPI write or read command. See
  136. //! "normal mode" operation in the I2C/SPI Master section of the datasheet
  137. //! for more information on this parameter.
  138. //!
  139. //! @{
  140. //
  141. //*****************************************************************************
  142. #define AM_HAL_IOM_CS_LOW 0x10000000
  143. #define AM_HAL_IOM_NO_STOP 0x10000000
  144. #define AM_HAL_IOM_LSB_FIRST 0x08000000
  145. #define AM_HAL_IOM_10BIT_ADDRESS 0x04000000
  146. #define AM_HAL_IOM_RAW 0x40000000
  147. #define AM_HAL_IOM_OFFSET(n) (((n) << 8) & 0x0000FF00)
  148. //! @}
  149. //*****************************************************************************
  150. //
  151. //! @name IOM Interrupts
  152. //! @brief Macro definitions for IOM interrupt status bits.
  153. //!
  154. //! These macros correspond to the bits in the IOM interrupt status register.
  155. //! They may be used with any of the \e am_hal_iom_int_x() functions.
  156. //!
  157. //! @{
  158. //
  159. //*****************************************************************************
  160. #define AM_HAL_IOM_INT_ARB AM_REG_IOMSTR_INTEN_ARB_M
  161. #define AM_HAL_IOM_INT_STOP AM_REG_IOMSTR_INTEN_STOP_M
  162. #define AM_HAL_IOM_INT_START AM_REG_IOMSTR_INTEN_START_M
  163. #define AM_HAL_IOM_INT_ICMD AM_REG_IOMSTR_INTEN_ICMD_M
  164. #define AM_HAL_IOM_INT_IACC AM_REG_IOMSTR_INTEN_IACC_M
  165. #define AM_HAL_IOM_INT_WTLEN AM_REG_IOMSTR_INTEN_WTLEN_M
  166. #define AM_HAL_IOM_INT_NAK AM_REG_IOMSTR_INTEN_NAK_M
  167. #define AM_HAL_IOM_INT_FOVFL AM_REG_IOMSTR_INTEN_FOVFL_M
  168. #define AM_HAL_IOM_INT_FUNDFL AM_REG_IOMSTR_INTEN_FUNDFL_M
  169. #define AM_HAL_IOM_INT_THR AM_REG_IOMSTR_INTEN_THR_M
  170. #define AM_HAL_IOM_INT_CMDCMP AM_REG_IOMSTR_INTEN_CMDCMP_M
  171. #define AM_HAL_IOM_INT_ALL ( \
  172. AM_HAL_IOM_INT_ARB | \
  173. AM_HAL_IOM_INT_STOP | \
  174. AM_HAL_IOM_INT_START | \
  175. AM_HAL_IOM_INT_ICMD | \
  176. AM_HAL_IOM_INT_IACC | \
  177. AM_HAL_IOM_INT_WTLEN | \
  178. AM_HAL_IOM_INT_NAK | \
  179. AM_HAL_IOM_INT_FOVFL | \
  180. AM_HAL_IOM_INT_FUNDFL | \
  181. AM_HAL_IOM_INT_THR | \
  182. AM_HAL_IOM_INT_CMDCMP)
  183. #define AM_HAL_IOM_INT_SWERR ( \
  184. AM_HAL_IOM_INT_ICMD | \
  185. AM_HAL_IOM_INT_FOVFL | \
  186. AM_HAL_IOM_INT_FUNDFL | \
  187. AM_HAL_IOM_INT_IACC)
  188. #define AM_HAL_IOM_INT_I2CARBERR ( \
  189. AM_HAL_IOM_INT_ARB | \
  190. AM_HAL_IOM_INT_START | \
  191. AM_HAL_IOM_INT_STOP)
  192. //! @}
  193. //*****************************************************************************
  194. //
  195. //! @name Software IOM modules
  196. //! @brief Macro definitions for using the software I2C interface.
  197. //!
  198. //! Use this macro as the module number for standard IOM functions to emulate
  199. //! them using the bit-banged i2c interface.
  200. //!
  201. //! @{
  202. //
  203. //*****************************************************************************
  204. #define AM_HAL_IOM_I2CBB_MODULE AM_REG_IOMSTR_NUM_MODULES
  205. //! @}
  206. //*****************************************************************************
  207. //
  208. //! @name IOM Return Codes
  209. //! @brief Enum definitions for defining return values for IOM APIs
  210. //!
  211. //! This enum defines possible values for non-void IOM APIs
  212. //!
  213. //! @{
  214. //
  215. //*****************************************************************************
  216. typedef enum
  217. {
  218. AM_HAL_IOM_SUCCESS = 0,
  219. AM_HAL_IOM_ERR_TIMEOUT,
  220. AM_HAL_IOM_ERR_INVALID_MODULE,
  221. AM_HAL_IOM_ERR_INVALID_PARAM,
  222. AM_HAL_IOM_ERR_INVALID_CFG,
  223. AM_HAL_IOM_ERR_INVALID_OPER,
  224. AM_HAL_IOM_ERR_I2C_NAK,
  225. AM_HAL_IOM_ERR_I2C_ARB,
  226. AM_HAL_IOM_ERR_RESOURCE_ERR,
  227. } am_hal_iom_status_e ;
  228. //! @}
  229. //*****************************************************************************
  230. //
  231. //! @brief Union type for a word-aligned, byte-addressable array.
  232. //!
  233. //! This is a convenience macro that may be used to define byte-addressable
  234. //! arrays with 32-bit alignment. This allows the programmer to define SPI or
  235. //! I2C transactions as a series of 8-bit values, but also write them to the
  236. //! IOM FIFO efficiently as a series of 32-bit values.
  237. //!
  238. //! Example usage:
  239. //!
  240. //! @code
  241. //! //
  242. //! // Declare a buffer array with at least 3-bytes worth of space.
  243. //! //
  244. //! am_hal_iom_buffer(3) sBuffer;
  245. //!
  246. //! //
  247. //! // Populate the buffer with a 3-byte command.
  248. //! //
  249. //! sBuffer.bytes[0] = 's';
  250. //! sBuffer.bytes[1] = 'p';
  251. //! sBuffer.bytes[2] = 'i';
  252. //!
  253. //! //
  254. //! // Send the buffer over the spi interface.
  255. //! //
  256. //! am_hal_iom_spi_write(psDevice, sBuffer.words, 3, 0);
  257. //!
  258. //! @endcode
  259. //
  260. //*****************************************************************************
  261. #define am_hal_iom_buffer(A) \
  262. union \
  263. { \
  264. uint32_t words[(A + 3) >> 2]; \
  265. uint8_t bytes[A]; \
  266. }
  267. //*****************************************************************************
  268. //
  269. //! @brief Configuration structure for the IO master module.
  270. //
  271. //*****************************************************************************
  272. typedef struct
  273. {
  274. //
  275. //! @brief Selects the physical protocol for the IO master module. Choose
  276. //! either AM_HAL_IOM_SPIMODE or AM_HAL_IOM_I2CMODE.
  277. //
  278. uint32_t ui32InterfaceMode;
  279. //
  280. //! @brief Selects the output clock frequency for SPI or I2C mode. Choose
  281. //! one of the AM_HAL_IOM_nMHZ or AM_HAL_IOM_nKHZ macros.
  282. //
  283. uint32_t ui32ClockFrequency;
  284. //
  285. //! Select the SPI clock phase (unused in I2C mode).
  286. //
  287. bool bSPHA;
  288. //
  289. //! Select the SPI clock polarity (unused in I2C mode).
  290. //
  291. bool bSPOL;
  292. //
  293. //! @brief Select the FIFO write threshold.
  294. //!
  295. //! The IOM controller will generate a processor interrupt when the number
  296. //! of entries in the FIFO goes *below* this number.
  297. //
  298. uint8_t ui8WriteThreshold;
  299. //
  300. //! @brief Select the FIFO read threshold.
  301. //!
  302. //! The IOM controller will generate a processor interrupt when the number
  303. //! of entries in the FIFO grows *larger* than this number.
  304. //
  305. uint8_t ui8ReadThreshold;
  306. }
  307. am_hal_iom_config_t;
  308. //*****************************************************************************
  309. //
  310. //! Configuration structure for an individual SPI device.
  311. //
  312. //*****************************************************************************
  313. typedef struct
  314. {
  315. //
  316. //! IOM module to use for communicating with this device.
  317. //
  318. uint32_t ui32Module;
  319. //
  320. //! Chip select signal that should be used for this device.
  321. //
  322. uint32_t ui32ChipSelect;
  323. //
  324. //! Additional options that will ALWAYS be ORed into the command word.
  325. //
  326. uint32_t ui32Options;
  327. }
  328. am_hal_iom_spi_device_t;
  329. //*****************************************************************************
  330. //
  331. //! Configuration structure for an individual I2C device.
  332. //
  333. //*****************************************************************************
  334. typedef struct
  335. {
  336. //
  337. //! IOM module to use for communicating with this device.
  338. //
  339. uint32_t ui32Module;
  340. //
  341. //! I2C address associated with this device.
  342. //
  343. uint32_t ui32BusAddress;
  344. //
  345. //! Additional options that will ALWAYS be ORed into the command word.
  346. //
  347. uint32_t ui32Options;
  348. }
  349. am_hal_iom_i2c_device_t;
  350. //*****************************************************************************
  351. //
  352. // Typedef for non-blocking function callbacks.
  353. //
  354. //*****************************************************************************
  355. typedef void (*am_hal_iom_callback_t)(void);
  356. //*****************************************************************************
  357. //
  358. // Typedef for a function that waits until the IOM queue is empty.
  359. //
  360. //*****************************************************************************
  361. typedef void (*am_hal_iom_queue_flush_t)(uint32_t);
  362. extern am_hal_iom_queue_flush_t am_hal_iom_queue_flush;
  363. //*****************************************************************************
  364. //
  365. // Operations
  366. //
  367. //*****************************************************************************
  368. #define AM_HAL_IOM_QUEUE_SPI_WRITE 0
  369. #define AM_HAL_IOM_QUEUE_SPI_READ 1
  370. #define AM_HAL_IOM_QUEUE_I2C_WRITE 2
  371. #define AM_HAL_IOM_QUEUE_I2C_READ 3
  372. //*****************************************************************************
  373. //
  374. // Structure to hold IOM operations.
  375. //
  376. //*****************************************************************************
  377. typedef struct
  378. {
  379. uint32_t ui32Operation;
  380. uint32_t ui32Module;
  381. uint32_t ui32ChipSelect;
  382. uint32_t *pui32Data;
  383. uint32_t ui32NumBytes;
  384. uint32_t ui32Options;
  385. am_hal_iom_callback_t pfnCallback;
  386. }
  387. am_hal_iom_queue_entry_t;
  388. //*****************************************************************************
  389. //
  390. // Structure to hold IOM configuration during module power-down.
  391. //
  392. //*****************************************************************************
  393. typedef struct
  394. {
  395. uint32_t FIFOTHR;
  396. uint32_t CLKCFG;
  397. uint32_t CFG;
  398. uint32_t INTEN;
  399. uint32_t bValid;
  400. }
  401. am_hal_iom_pwrsave_t;
  402. //*****************************************************************************
  403. //
  404. // Global variables
  405. //
  406. //*****************************************************************************
  407. extern am_hal_iom_pwrsave_t am_hal_iom_pwrsave[AM_REG_IOMSTR_NUM_MODULES];
  408. #ifdef __cplusplus
  409. extern "C"
  410. {
  411. #endif
  412. //*****************************************************************************
  413. //
  414. // External function definitions
  415. //
  416. //*****************************************************************************
  417. extern void am_hal_iom_pwrctrl_enable(uint32_t ui32Module);
  418. extern void am_hal_iom_pwrctrl_disable(uint32_t ui32Module);
  419. extern void am_hal_iom_power_on_restore(uint32_t ui32Module);
  420. extern void am_hal_iom_power_off_save(uint32_t ui32Module);
  421. extern void am_hal_iom_config(uint32_t ui32Module,
  422. const am_hal_iom_config_t *psConfig);
  423. extern uint32_t am_hal_iom_frequency_get(uint32_t ui32Module);
  424. extern void am_hal_iom_enable(uint32_t ui32Module);
  425. extern void am_hal_iom_disable(uint32_t ui32Module);
  426. extern am_hal_iom_status_e am_hal_iom_spi_write(uint32_t ui32Module, uint32_t ui32ChipSelect,
  427. uint32_t *pui32Data, uint32_t ui32NumBytes,
  428. uint32_t ui32Options);
  429. extern am_hal_iom_status_e am_hal_iom_spi_read(uint32_t ui32Module, uint32_t ui32ChipSelect,
  430. uint32_t *pui32Data, uint32_t ui32NumBytes,
  431. uint32_t ui32Options);
  432. extern am_hal_iom_status_e am_hal_iom_spi_fullduplex(uint32_t ui32Module, uint32_t ui32ChipSelect,
  433. uint32_t *pui32TxData, uint32_t *pui32RxData,
  434. uint32_t ui32NumBytes, uint32_t ui32Options);
  435. extern am_hal_iom_status_e am_hal_iom_spi_write_nq(uint32_t ui32Module, uint32_t ui32ChipSelect,
  436. uint32_t *pui32Data, uint32_t ui32NumBytes,
  437. uint32_t ui32Options);
  438. extern am_hal_iom_status_e am_hal_iom_spi_read_nq(uint32_t ui32Module, uint32_t ui32ChipSelect,
  439. uint32_t *pui32Data, uint32_t ui32NumBytes,
  440. uint32_t ui32Options);
  441. extern am_hal_iom_status_e am_hal_iom_spi_fullduplex_nq(uint32_t ui32Module, uint32_t ui32ChipSelect,
  442. uint32_t *pui32TxData, uint32_t *pui32RxData,
  443. uint32_t ui32NumBytes, uint32_t ui32Options);
  444. extern am_hal_iom_status_e am_hal_iom_spi_write_nb(uint32_t ui32Module, uint32_t ui32ChipSelect,
  445. uint32_t *pui32Data, uint32_t ui32NumBytes,
  446. uint32_t ui32Options,
  447. am_hal_iom_callback_t pfnCallback);
  448. extern am_hal_iom_status_e am_hal_iom_spi_read_nb(uint32_t ui32Module, uint32_t ui32ChipSelect,
  449. uint32_t *pui32Data, uint32_t ui32NumBytes,
  450. uint32_t ui32Options,
  451. am_hal_iom_callback_t pfnCallback);
  452. extern void am_hal_iom_spi_cmd_run(uint32_t ui32Operation,
  453. uint32_t ui32Module,
  454. uint32_t ui32ChipSelect,
  455. uint32_t ui32NumBytes,
  456. uint32_t ui32Options);
  457. extern am_hal_iom_status_e am_hal_iom_i2c_write(uint32_t ui32Module,
  458. uint32_t ui32BusAddress,
  459. uint32_t *pui32Data,
  460. uint32_t ui32NumBytes,
  461. uint32_t ui32Options);
  462. extern am_hal_iom_status_e am_hal_iom_i2c_read(uint32_t ui32Module,
  463. uint32_t ui32BusAddress,
  464. uint32_t *pui32Data,
  465. uint32_t ui32NumBytes,
  466. uint32_t ui32Options);
  467. extern am_hal_iom_status_e am_hal_iom_i2c_write_nq(uint32_t ui32Module,
  468. uint32_t ui32BusAddress,
  469. uint32_t *pui32Data,
  470. uint32_t ui32NumBytes,
  471. uint32_t ui32Options);
  472. extern am_hal_iom_status_e am_hal_iom_i2c_read_nq(uint32_t ui32Module,
  473. uint32_t ui32BusAddress,
  474. uint32_t *pui32Data,
  475. uint32_t ui32NumBytes,
  476. uint32_t ui32Options);
  477. extern am_hal_iom_status_e am_hal_iom_i2c_write_nb(uint32_t ui32Module,
  478. uint32_t ui32BusAddress,
  479. uint32_t *pui32Data,
  480. uint32_t ui32NumBytes,
  481. uint32_t ui32Options,
  482. am_hal_iom_callback_t pfnCallback);
  483. extern am_hal_iom_status_e am_hal_iom_i2c_read_nb(uint32_t ui32Module,
  484. uint32_t ui32BusAddress,
  485. uint32_t *pui32Data,
  486. uint32_t ui32NumBytes,
  487. uint32_t ui32Options,
  488. am_hal_iom_callback_t pfnCallback);
  489. extern am_hal_iom_status_e am_hal_iom_i2c_cmd_run(uint32_t ui32Operation,
  490. uint32_t ui32Module,
  491. uint32_t ui32BusAddress,
  492. uint32_t ui32NumBytes,
  493. uint32_t ui32Options);
  494. extern void am_hal_iom_command_repeat_set(uint32_t ui32Module,
  495. uint32_t ui32CmdCount);
  496. extern uint32_t am_hal_iom_status_get(uint32_t ui32Module);
  497. extern am_hal_iom_status_e am_hal_iom_error_status_get(uint32_t ui32Module);
  498. extern uint32_t am_hal_iom_fifo_write(uint32_t ui32Module, uint32_t *pui32Data,
  499. uint32_t ui32NumBytes);
  500. extern uint32_t am_hal_iom_fifo_read(uint32_t ui32Module, uint32_t *pui32Data,
  501. uint32_t ui32NumBytes);
  502. extern uint8_t am_hal_iom_fifo_empty_slots(uint32_t ui32Module);
  503. extern uint8_t am_hal_iom_fifo_full_slots(uint32_t ui32Module);
  504. extern void am_hal_iom_poll_complete(uint32_t ui32Module);
  505. extern void am_hal_iom_int_service(uint32_t ui32Module, uint32_t ui32Status);
  506. extern void am_hal_iom_int_enable(uint32_t ui32Module, uint32_t ui32Interrupt);
  507. extern uint32_t am_hal_iom_int_enable_get(uint32_t ui32Module);
  508. extern void am_hal_iom_int_disable(uint32_t ui32Module, uint32_t ui32Interrupt);
  509. extern void am_hal_iom_int_clear(uint32_t ui32Module, uint32_t ui32Interrupt);
  510. extern void am_hal_iom_int_set(uint32_t ui32Module, uint32_t ui32Interrupt);
  511. extern uint32_t am_hal_iom_int_status_get(uint32_t ui32Module, bool bEnabledOnly);
  512. extern void am_hal_iom_queue_init(uint32_t ui32ModuleNum,
  513. am_hal_iom_queue_entry_t *psQueueMemory,
  514. uint32_t ui32QueueMemSize);
  515. extern uint32_t am_hal_iom_queue_length_get(uint32_t ui32Module);
  516. extern void am_hal_iom_sleeping_queue_flush(uint32_t ui32Module);
  517. extern am_hal_iom_status_e am_hal_iom_queue_spi_write(uint32_t ui32Module, uint32_t ui32ChipSelect,
  518. uint32_t *pui32Data, uint32_t ui32NumBytes,
  519. uint32_t ui32Options,
  520. am_hal_iom_callback_t pfnCallback);
  521. extern am_hal_iom_status_e am_hal_iom_queue_spi_read(uint32_t ui32Module, uint32_t ui32ChipSelect,
  522. uint32_t *pui32Data, uint32_t ui32NumBytes,
  523. uint32_t ui32Options,
  524. am_hal_iom_callback_t pfnCallback);
  525. extern am_hal_iom_status_e am_hal_iom_queue_i2c_write(uint32_t ui32Module, uint32_t ui32BusAddress,
  526. uint32_t *pui32Data, uint32_t ui32NumBytes,
  527. uint32_t ui32Options,
  528. am_hal_iom_callback_t pfnCallback);
  529. extern am_hal_iom_status_e am_hal_iom_queue_i2c_read(uint32_t ui32Module, uint32_t ui32BusAddress,
  530. uint32_t *pui32Data, uint32_t ui32NumBytes,
  531. uint32_t ui32Options,
  532. am_hal_iom_callback_t pfnCallback);
  533. extern void am_hal_iom_queue_start_next_msg(uint32_t ui32Module);
  534. extern void am_hal_iom_queue_service(uint32_t ui32Module, uint32_t ui32Status);
  535. //*****************************************************************************
  536. //
  537. // Helper functions.
  538. //
  539. //*****************************************************************************
  540. #define AM_IOMASTER_ISR_QUEUE(x) \
  541. void am_iomaster##x##_isr(void) \
  542. { \
  543. uint32_t ui32IntStatus; \
  544. ui32IntStatus = am_hal_iom_int_status_get(x, false); \
  545. am_hal_iom_int_clear(x, ui32IntStatus); \
  546. am_hal_iom_queue_service(x, ui32IntStatus); \
  547. }
  548. #define AM_IOMASTER_ISR_NB(x) \
  549. void am_iomaster##x##_isr(void) \
  550. { \
  551. uint32_t ui32IntStatus; \
  552. ui32IntStatus = am_hal_iom_int_status_get(x, false); \
  553. am_hal_iom_int_clear(x, ui32IntStatus); \
  554. am_hal_iom_int_service(x, ui32IntStatus); \
  555. }
  556. #ifdef __cplusplus
  557. }
  558. #endif
  559. #endif // AM_HAL_IOM_H
  560. //*****************************************************************************
  561. //
  562. // End Doxygen group.
  563. //! @}
  564. //
  565. //*****************************************************************************