imx_uart.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2010-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*!
  31. * @file imx_uart.h
  32. * @brief various defines used by imx_uart.c
  33. */
  34. #ifndef __IMX_UART_H__
  35. #define __IMX_UART_H__
  36. #include "sdk.h"
  37. //! @addtogroup diag_uart
  38. //! @{
  39. //////////////////////////////////////////////////////////////////////////
  40. //Constants
  41. /////////////////////////////////////////////////////////////////////////
  42. /* UART specific defines */
  43. //! @brief Modes of the PARITY for UART transfer.
  44. enum _uart_parity
  45. {
  46. PARITY_NONE = 0, //!< PARITY mode is PARITY_NONE.
  47. PARITY_EVEN = 2, //!< PARITY mode is PARITY_EVEN.
  48. PARITY_ODD = 3 //!< PARITY mode is PARITY_ODD.
  49. };
  50. //! @brief Number of stopbits after a character.
  51. enum _uart_stopbits
  52. {
  53. STOPBITS_ONE = 0, //!< One stopbits after a character.
  54. STOPBITS_TWO = 1 //!< Two stopbits after a character.
  55. };
  56. //! @brief Flow control mode for UART transfer.
  57. enum _uart_flowctrl
  58. {
  59. FLOWCTRL_OFF = 0, //!< Flow control off for UART transfer.
  60. FLOWCTRL_ON = 1 //!< Flow control on for UART transfer.
  61. };
  62. //! @brief Specify the FIFO for UART transfer.
  63. enum _uart_fifo
  64. {
  65. TX_FIFO = 0, //!< Config the TX fifo for UART transfer.
  66. RX_FIFO = 1 //!< Config the RX fifo for UART transfer.
  67. };
  68. //! @brief Specify the number of bits in a data
  69. enum _uart_bits
  70. {
  71. SEVENBITS = 0, //!< Config seven bits in a data.
  72. EIGHTBITS = 1 //!< Config eight bits in a data.
  73. };
  74. //! @brief Specify the service mode
  75. #define DMA_MODE 2 //!< Config the service mode for dma request.
  76. #define IRQ_MODE 1 //!< Config the service mode for interrupt.
  77. #define UART_MODULE_CLK(x) ((x) == HW_UART1 ? UART1_MODULE_CLK : (x) == HW_UART2 ? UART2_MODULE_CLK : (x) == HW_UART3 ? UART3_MODULE_CLK : (x) == HW_UART4 ? UART4_MODULE_CLK : -1)
  78. #define UART_IRQS(x) ((x) == HW_UART1 ? IMX_INT_UART1 : (x) == HW_UART2 ? IMX_INT_UART2 : (x) == HW_UART3 ? IMX_INT_UART3 : (x) == HW_UART4 ? IMX_INT_UART4 : (x) == HW_UART5 ? IMX_INT_UART5 : 0xFFFFFFFF)
  79. //////////////////////////////////////////////////////////////////////////
  80. //API
  81. /////////////////////////////////////////////////////////////////////////
  82. /*!
  83. * @brief Initialize the UART port
  84. *
  85. * @param instance the UART instance number.
  86. * @param baudrate serial baud rate such 9600, 57600, 115200, etc.
  87. * @param parity enable parity checking: PARITY_NONE, PARITY_EVEN,
  88. * PARITY_ODD.
  89. * @param stopbits number of stop bits: STOPBITS_ONE, STOPBITS_TWO.
  90. * @param datasize number of bits in a data: SEVENBITS, EIGHTBITS,
  91. * NINEBITS (like RS-485 but not supported).
  92. * @param flowcontrol enable (RTS/CTS) hardware flow control:
  93. * FLOWCTRL_ON, FLOWCTRL_OFF.
  94. */
  95. void uart_init(uint32_t instance, uint32_t baudrate, uint8_t parity,uint8_t stopbits, uint8_t datasize, uint8_t flowcontrol);
  96. /*!
  97. * @brief Output a character to UART port
  98. *
  99. * @param instance the UART instance number.
  100. * @param ch pointer to the character for output
  101. * @return the character that has been sent
  102. */
  103. uint8_t uart_putchar(uint32_t instance, uint8_t * ch);
  104. /*!
  105. * @brief Receive a character on the UART port
  106. *
  107. * @param instance the UART instance number.
  108. * @return a character received from the UART port; if the RX FIFO
  109. * is empty or errors are detected, it returns NONE_CHAR
  110. */
  111. uint8_t uart_getchar(uint32_t instance);
  112. /*!
  113. * @brief Configure the RX or TX FIFO level and trigger mode
  114. *
  115. * @param instance the UART instance number.
  116. * @param fifo FIFO to configure: RX_FIFO or TX_FIFO.
  117. * @param trigger_level set the trigger level of the FIFO to generate
  118. * an IRQ or a DMA request: number of characters.
  119. * @param service_mode FIFO served with DMA or IRQ or polling (default).
  120. */
  121. void uart_set_FIFO_mode(uint32_t instance, uint8_t fifo, uint8_t trigger_level,
  122. uint8_t service_mode);
  123. /*!
  124. * @brief Enables UART loopback test mode
  125. *
  126. * @param instance the UART instance number.
  127. * @param state enable/disable the loopback mode
  128. */
  129. void uart_set_loopback_mode(uint32_t instance, uint8_t state);
  130. /*!
  131. * @brief Setup UART interrupt. It enables or disables the related HW module
  132. * interrupt, and attached the related sub-routine into the vector table.
  133. *
  134. * @param instance the UART instance number.
  135. * @param irq_subroutine the UART interrupt interrupt routine.
  136. * @param state ENABLE or DISABLE the interrupt.
  137. */
  138. void uart_setup_interrupt(uint32_t instance, void (*irq_subroutine)(void), uint8_t state);
  139. /*!
  140. * @brief Obtain UART reference frequency
  141. *
  142. * @param instance the UART instance number.
  143. * @return reference frequency in Hz
  144. */
  145. uint32_t uart_get_reffreq(uint32_t instance);
  146. //! @name Board support functions
  147. //!
  148. //! These functions are called by the driver in order to factor out board
  149. //! specific functionality. They must be defined by the board support
  150. //! library or the application.
  151. //@{
  152. //! @brief Configure IOMUX for the UART driver.
  153. void uart_iomux_config(int instance);
  154. //@}
  155. //! @}
  156. #endif //__IMX_UART_H__