debug_sam3u.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  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. /*
  33. * $Log$
  34. * Revision 0.01 2009/09/20 ulrichprinz
  35. * First checkin of using DBGU as limited standard USART.
  36. *
  37. */
  38. //#define NUT_DEPRECATED
  39. #include <cfg/os.h>
  40. #include <cfg/clock.h>
  41. #include <cfg/arch.h>
  42. #include <cfg/uart.h>
  43. #include <string.h>
  44. #include <sys/atom.h>
  45. #include <sys/event.h>
  46. #include <sys/timer.h>
  47. #include <dev/irqreg.h>
  48. #include <dev/debug.h>
  49. #include <arch/cm3.h>
  50. #include <arch/arm/at91_dbgu.h>
  51. #include <dev/usartat91.h>
  52. /*
  53. * Local function prototypes.
  54. *
  55. * Commented functions are not supported by DBGU
  56. *
  57. */
  58. static uint32_t At91UsartGetSpeed(void);
  59. static int At91UsartSetSpeed(uint32_t rate);
  60. static uint8_t At91UsartGetDataBits(void);
  61. static int At91UsartSetDataBits( uint8_t bits);
  62. static uint8_t At91UsartGetParity(void);
  63. static int At91UsartSetParity(uint8_t mode);
  64. static uint8_t At91UsartGetStopBits(void);
  65. static int At91UsartSetStopBits(uint8_t bits);
  66. static uint32_t At91UsartGetStatus(void);
  67. static int At91UsartSetStatus(uint32_t flags);
  68. static uint8_t At91UsartGetClockMode(void);
  69. static int At91UsartSetClockMode(uint8_t mode);
  70. static void At91UsartTxStart(void);
  71. static void At91UsartRxStart(void);
  72. static int At91UsartInit(void);
  73. static int At91UsartDeinit(void);
  74. static uint32_t At91UsartGetFlowControl(void);
  75. static int At91UsartSetFlowControl(uint32_t flags);
  76. #define sig_DBGU sig_UART
  77. #define DBGU_BASE AT91C_BASE_DBGU
  78. #define US_ID AT91C_ID_DBGU
  79. #define PMC_PCER AT91C_PMC_PCER
  80. #define PMC_PCDR AT91C_PMC_PCDR
  81. extern IRQ_HANDLER sig_DBGU;
  82. /*!
  83. * \addtogroup xgNutArchArmAt91Us
  84. */
  85. /*@{*/
  86. /*!
  87. * \brief DBGU device control block structure.
  88. */
  89. static USARTDCB dcb_dbgu = {
  90. 0, /* dcb_modeflags */
  91. 0, /* dcb_statusflags */
  92. 0, /* dcb_rtimeout */
  93. 0, /* dcb_wtimeout */
  94. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_tx_rbf */
  95. {0, 0, 0, 0, 0, 0, 0, 0}, /* dcb_rx_rbf */
  96. 0, /* dbc_last_eol */
  97. At91UsartInit, /* dcb_init */
  98. At91UsartDeinit, /* dcb_deinit */
  99. At91UsartTxStart, /* dcb_tx_start */
  100. At91UsartRxStart, /* dcb_rx_start */
  101. At91UsartSetFlowControl, /* dcb_set_flow_control */
  102. At91UsartGetFlowControl, /* dcb_get_flow_control */
  103. At91UsartSetSpeed, /* dcb_set_speed */
  104. At91UsartGetSpeed, /* dcb_get_speed */
  105. At91UsartSetDataBits, /* dcb_set_data_bits */
  106. At91UsartGetDataBits, /* dcb_get_data_bits */
  107. At91UsartSetParity, /* dcb_set_parity */
  108. At91UsartGetParity, /* dcb_get_parity */
  109. At91UsartSetStopBits, /* dcb_set_stop_bits */
  110. At91UsartGetStopBits, /* dcb_get_stop_bits */
  111. At91UsartSetStatus, /* dcb_set_status */
  112. At91UsartGetStatus, /* dcb_get_status */
  113. At91UsartSetClockMode, /* dcb_set_clock_mode */
  114. At91UsartGetClockMode, /* dcb_get_clock_mode */
  115. };
  116. /*!
  117. * \name AT91 DBGU Device
  118. */
  119. /*@{*/
  120. /*!
  121. * \brief USART0 device information structure.
  122. *
  123. * An application must pass a pointer to this structure to
  124. * NutRegisterDevice() before using the serial communication
  125. * driver of the AT91's on-chip USART0.
  126. *
  127. * The device is named \b uart0.
  128. *
  129. * \showinitializer
  130. */
  131. NUTDEVICE devDebug = {
  132. 0, /* Pointer to next device, dev_next. */
  133. {'d', 'b', 'g', 'u', 0, 0, 0, 0, 0}, /* Unique device name, dev_name. */
  134. IFTYP_CHAR, /* Type of device, dev_type. */
  135. AT91C_BASE_DBGU, /* Base address, dev_base (not used). */
  136. 0, /* First interrupt number, dev_irq (not used). */
  137. 0, /* Interface control block, dev_icb (not used). */
  138. &dcb_dbgu, /* Driver control block, dev_dcb. */
  139. UsartInit, /* Driver initialization routine, dev_init. */
  140. UsartIOCtl, /* Driver specific control function, dev_ioctl. */
  141. UsartRead, /* Read from device, dev_read. */
  142. UsartWrite, /* Write to device, dev_write. */
  143. UsartOpen, /* Open a device or file, dev_open. */
  144. UsartClose, /* Close a device or file, dev_close. */
  145. UsartSize, /* Request file size, dev_size. */
  146. UsartSelect, /* Select function, dev_select. */
  147. };
  148. /*@}*/
  149. /*@}*/
  150. /* Modem control includes hardware handshake. */
  151. /*
  152. * Hardware driven control signals are not available
  153. * with the DBUG unit of most chips.
  154. */
  155. #undef UART_MODEM_CONTROL
  156. #undef UART_HARDWARE_HANDSHAKE
  157. #define UART_RXTX_PINS (AT91C_PA11_DRXD|AT91C_PA12_DTXD)
  158. #undef UART_HDX_PIN
  159. #undef UART_RTS_PIN
  160. #undef UART_CTS_PIN
  161. #undef UART_MODEM_PINS
  162. #define UART_RXTX_PINS_ENABLE() outr(AT91C_PIOA_PDR, UART_RXTX_PINS)
  163. #define UART_INIT_BAUDRATE 115200
  164. #define USARTn_BASE AT91C_BASE_DBGU
  165. #define US_ID AT91C_ID_DBGU
  166. #define SIG_UART sig_UART
  167. #define dcb_usart dcb_dbgu
  168. #include "usartat91.c"