mcf5_uart1.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2012 by Embedded Technologies s.r.o
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. */
  32. #include <cfg/arch.h>
  33. #include <cfg/uart.h>
  34. #include <arch/m68k.h>
  35. #include <dev/usart.h>
  36. #define BASE 1
  37. /*
  38. * Function prototypes
  39. */
  40. static uint32_t Mcf5UsartGetSpeed(void);
  41. static int Mcf5UsartSetSpeed(uint32_t rate);
  42. static uint8_t Mcf5UsartGetDataBits(void);
  43. static int Mcf5UsartSetDataBits(uint8_t bits);
  44. static uint8_t Mcf5UsartGetParity(void);
  45. static int Mcf5UsartSetParity(uint8_t mode);
  46. static uint8_t Mcf5UsartGetStopBits(void);
  47. static int Mcf5UsartSetStopBits(uint8_t bits);
  48. static uint32_t Mcf5UsartGetFlowControl(void);
  49. static int Mcf5UsartSetFlowControl(uint32_t flags);
  50. static uint32_t Mcf5UsartGetStatus(void);
  51. static int Mcf5UsartSetStatus(uint32_t flags);
  52. static void Mcf5UsartTxStart(void);
  53. static void Mcf5UsartRxStart(void);
  54. static int Mcf5UsartInit(void);
  55. static int Mcf5UsartDeinit(void);
  56. /*
  57. * \brief UART1 control structure used for write only registers.
  58. */
  59. static UARTWREGS reg_uart1;
  60. /*!
  61. * \brief UART1 device control block structure.
  62. */
  63. static USARTDCB dcb_uart1 = {
  64. 0, /* dcb_modeflags */
  65. 0, /* dcb_statusflags */
  66. 0, /* dcb_rtimeout */
  67. 0, /* dcb_wtimeout */
  68. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_tx_rbf */
  69. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_rx_rbf */
  70. 0, /* dbc_last_eol */
  71. Mcf5UsartInit, /* dcb_init */
  72. Mcf5UsartDeinit, /* dcb_deinit */
  73. Mcf5UsartTxStart, /* dcb_tx_start */
  74. Mcf5UsartRxStart, /* dcb_rx_start */
  75. Mcf5UsartSetFlowControl, /* dcb_set_flow_control */
  76. Mcf5UsartGetFlowControl, /* dcb_get_flow_control */
  77. Mcf5UsartSetSpeed, /* dcb_set_speed */
  78. Mcf5UsartGetSpeed, /* dcb_get_speed */
  79. Mcf5UsartSetDataBits, /* dcb_set_data_bits */
  80. Mcf5UsartGetDataBits, /* dcb_get_data_bits */
  81. Mcf5UsartSetParity, /* dcb_set_parity */
  82. Mcf5UsartGetParity, /* dcb_get_parity */
  83. Mcf5UsartSetStopBits, /* dcb_set_stop_bits */
  84. Mcf5UsartGetStopBits, /* dcb_get_stop_bits */
  85. Mcf5UsartSetStatus, /* dcb_set_status */
  86. Mcf5UsartGetStatus, /* dcb_get_status */
  87. 0, /* dcb_set_clock_mode */
  88. 0, /* dcb_get_clock_mode */
  89. };
  90. /*!
  91. * \name Coldfire UART1 Device
  92. */
  93. /*@{*/
  94. /*!
  95. * \brief Coldfire device information structure.
  96. *
  97. * An application must pass a pointer to this structure to
  98. * NutRegisterDevice() before using the serial communication
  99. * driver of the Coldfire's on-chip UART1.
  100. *
  101. * The device is named \b uart1.
  102. *
  103. * \showinitializer
  104. */
  105. NUTDEVICE devUartMcf5_1 = {
  106. 0, /* Pointer to next device, dev_next. */
  107. {'u', 'a', 'r', 't', '1', 0, 0, 0, 0}, /* Unique device name, dev_name. */
  108. IFTYP_CHAR, /* Type of device, dev_type. */
  109. BASE, /* Base address, dev_base. */
  110. 0, /* First interrupt number, dev_irq (not used). */
  111. 0, /* Interface control block, dev_icb (not used). */
  112. &dcb_uart1, /* Driver control block, dev_dcb. */
  113. UsartInit, /* Driver initialization routine, dev_init. */
  114. UsartIOCtl, /* Driver specific control function, dev_ioctl. */
  115. UsartRead, /* Read from device, dev_read. */
  116. UsartWrite, /* Write to device, dev_write. */
  117. UsartOpen, /* Open a device or file, dev_open. */
  118. UsartClose, /* Close a device or file, dev_close. */
  119. UsartSize, /* Request file size, dev_size. */
  120. UsartSelect, /* Select function, dev_select */
  121. };
  122. /*@}*/
  123. /*
  124. * Peripheral GPIO Configuration
  125. */
  126. #define TXD_PORT UART1_TXD_PORT
  127. #define TXD_PIN UART1_TXD_PIN
  128. #define TXD_PERIPHERAL UART1_TXD_PERIPHERAL
  129. #define RXD_PORT UART1_RXD_PORT
  130. #define RXD_PIN UART1_RXD_PIN
  131. #define RXD_PERIPHERAL UART1_RXD_PERIPHERAL
  132. #ifdef UART1_RTS_PIN
  133. #define RTS_PORT UART1_RTS_PORT
  134. #define RTS_PIN UART1_RTS_PIN
  135. #define RTS_PERIPHERAL UART1_RTS_PERIPHERAL
  136. #endif
  137. #ifdef UART1_CTS_PIN
  138. #define CTS_PORT UART1_CTS_PORT
  139. #define CTS_PIN UART1_CTS_PIN
  140. #define CTS_PERIPHERAL UART1_CTS_PERIPHERAL
  141. #endif
  142. /*
  143. * Half/Full Duplex Configuration
  144. */
  145. #ifdef UART1_HARDWARE_HDX
  146. #define HDX_ENABLED
  147. #endif
  148. /*
  149. * Software Flow Control
  150. */
  151. #ifdef UART1_XONXOFF
  152. #define XONXOFF
  153. #endif
  154. /*
  155. * Half Duplex Control
  156. */
  157. #ifdef UART1_HDX_CTRL
  158. #define HDX_CTRL
  159. #define HDX_CTRL_BOARD_SPEC UART1_HDX_CTRL_BOARD_SPEC
  160. #ifdef UART1_HDX_CTRL_INV
  161. #define HDX_CTRL_INV
  162. #endif
  163. #if (defined UART1_HDX_CTRL_PIN) || (defined UART1_HDX_CTRL_PORT)
  164. #define HDX_CTRL_PORT UART1_HDX_CTRL_PORT
  165. #define HDX_CTRL_PIN UART1_HDX_CTRL_PIN
  166. #endif
  167. #endif
  168. /*
  169. * RS485 DE/RE Control
  170. */
  171. #ifdef UART1_RS485_CTRL
  172. #define RS485_CTRL
  173. #define RS485_CTRL_BOARD_SPEC UART1_RS485_CTRL_BOARD_SPEC
  174. #ifdef UART1_RS485_CTRL_DE_INV
  175. #define RS485_CTRL_DE_INV
  176. #endif
  177. #if (defined UART1_RS485_CTRL_DE_PIN) || (defined UART1_RS485_CTRL_DE_PORT)
  178. #define RS485_CTRL_DE_PORT UART1_RS485_CTRL_DE_PORT
  179. #define RS485_CTRL_DE_PIN UART1_RS485_CTRL_DE_PIN
  180. #endif
  181. #ifdef UART1_RS485_CTRL_RE_INV
  182. #define RS485_CTRL_RE_INV
  183. #endif
  184. #if (defined UART1_RS485_CTRL_RE_PIN) || (defined UART1_RS485_CTRL_RE_PORT)
  185. #define RS485_CTRL_RE_PORT UART1_RS485_CTRL_RE_PORT
  186. #define RS485_CTRL_RE_PIN UART1_RS485_CTRL_RE_PIN
  187. #endif
  188. #endif
  189. /*
  190. * Global Variables
  191. */
  192. #define sig_uart sig_UART1
  193. #define dcb_uart dcb_uart1
  194. #define reg_uart reg_uart1
  195. #include "mcf5_uart.c"