IxUART.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /**
  2. * @file IxUART.h
  3. *
  4. * @date 12-OCT-01
  5. *
  6. * @brief Public header for the Intel IXP400 internal UART, generic driver.
  7. *
  8. * Design Notes:
  9. * This driver allows you to perform the following functions:
  10. * Device Initialization,
  11. * send/receive characters.
  12. *
  13. * Perform Uart IOCTL for the following:
  14. * Set/Get the current baud rate,
  15. * set parity,
  16. * set the number of Stop bits,
  17. * set the character Length (5,6,7,8),
  18. * enable/disable Hardware flow control.
  19. *
  20. * Only Polled mode is supported for now.
  21. *
  22. *
  23. * @par
  24. * IXP400 SW Release version 2.0
  25. *
  26. * -- Copyright Notice --
  27. *
  28. * @par
  29. * Copyright 2001-2005, Intel Corporation.
  30. * All rights reserved.
  31. *
  32. * @par
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions
  35. * are met:
  36. * 1. Redistributions of source code must retain the above copyright
  37. * notice, this list of conditions and the following disclaimer.
  38. * 2. Redistributions in binary form must reproduce the above copyright
  39. * notice, this list of conditions and the following disclaimer in the
  40. * documentation and/or other materials provided with the distribution.
  41. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  42. * may be used to endorse or promote products derived from this software
  43. * without specific prior written permission.
  44. *
  45. * @par
  46. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  47. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  49. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  50. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  51. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  52. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  56. * SUCH DAMAGE.
  57. *
  58. * @par
  59. * -- End of Copyright Notice --
  60. */
  61. /**
  62. * @defgroup IxUARTAccAPI IXP400 UART Access (IxUARTAcc) API
  63. *
  64. * @brief IXP400 UARTAcc Driver Public API
  65. *
  66. * @{
  67. */
  68. /* Defaults */
  69. /**
  70. * @defgroup DefaultDefines Defines for Default Values
  71. *
  72. * @brief Default values which can be used for UART configuration
  73. *
  74. * @sa ixUARTDev
  75. */
  76. /**
  77. * @def IX_UART_DEF_OPTS
  78. *
  79. * @brief The default hardware options to set the UART to -
  80. * no flow control, 8 bit word, 1 stop bit, no parity
  81. *
  82. * @ingroup DefaultDefines
  83. */
  84. #define IX_UART_DEF_OPTS (CLOCAL | CS8)
  85. /**
  86. * @def IX_UART_DEF_XMIT
  87. *
  88. * @brief The default UART FIFO size - must be no bigger than 64
  89. *
  90. * @ingroup DefaultDefines
  91. */
  92. #define IX_UART_DEF_XMIT 64
  93. /**
  94. * @def IX_UART_DEF_BAUD
  95. *
  96. * @brief The default UART baud rate - 9600
  97. *
  98. * @ingroup DefaultDefines
  99. */
  100. #define IX_UART_DEF_BAUD 9600
  101. /**
  102. * @def IX_UART_MIN_BAUD
  103. *
  104. * @brief The minimum UART baud rate - 9600
  105. *
  106. * @ingroup DefaultDefines
  107. */
  108. #define IX_UART_MIN_BAUD 9600
  109. /**
  110. * @def IX_UART_MAX_BAUD
  111. *
  112. * @brief The maximum UART baud rate - 926100
  113. *
  114. * @ingroup DefaultDefines
  115. */
  116. #define IX_UART_MAX_BAUD 926100
  117. /**
  118. * @def IX_UART_XTAL
  119. *
  120. * @brief The UART clock speed
  121. *
  122. * @ingroup DefaultDefines
  123. */
  124. #define IX_UART_XTAL 14745600
  125. /* IOCTL commands (Request codes) */
  126. /**
  127. * @defgroup IoctlCommandDefines Defines for IOCTL Commands
  128. *
  129. * @brief IOCTL Commands (Request codes) which can be used
  130. * with @ref ixUARTIoctl
  131. */
  132. /**
  133. * @ingroup IoctlCommandDefines
  134. *
  135. * @def IX_BAUD_SET
  136. *
  137. * @brief Set the baud rate
  138. */
  139. #define IX_BAUD_SET 0
  140. /**
  141. * @ingroup IoctlCommandDefines
  142. *
  143. * @def IX_BAUD_GET
  144. *
  145. * @brief Get the baud rate
  146. */
  147. #define IX_BAUD_GET 1
  148. /**
  149. * @ingroup IoctlCommandDefines
  150. * @def IX_MODE_SET
  151. * @brief Set the UART mode of operation
  152. */
  153. #define IX_MODE_SET 2
  154. /**
  155. * @ingroup IoctlCommandDefines
  156. *
  157. * @def IX_MODE_GET
  158. *
  159. * @brief Get the current UART mode of operation
  160. */
  161. #define IX_MODE_GET 3
  162. /**
  163. * @ingroup IoctlCommandDefines
  164. *
  165. * @def IX_OPTS_SET
  166. *
  167. * @brief Set the UART device options
  168. */
  169. #define IX_OPTS_SET 4
  170. /**
  171. * @ingroup IoctlCommandDefines
  172. *
  173. * @def IX_OPTS_GET
  174. *
  175. * @brief Get the UART device options
  176. */
  177. #define IX_OPTS_GET 5
  178. /**
  179. * @ingroup IoctlCommandDefines
  180. *
  181. * @def IX_STATS_GET
  182. *
  183. * @brief Get the UART statistics
  184. */
  185. #define IX_STATS_GET 6
  186. /* POSIX style ioctl arguments */
  187. /**
  188. * @defgroup IoctlArgDefines Defines for IOCTL Arguments
  189. *
  190. * @brief POSIX style IOCTL arguments which can be used
  191. * with @ref ixUARTIoctl
  192. *
  193. * @sa ixUARTMode
  194. */
  195. /**
  196. * @ingroup IoctlArgDefines
  197. *
  198. * @def CLOCAL
  199. *
  200. * @brief Software flow control
  201. */
  202. #ifdef CLOCAL
  203. #undef CLOCAL
  204. #endif
  205. #define CLOCAL 0x1
  206. /**
  207. * @ingroup IoctlArgDefines
  208. *
  209. * @def CREAD
  210. *
  211. * @brief Enable interrupt receiver
  212. */
  213. #ifdef CREAD
  214. #undef CREAD
  215. #endif
  216. #define CREAD 0x2
  217. /**
  218. * @ingroup IoctlArgDefines
  219. *
  220. * @def CSIZE
  221. *
  222. * @brief Characters size
  223. */
  224. #ifdef CSIZE
  225. #undef CSIZE
  226. #endif
  227. #define CSIZE 0xc
  228. /**
  229. * @ingroup IoctlArgDefines
  230. *
  231. * @def CS5
  232. *
  233. * @brief 5 bits
  234. */
  235. #ifdef CS5
  236. #undef CS5
  237. #endif
  238. #define CS5 0x0
  239. /**
  240. * @ingroup IoctlArgDefines
  241. *
  242. * @def CS6
  243. *
  244. * @brief 6 bits
  245. */
  246. #ifdef CS6
  247. #undef CS6
  248. #endif
  249. #define CS6 0x4
  250. /**
  251. * @ingroup IoctlArgDefines
  252. *
  253. * @def CS7
  254. *
  255. * @brief 7 bits
  256. */
  257. #ifdef CS7
  258. #undef CS7
  259. #endif
  260. #define CS7 0x8
  261. /**
  262. * @ingroup IoctlArgDefines
  263. *
  264. * @def CS8
  265. *
  266. * @brief 8 bits
  267. */
  268. #ifdef CS8
  269. #undef CS8
  270. #endif
  271. #define CS8 0xc
  272. /**
  273. * @ingroup IoctlArgDefines
  274. *
  275. * @def STOPB
  276. *
  277. * @brief Send two stop bits (else one)
  278. */
  279. #define STOPB 0x20
  280. /**
  281. * @ingroup IoctlArgDefines
  282. *
  283. * @def PARENB
  284. *
  285. * @brief Parity detection enabled (else disabled)
  286. */
  287. #ifdef PARENB
  288. #undef PARENB
  289. #endif
  290. #define PARENB 0x40
  291. /**
  292. * @ingroup IoctlArgDefines
  293. *
  294. * @def PARODD
  295. *
  296. * @brief Odd parity (else even)
  297. */
  298. #ifdef PARODD
  299. #undef PARODD
  300. #endif
  301. #define PARODD 0x80
  302. /**
  303. * @enum ixUARTMode
  304. * @brief The mode to set to UART to.
  305. */
  306. typedef enum
  307. {
  308. INTERRUPT=0, /**< Interrupt mode */
  309. POLLED, /**< Polled mode */
  310. LOOPBACK /**< Loopback mode */
  311. } ixUARTMode;
  312. /**
  313. * @struct ixUARTStats
  314. * @brief Statistics for the UART.
  315. */
  316. typedef struct
  317. {
  318. UINT32 rxCount;
  319. UINT32 txCount;
  320. UINT32 overrunErr;
  321. UINT32 parityErr;
  322. UINT32 framingErr;
  323. UINT32 breakErr;
  324. } ixUARTStats;
  325. /**
  326. * @struct ixUARTDev
  327. * @brief Device descriptor for the UART.
  328. */
  329. typedef struct
  330. {
  331. UINT8 *addr; /**< device base address */
  332. ixUARTMode mode; /**< interrupt, polled or loopback */
  333. int baudRate; /**< baud rate */
  334. int freq; /**< UART clock frequency */
  335. int options; /**< hardware options */
  336. int fifoSize; /**< FIFO xmit size */
  337. ixUARTStats stats; /**< device statistics */
  338. } ixUARTDev;
  339. /**
  340. * @ingroup IxUARTAccAPI
  341. *
  342. * @fn IX_STATUS ixUARTInit(ixUARTDev* pUART)
  343. *
  344. * @param pUART @ref ixUARTDev [in] - pointer to UART structure describing our device.
  345. *
  346. * @brief Initialise the UART. This puts the chip in a quiescent state.
  347. *
  348. * @pre The base address for the UART must contain a valid value.
  349. * Also the baud rate and hardware options must contain sensible values
  350. * otherwise the defaults will be used as defined in ixUART.h
  351. *
  352. * @post UART is initialized and ready to send and receive data.
  353. *
  354. * @note This function should only be called once per device.
  355. *
  356. * @retval IX_SUCCESS - UART device successfully initialised.
  357. * @retval IX_FAIL - Critical error, device not initialised.
  358. ***************************************************************************/
  359. PUBLIC IX_STATUS ixUARTInit(ixUARTDev* pUART);
  360. /**
  361. * @ingroup IxUARTAccAPI
  362. *
  363. * @fn IX_STATUS ixUARTPollOutput(ixUARTDev* pUART, int outChar)
  364. *
  365. * @param pUART @ref ixUARTDev [out] - pointer to UART structure describing our device.
  366. * @param outChar int [out] - character to transmit.
  367. *
  368. * @brief Transmit a character in polled mode.
  369. *
  370. * @pre UART device must be initialised.
  371. *
  372. * @retval IX_SUCCESS - character was successfully transmitted.
  373. * @retval IX_FAIL - output buffer is full (try again).
  374. ***************************************************************************/
  375. PUBLIC IX_STATUS ixUARTPollOutput(ixUARTDev* pUART, int outChar);
  376. /**
  377. * @ingroup IxUARTAccAPI
  378. *
  379. * @fn IX_STATUS ixUARTPollInput(ixUARTDev* pUART, char *inChar)
  380. *
  381. * @param pUART @ref ixUARTDev [in] - pointer to UART structure describing our device.
  382. * @param *inChar char [in] - character read from the device.
  383. *
  384. * @brief Receive a character in polled mode.
  385. *
  386. * @pre UART device must be initialised.
  387. *
  388. * @retval IX_SUCCESS - character was successfully read.
  389. * @retval IX_FAIL - input buffer empty (try again).
  390. ***************************************************************************/
  391. PUBLIC IX_STATUS ixUARTPollInput(ixUARTDev* pUART, char *inChar);
  392. /**
  393. * @ingroup IxUARTAccAPI
  394. *
  395. * @fn IX_STATUS ixUARTIoctl(ixUARTDev* pUART, int cmd, void* arg)
  396. *
  397. * @param pUART @ref ixUARTDev [in] - pointer to UART structure describing our device.
  398. * @param cmd int [in] - an ioctl request code.
  399. * @param arg void* [in] - optional argument used to set the device mode,
  400. * baud rate, and hardware options.
  401. *
  402. * @brief Perform I/O control routines on the device.
  403. *
  404. * @retval IX_SUCCESS - requested feature was set/read successfully.
  405. * @retval IX_FAIL - error setting/reading the requested feature.
  406. *
  407. * @sa IoctlCommandDefines
  408. * @sa IoctlArgDefines
  409. ***************************************************************************/
  410. PUBLIC IX_STATUS ixUARTIoctl(ixUARTDev* pUART, int cmd, void* arg);
  411. /**
  412. * @} defgroup IxUARTAcc
  413. */