uart_s3c4510b_dbg.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include <dev/debug.h>
  2. #include <sys/device.h>
  3. #include <sys/file.h>
  4. #include <arch/arm.h>
  5. #include <dev/s3c4510b_hw.h>
  6. static NUTFILE dbgfile;
  7. /*!
  8. * \brief Handle I/O controls for debug device.
  9. *
  10. * The debug device doesn't support any.
  11. *
  12. * \return Always -1.
  13. */
  14. static int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
  15. {
  16. return -1;
  17. }
  18. /*!
  19. * \brief Initialize debug device.
  20. *
  21. * Simply enable the device.
  22. * Baudrate divisor set to x for
  23. * 19200 Baud at 50 MHz.
  24. *
  25. * \return Always 0.
  26. */
  27. static int DebugInit(NUTDEVICE * dev)
  28. {
  29. outl(0x03, DEBUG_UARTLCON_BASE);
  30. outl(0x09, DEBUG_UARTCONT_BASE);
  31. outl(0x500, DEBUG_UARTBRD_BASE);
  32. return 0;
  33. }
  34. /*!
  35. * \brief Send a single character to debug device.
  36. *
  37. * A newline character will be automatically prepended
  38. * by a carriage return.
  39. */
  40. static void DebugPut(char ch)
  41. {
  42. if (ch == '\n')
  43. DebugPut('\r');
  44. while (!(inl(DEBUG_CHK_STAT_BASE) & 0x40));
  45. outl(ch, DEBUG_TX_BUFF_BASE);
  46. }
  47. /*!
  48. * \brief Read a single character from debug device.
  49. *
  50. * Non blocking version of DebugGet(). If I/O operation is pending
  51. * this function returns -1.
  52. */
  53. static int DebugGetNB(void)
  54. {
  55. if (inl(DEBUG_CHK_STAT_BASE) & 0x20)
  56. return (int)inl(DEBUG_RX_BUFF_BASE);
  57. return -1;
  58. }
  59. /*!
  60. * \brief Read one character from debug device.
  61. *
  62. * This function doesn't wait for a character. If I/O operation is pending,
  63. * it returns /0/-1
  64. * \return Number of characters read.
  65. */
  66. static int DebugRead(NUTFILE * fp, void *buffer, int len)
  67. {
  68. int c, l = 0;
  69. char *cp = buffer;
  70. while (l < len) {
  71. c = DebugGetNB();
  72. if (c == -1) {
  73. *cp++ = '\0';
  74. return 0;
  75. }
  76. cp[l++] = (unsigned char) c;
  77. }
  78. return l;
  79. }
  80. /*!
  81. * \brief Send characters to debug device.
  82. *
  83. * A carriage return character will be automatically appended
  84. * to any linefeed.
  85. *
  86. * \return Number of characters sent.
  87. */
  88. static int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
  89. {
  90. int c = len;
  91. CONST char *cp = buffer;
  92. while (c--)
  93. DebugPut(*cp++);
  94. return len;
  95. }
  96. /*!
  97. * \brief Open debug device.
  98. *
  99. * \return Pointer to a static NUTFILE structure.
  100. */
  101. static NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
  102. {
  103. dbgfile.nf_dev = dev;
  104. dbgfile.nf_fcb = NULL;
  105. return &dbgfile;
  106. }
  107. /*!
  108. * \brief Close debug device.
  109. *
  110. * \return Always 0.
  111. */
  112. static int DebugClose(NUTFILE * fp)
  113. {
  114. return 0;
  115. }
  116. /*!
  117. * \brief Debug device information structure.
  118. */
  119. NUTDEVICE devDebug0 = {
  120. 0, /*!< Pointer to next device. */
  121. {'u', 'a', 'r', 't', 'a', 'r', 'm', 'd', 0} /* uartarmd */
  122. , /*!< Unique device name. */
  123. 0, /*!< Type of device. */
  124. 0, /*!< Base address. */
  125. 0, /*!< First interrupt number. */
  126. 0, /*!< Interface control block. */
  127. 0, /*!< Driver control block. */
  128. DebugInit, /*!< Driver initialization routine. */
  129. DebugIOCtl, /*!< Driver specific control function. */
  130. DebugRead,
  131. DebugWrite,
  132. /* Write from program space data to device. not havard structure */
  133. DebugOpen,
  134. DebugClose,
  135. 0,
  136. 0, /*!< Select function, optional, not yet implemented */
  137. };