|
|
@ -1,19 +1,11 @@ |
|
|
|
#include <ti/csl/csl_chip.h> |
|
|
|
#include <ti/csl/cslr_uart.h> |
|
|
|
#include <vsky/libdsp/Settings.h> |
|
|
|
#include "package/internal/Uart.xdc.h" |
|
|
|
#include "uart.h" |
|
|
|
|
|
|
|
#define hUartRegs ((CSL_UartRegs*)CSL_UART_REGS) |
|
|
|
|
|
|
|
static Uint16 __to_regrate(Uint32 bps) |
|
|
|
{ |
|
|
|
// Uint32 uc = 166666666;
|
|
|
|
Uint32 uc = Settings_freq / 6; |
|
|
|
|
|
|
|
return (Uint16)(uc / (bps * 16)); |
|
|
|
} |
|
|
|
|
|
|
|
Int32 Uart_init() |
|
|
|
int uart_init() |
|
|
|
{ |
|
|
|
// Allows access to the divisor latches of the baud generator during a
|
|
|
|
// read or write operation (DLL and DLH)
|
|
|
@ -91,16 +83,11 @@ Int32 Uart_init() |
|
|
|
CSL_FINS (hUartRegs->FCR, UART_FCR_RXCLR, CSL_UART_FCR_RXCLR_CLR); |
|
|
|
CSL_FINS (hUartRegs->FCR, UART_FCR_DMAMODE1, CSL_UART_FCR_DMAMODE1_DISABLE); |
|
|
|
CSL_FINS (hUartRegs->FCR, UART_FCR_RXFIFTL, CSL_UART_FCR_RXFIFTL_CHAR1); |
|
|
|
|
|
|
|
Uart_setBaudrate(Uart_baudrate); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void Uart_setBaudrate(Uint32 bps) |
|
|
|
void uart_set_baudrate(unsigned short rate) |
|
|
|
{ |
|
|
|
Uint16 rate = __to_regrate(bps); |
|
|
|
|
|
|
|
hUartRegs->LCR = 0x80; |
|
|
|
|
|
|
|
// Set the baudrate,for accessing LCR[7] should be enable
|
|
|
@ -109,22 +96,19 @@ void Uart_setBaudrate(Uint32 bps) |
|
|
|
hUartRegs->LCR = 0x03; |
|
|
|
} |
|
|
|
|
|
|
|
Uint32 Uart_getBaudrate(void) |
|
|
|
unsigned short uart_get_baudrate(void) |
|
|
|
{ |
|
|
|
Uint32 rate = 0; |
|
|
|
Uint16 reg; |
|
|
|
Uint32 uc = Settings_freq / 6; |
|
|
|
|
|
|
|
hUartRegs->LCR = 0x80; |
|
|
|
// Read the baudrate
|
|
|
|
reg = (hUartRegs->DLL & 0xff) | ((hUartRegs->DLH & 0xff)<< 8); |
|
|
|
hUartRegs->LCR = 0x03; |
|
|
|
if (reg > 0) |
|
|
|
rate = uc / (reg * 16); |
|
|
|
return rate; |
|
|
|
|
|
|
|
return reg; |
|
|
|
} |
|
|
|
|
|
|
|
Int32 Uart_get(void) |
|
|
|
unsigned char uart_read(void) |
|
|
|
{ |
|
|
|
uint8_t uRcvChar = 0; |
|
|
|
|
|
|
@ -133,17 +117,15 @@ Int32 Uart_get(void) |
|
|
|
return uRcvChar; |
|
|
|
} |
|
|
|
|
|
|
|
void Uart_put(Int32 var) |
|
|
|
void uart_write(unsigned char ch) |
|
|
|
{ |
|
|
|
UInt8 b = var & 0xff; |
|
|
|
|
|
|
|
while (!(CSL_FEXT(hUartRegs->LSR, UART_LSR_THRE))) { |
|
|
|
; |
|
|
|
} |
|
|
|
CSL_FINS(hUartRegs->THR, UART_THR_DATA, b); |
|
|
|
CSL_FINS(hUartRegs->THR, UART_THR_DATA, ch); |
|
|
|
} |
|
|
|
|
|
|
|
Bool Uart_isReady(void) |
|
|
|
int uart_is_ready() |
|
|
|
{ |
|
|
|
Bool dr = FALSE; |
|
|
|
|
|
|
@ -154,15 +136,3 @@ Bool Uart_isReady(void) |
|
|
|
return (dr); |
|
|
|
} |
|
|
|
|
|
|
|
Void Uart_puts(String s) |
|
|
|
{ |
|
|
|
Char ch; |
|
|
|
if (s) { |
|
|
|
while ((ch = *s) != '\0') { |
|
|
|
Uart_put(ch); |
|
|
|
++s; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|