lpc176x_debug3.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2013 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * \verbatim
  36. * $Id: $
  37. * \endverbatim
  38. */
  39. #include <cfg/arch.h>
  40. #include <cfg/uart.h>
  41. #include <dev/debug.h>
  42. #include <sys/timer.h>
  43. #include <sys/file.h>
  44. #include <sys/device.h>
  45. #include <arch/cm3/nxp/lpc176x.h>
  46. #include <arch/cm3/nxp/lpc176x_clk.h>
  47. #include <arch/cm3/nxp/lpc17xx_usart.h>
  48. /*!
  49. * \addtogroup xgNutArchCm3Lpc177x_8xDebug
  50. */
  51. /*@{*/
  52. static NUTFILE *Lpc17xxDevDebugOpen(NUTDEVICE * dev, const char *name, int mode, int acc);
  53. static int Lpc17xxDevDebugClose(NUTFILE * fp);
  54. static int Lpc17xxDevDebugWrite(NUTFILE * fp, const void *buffer, int len);
  55. #ifdef NUT_DEV_DEBUG_READ
  56. static int Lpc17xxDevDebugRead(NUTFILE * fp, void *buffer, int size);
  57. static long Lpc17xxDevDebugSize(NUTFILE *fp);
  58. #endif
  59. static int Lpc17xxDevDebugIOCtl(NUTDEVICE * dev, int req, void *conf);
  60. static int Lpc17xxDevDebugInit(NUTDEVICE * dev);
  61. /*!
  62. * \name LPC17xx USART3 Device
  63. */
  64. /*@{*/
  65. static NUTFILE dbg3file;
  66. /*!
  67. * \brief Debug UART 3 device information structure.
  68. *
  69. * An application must pass a pointer to this structure to
  70. * NutRegisterDevice() before using the serial communication
  71. * driver of the LPC17xx's on-chip USART3.
  72. *
  73. * The device is named usart3.
  74. *
  75. * \showinitializer
  76. */
  77. NUTDEVICE devDebug3 = {
  78. NULL, /*!< Pointer to next device, dev_next. */
  79. {'u', 'a', 'r', 't', '3', 0, 0, 0, 0}
  80. , /*!< Unique device name, dev_name. */
  81. 0, /*!< Type of device, dev_type. */
  82. LPC_UART3_BASE, /*!< Base address, dev_base. */
  83. 0, /*!< First interrupt number, dev_irq. */
  84. NULL, /*!< Interface control block, dev_icb. */
  85. &dbg3file, /*!< Driver control block, dev_dcb. */
  86. Lpc17xxDevDebugInit, /*!< Driver initialization routine, dev_init. */
  87. Lpc17xxDevDebugIOCtl, /*!< Driver specific control function, dev_ioctl. */
  88. #ifdef NUT_DEV_DEBUG_READ
  89. Lpc17xxDevDebugRead, /*!< dev_read. */
  90. #else
  91. NULL, /*!< dev_read. */
  92. #endif
  93. Lpc17xxDevDebugWrite, /*!< dev_write. */
  94. Lpc17xxDevDebugOpen, /*!< dev_open. */
  95. Lpc17xxDevDebugClose, /*!< dev_close. */
  96. #ifdef NUT_DEV_DEBUG_READ
  97. Lpc17xxDevDebugSize, /*!< dev_size. */
  98. #else
  99. NULL, /*!< dev_size. */
  100. #endif
  101. NULL, /*!< dev_select, optional, not yet implemented */
  102. };
  103. /*@}*/
  104. /*!
  105. * \brief Debug UART0 GPIO configuartion and assignment.
  106. */
  107. #define TX_GPIO_PORT NUTGPIO_PORT0
  108. #define TX_GPIO_PIN 0
  109. #define TX_GPIO_PIN_CFG GPIO_CFG_OUTPUT | GPIO_CFG_PERIPHERAL2
  110. #define RX_GPIO_PORT NUTGPIO_PORT0
  111. #define RX_GPIO_PIN 1
  112. #define RX_GPIO_PIN_CFG GPIO_CFG_INPUT | GPIO_CFG_PERIPHERAL2
  113. /* Alternatively:
  114. #define TX_GPIO_PORT NUTGPIO_PORT0
  115. #define TX_GPIO_PIN 25
  116. #define TX_GPIO_PIN_CFG GPIO_CFG_OUTPUT | GPIO_CFG_PERIPHERAL3
  117. #define RX_GPIO_PORT NUTGPIO_PORT0
  118. #define RX_GPIO_PIN 26
  119. #define RX_GPIO_PIN_CFG GPIO_CFG_INPUT | GPIO_CFG_PERIPHERAL3
  120. or:
  121. #define TX_GPIO_PORT NUTGPIO_PORT4
  122. #define TX_GPIO_PIN 28
  123. #define TX_GPIO_PIN_CFG GPIO_CFG_OUTPUT | GPIO_CFG_PERIPHERAL3
  124. #define RX_GPIO_PORT NUTGPIO_PORT4
  125. #define RX_GPIO_PIN 29
  126. #define RX_GPIO_PIN_CFG GPIO_CFG_INPUT | GPIO_CFG_PERIPHERAL3
  127. */
  128. /*!
  129. * \brief Debug UART0 base configuration.
  130. */
  131. #define USARTn LPC_UART3
  132. #define USARTnBase LPC_UART3_BASE
  133. /*@}*/
  134. #include "lpc17xx_debug.c"