lpc177x_8x_debug0.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2012 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. #if defined(MCU_LPC177x_8x)
  46. #include <arch/cm3/nxp/lpc177x_8x.h>
  47. #include <arch/cm3/nxp/lpc177x_8x_clk.h>
  48. #elif defined(MCU_LPC407x_8x)
  49. #include <arch/cm3/nxp/lpc407x_8x.h>
  50. #include <arch/cm3/nxp/lpc407x_8x_clk.h>
  51. #else
  52. #warning "Unknown LPC familiy"
  53. #endif
  54. #include <arch/cm3/nxp/lpc17xx_usart.h>
  55. /*!
  56. * \addtogroup xgNutArchCm3Lpc177x_8xDebug
  57. */
  58. /*@{*/
  59. static NUTFILE *Lpc17xxDevDebugOpen(NUTDEVICE * dev, const char *name, int mode, int acc);
  60. static int Lpc17xxDevDebugClose(NUTFILE * fp);
  61. static int Lpc17xxDevDebugWrite(NUTFILE * fp, const void *buffer, int len);
  62. #ifdef NUT_DEV_DEBUG_READ
  63. static int Lpc17xxDevDebugRead(NUTFILE * fp, void *buffer, int size);
  64. static long Lpc17xxDevDebugSize(NUTFILE *fp);
  65. #endif
  66. static int Lpc17xxDevDebugIOCtl(NUTDEVICE * dev, int req, void *conf);
  67. static int Lpc17xxDevDebugInit(NUTDEVICE * dev);
  68. /*!
  69. * \name LPC17xx USART0 Device
  70. */
  71. /*@{*/
  72. static NUTFILE dbg0file;
  73. /*!
  74. * \brief Debug UART 0 device information structure.
  75. *
  76. * An application must pass a pointer to this structure to
  77. * NutRegisterDevice() before using the serial communication
  78. * driver of the LPC17xx's on-chip USART0.
  79. *
  80. * The device is named usart0.
  81. *
  82. * \showinitializer
  83. */
  84. NUTDEVICE devDebug0 = {
  85. NULL, /*!< Pointer to next device, dev_next. */
  86. {'u', 'a', 'r', 't', '0', 0, 0, 0, 0}
  87. , /*!< Unique device name, dev_name. */
  88. 0, /*!< Type of device, dev_type. */
  89. LPC_UART0_BASE, /*!< Base address, dev_base. */
  90. 0, /*!< First interrupt number, dev_irq. */
  91. NULL, /*!< Interface control block, dev_icb. */
  92. &dbg0file, /*!< Driver control block, dev_dcb. */
  93. Lpc17xxDevDebugInit, /*!< Driver initialization routine, dev_init. */
  94. Lpc17xxDevDebugIOCtl, /*!< Driver specific control function, dev_ioctl. */
  95. #ifdef NUT_DEV_DEBUG_READ
  96. Lpc17xxDevDebugRead, /*!< dev_read. */
  97. #else
  98. NULL, /*!< dev_read. */
  99. #endif
  100. Lpc17xxDevDebugWrite, /*!< dev_write. */
  101. Lpc17xxDevDebugOpen, /*!< dev_open. */
  102. Lpc17xxDevDebugClose, /*!< dev_close. */
  103. #ifdef NUT_DEV_DEBUG_READ
  104. Lpc17xxDevDebugSize, /*!< dev_size. */
  105. #else
  106. NULL, /*!< dev_size. */
  107. #endif
  108. NULL, /*!< dev_select, optional, not yet implemented */
  109. };
  110. /*@}*/
  111. /*!
  112. * \brief Debug UART0 GPIO configuartion and assignment.
  113. */
  114. #define TX_GPIO_PORT NUTGPIO_PORT0
  115. #define TX_GPIO_PIN 2
  116. #define TX_GPIO_PIN_CFG GPIO_CFG_OUTPUT | GPIO_CFG_PERIPHERAL1
  117. #define RX_GPIO_PORT NUTGPIO_PORT0
  118. #define RX_GPIO_PIN 3
  119. #define RX_GPIO_PIN_CFG GPIO_CFG_INPUT | GPIO_CFG_PERIPHERAL1
  120. /*!
  121. * \brief Debug UART0 base configuration.
  122. */
  123. #define USARTn LPC_UART0
  124. #define USARTnBase LPC_UART0_BASE
  125. /*@}*/
  126. #include "lpc17xx_debug.c"