usart3sc16is752.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright (C) 2010 by Ulrich Prinz (uprinz2@netscape.net)
  3. * Copyright (C) 2009 by Rittal GmbH & Co. KG. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. */
  34. /*
  35. * $Log$
  36. *
  37. * Revision 1.0 2009/04/13 ulrichprinz
  38. * First checkin, new twi driver for SC16IS752 dual usart chip
  39. * (currently SAM7X256 is tested only)
  40. *
  41. */
  42. #include <cfg/os.h>
  43. #include <cfg/clock.h>
  44. #include <cfg/arch.h>
  45. #include <cfg/uart.h>
  46. //#include <string.h>
  47. #include <sys/atom.h>
  48. #include <sys/event.h>
  49. #include <sys/timer.h>
  50. #include <dev/irqreg.h>
  51. #include <dev/usartsc16is752.h>
  52. #define SCDEV 1
  53. #define CH_ 1
  54. #define NUTDEV_ devUsartsc16is752d
  55. #if defined(__linux__)
  56. #define IRQ_ 1
  57. #else
  58. extern IRQ_HANDLER sig_INTERRUPT0;
  59. #define IRQ_ sig_INTERRUPT0
  60. #endif
  61. // static void Sc16is752UsartEnable_(void)
  62. // {
  63. // Sc16is752UsartEnable(SCDEV, CH_);
  64. // }
  65. //
  66. // static void Sc16is752UsartDisable_(void)
  67. // {
  68. // Sc16is752UsartDisable(SCDEV, CH_);
  69. // }
  70. NUTDEVICE devUsartsc16is752d;
  71. static uint32_t Sc16is752UsartGetSpeed_(void)
  72. {
  73. return Sc16is752UsartGetSpeed(SCDEV, CH_);
  74. }
  75. static int Sc16is752UsartSetSpeed_(uint32_t rate)
  76. {
  77. return Sc16is752UsartSetSpeed(rate, SCDEV, CH_);
  78. }
  79. static uint8_t Sc16is752UsartGetDataBits_(void)
  80. {
  81. return Sc16is752UsartGetDataBits(SCDEV, CH_);
  82. }
  83. static int Sc16is752UsartSetDataBits_(uint8_t bits)
  84. {
  85. return Sc16is752UsartSetDataBits(bits, SCDEV, CH_);
  86. }
  87. static uint8_t Sc16is752UsartGetParity_(void)
  88. {
  89. return Sc16is752UsartGetParity(SCDEV, CH_);
  90. }
  91. static int Sc16is752UsartSetParity_(uint8_t mode)
  92. {
  93. return Sc16is752UsartSetParity(mode, SCDEV, CH_);
  94. }
  95. static uint8_t Sc16is752UsartGetStopBits_(void)
  96. {
  97. return Sc16is752UsartGetStopBits(SCDEV, CH_);
  98. }
  99. static int Sc16is752UsartSetStopBits_(uint8_t bits)
  100. {
  101. return Sc16is752UsartSetStopBits(bits, SCDEV, CH_);
  102. }
  103. static uint32_t Sc16is752UsartGetStatus_(void)
  104. {
  105. return Sc16is752UsartGetStatus(SCDEV, CH_);
  106. }
  107. static int Sc16is752UsartSetStatus_(uint32_t flags)
  108. {
  109. return Sc16is752UsartSetStatus(flags, SCDEV, CH_);
  110. }
  111. static uint8_t Sc16is752UsartGetClockMode_(void)
  112. {
  113. return Sc16is752UsartGetClockMode(SCDEV, CH_);
  114. }
  115. static int Sc16is752UsartSetClockMode_(uint8_t mode)
  116. {
  117. return Sc16is752UsartSetClockMode(mode, SCDEV, CH_);
  118. }
  119. static uint32_t Sc16is752UsartGetFlowControl_(void)
  120. {
  121. return Sc16is752UsartGetFlowControl(SCDEV, CH_);
  122. }
  123. static int Sc16is752UsartSetFlowControl_(uint32_t flags)
  124. {
  125. return Sc16is752UsartSetFlowControl(flags, SCDEV, CH_);
  126. }
  127. static void Sc16is752UsartTxStart_(void)
  128. {
  129. Sc16is752UsartTxStart(SCDEV, CH_);
  130. }
  131. static void Sc16is752UsartRxStart_(void)
  132. {
  133. Sc16is752UsartRxStart(SCDEV, CH_);
  134. }
  135. static int Sc16is752UsartInit_(void)
  136. {
  137. #if defined(__linux__)
  138. return Sc16is752UsartInit(SCDEV, CH_, &NUTDEV_, 1);
  139. #else
  140. return Sc16is752UsartInit(SCDEV, CH_, &NUTDEV_, &IRQ_);
  141. #endif
  142. }
  143. static int Sc16is752UsartDeinit_(void)
  144. {
  145. #if defined(__linux__)
  146. return Sc16is752UsartDeinit(SCDEV, CH_, 1);
  147. #else
  148. return Sc16is752UsartDeinit(SCDEV, CH_, &IRQ_);
  149. #endif
  150. }
  151. /*!
  152. * \addtogroup xgNutArchArmAt91Us
  153. */
  154. /*@{*/
  155. /*!
  156. * \brief USART3 device control block structure.
  157. */
  158. static USARTDCB dcb_usartd = {
  159. 0, /* dcb_modeflags */
  160. 0, /* dcb_statusflags */
  161. 0, /* dcb_rtimeout */
  162. 0, /* dcb_wtimeout */
  163. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_tx_rbf */
  164. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_rx_rbf */
  165. 0, /* dbc_last_eol */
  166. Sc16is752UsartInit_, /* dcb_init */
  167. Sc16is752UsartDeinit_, /* dcb_deinit */
  168. Sc16is752UsartTxStart_, /* dcb_tx_start */
  169. Sc16is752UsartRxStart_, /* dcb_rx_start */
  170. Sc16is752UsartSetFlowControl_, /* dcb_set_flow_control */
  171. Sc16is752UsartGetFlowControl_, /* dcb_get_flow_control */
  172. Sc16is752UsartSetSpeed_, /* dcb_set_speed */
  173. Sc16is752UsartGetSpeed_, /* dcb_get_speed */
  174. Sc16is752UsartSetDataBits_, /* dcb_set_data_bits */
  175. Sc16is752UsartGetDataBits_, /* dcb_get_data_bits */
  176. Sc16is752UsartSetParity_, /* dcb_set_parity */
  177. Sc16is752UsartGetParity_, /* dcb_get_parity */
  178. Sc16is752UsartSetStopBits_, /* dcb_set_stop_bits */
  179. Sc16is752UsartGetStopBits_, /* dcb_get_stop_bits */
  180. Sc16is752UsartSetStatus_, /* dcb_set_status */
  181. Sc16is752UsartGetStatus_, /* dcb_get_status */
  182. Sc16is752UsartSetClockMode_, /* dcb_set_clock_mode */
  183. Sc16is752UsartGetClockMode_, /* dcb_get_clock_mode */
  184. };
  185. /*!
  186. * \name SC16IS752 USARTd Device
  187. */
  188. /*@{*/
  189. /*!
  190. * \brief USART3 device information structure.
  191. *
  192. * An application must pass a pointer to this structure to
  193. * NutRegisterDevice() before using the serial communication
  194. * driver of the AT91's on-chip USART3.
  195. *
  196. * The device is named \b uartd.
  197. *
  198. * \showinitializer
  199. */
  200. NUTDEVICE devUsartsc16is752d = {
  201. 0, /* Pointer to next device, dev_next. */
  202. {'u', 'a', 'r', 't', '_', 'd', 0, 0, 0}, /* Unique device name, dev_name. */
  203. IFTYP_CHAR, /* Type of device, dev_type. */
  204. (SCDEV<<8)|CH_, /* Base address, used for dev & ch: (dev<<8)|ch */
  205. 0, /* First interrupt number, dev_irq (not used). */
  206. 0, /* Interface control block, dev_icb (not used). */
  207. &dcb_usartd, /* Driver control block, dev_dcb. */
  208. UsartInit, /* Driver initialization routine, dev_init. */
  209. UsartIOCtl, /* Driver specific control function, dev_ioctl. */
  210. UsartRead, /* Read from device, dev_read. */
  211. UsartWrite, /* Write to device, dev_write. */
  212. #ifdef __HARVARD_ARCH__
  213. UsartWrite_P, /* Write program memory to device, dev_write_P. */
  214. #endif
  215. UsartOpen, /* Open a device or file, dev_open. */
  216. UsartClose, /* Close a device or file, dev_close. */
  217. UsartSize, /* Request file size, dev_size. */
  218. UsartSelect, /* Select function, dev_select. */
  219. };
  220. /*@}*/
  221. /*@}*/