uartConsole.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * \file uartConsole.c
  3. *
  4. * \brief This file contains functions which interface interactively
  5. * with the user through the serial console to perform some
  6. * utility operations.
  7. */
  8. /*
  9. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the
  21. * distribution.
  22. *
  23. * Neither the name of Texas Instruments Incorporated nor the names of
  24. * its contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. /* HW Macros */
  40. #include "hw_types.h"
  41. /* System Defines */
  42. #include "evmC6748.h"
  43. #include "soc_C6748.h"
  44. #include "hw_syscfg0_C6748.h"
  45. /* Driver APIs */
  46. #include "uart.h"
  47. #include "psc.h"
  48. /******************************************************************************
  49. ** INTERNAL MACRO DEFINITIONS
  50. ******************************************************************************/
  51. #define UART_STDIO_INSTANCE (2)
  52. #define UART_CONSOLE_BASE (SOC_UART_2_REGS)
  53. /******************************************************************************
  54. ** INTERNAL FUNCTION PROTOTYPES
  55. ******************************************************************************/
  56. static void UARTStdioInitExpClk(unsigned int baudRate,
  57. unsigned int rxTrigLevel);
  58. void UARTConsolePutc(unsigned char data);
  59. unsigned char UARTConsoleGetc(void);
  60. void UARTConsoleInit(void);
  61. /******************************************************************************
  62. ** INTERNAL FUNCTION DEFINITIONS
  63. ******************************************************************************/
  64. /**
  65. * \brief This function initializes the specified UART instance for use.
  66. * This does the following:
  67. * 1> Sets the baud rate of communication. \n
  68. * 2> Configures the line characteristics. Specifically, this:
  69. * a> sets the Word Length in each character frame as 8 bits.
  70. * b> selects No parity option.
  71. * c> selects one stop bit in each frame.
  72. *
  73. * 3> Enables the FIFO mode for transmitter and receiver.
  74. * 4> Sets the Receiver FIFO Trigger Level.
  75. *
  76. * \param baudRate The baud rate to be used for communication.
  77. * \param rxTrigLevel The receiver trigger level. This can take one of the
  78. * following four values:
  79. * 1> UART_RX_TRIG_LEVEL_1
  80. * 2> UART_RX_TRIG_LEVEL_4
  81. * 3> UART_RX_TRIG_LEVEL_8
  82. * 4> UART_RX_TRIG_LEVEL_14
  83. *
  84. *
  85. * \return None.
  86. */
  87. // ʱÖÓ
  88. #define SYSCLK_1_FREQ (456000000)
  89. #define SYSCLK_2_FREQ (SYSCLK_1_FREQ/2)
  90. #define UART_2_FREQ (SYSCLK_2_FREQ)
  91. static void UARTStdioInitExpClk(unsigned int baudRate, unsigned int rxTrigLevel)
  92. {
  93. /* Enables the transmitter and receiver*/
  94. UARTEnable(UART_CONSOLE_BASE);
  95. /* Configuring the UART parameters*/
  96. /* 8-bit work length, no parity, 1 stop bit. */
  97. /* The UART module input frequency shall be 150MHz.*/
  98. UARTConfigSetExpClk(UART_CONSOLE_BASE,
  99. UART_2_FREQ,
  100. baudRate,
  101. UART_WORDL_8BITS,
  102. UART_OVER_SAMP_RATE_16);
  103. /* Enables FIFO mode for transmitter and receiver.*/
  104. UARTFIFOEnable(UART_CONSOLE_BASE);
  105. /* Sets the receiver FIFO Trigger level.*/
  106. UARTFIFOLevelSet(UART_CONSOLE_BASE, rxTrigLevel);
  107. }
  108. /**
  109. * \brief This function initializes the specified UART instance for use.
  110. * This does the following:
  111. * 1> Sets the baud rate of communication as 115200.
  112. * 2> Configures the line characteristics to a typical value being
  113. * 8-N-1 which means 8 data bits per frame, No parity bit and
  114. * 1 stop bit/frame.
  115. * 3> Enables the FIFO for transmitter and receiver.
  116. * 4> Sets the receiver trigger level to be 1 byte.
  117. *
  118. * \return None.
  119. *
  120. * \note This function invokes UARTStdioInitExpClk() to perform the above
  121. * configurations. The function UARTStdioInitExpClk() could be
  122. * directly invoked for more customized configurations.
  123. */
  124. void UARTConsoleInit(void)
  125. {
  126. #if (0 == UART_STDIO_INSTANCE)
  127. {
  128. PSCModuleControl(SOC_PSC_0_REGS,9, 0, PSC_MDCTL_NEXT_ENABLE);
  129. UARTPinMuxSetup(0, FALSE);
  130. }
  131. #elif (1 == UART_STDIO_INSTANCE)
  132. {
  133. PSCModuleControl(SOC_PSC_1_REGS,12, 0, PSC_MDCTL_NEXT_ENABLE);
  134. UARTPinMuxSetup(1, FALSE);
  135. }
  136. #else
  137. {
  138. PSCModuleControl(SOC_PSC_1_REGS,13, 0, PSC_MDCTL_NEXT_ENABLE);
  139. UARTPinMuxSetup(2, FALSE);
  140. }
  141. #endif
  142. UARTStdioInitExpClk(BAUD_115200, UART_RX_TRIG_LEVEL_1);
  143. }
  144. /**
  145. * \brief This function puts a character on the serial console.
  146. *
  147. * \param data The character to be put on the serial console
  148. *
  149. * \return None.
  150. */
  151. //void UARTConsolePutc(unsigned char data)
  152. //{
  153. // UARTCharPut(UART_CONSOLE_BASE, data);
  154. //}
  155. /**
  156. * \brief This function puts a character on the serial console.
  157. *
  158. * \param none
  159. *
  160. * \return Character as input from the console
  161. */
  162. //unsigned char UARTConsoleGetc(void)
  163. //{
  164. // return ((unsigned char)UARTCharGet(UART_CONSOLE_BASE));
  165. //}
  166. /********************************* End Of File ******************************/