Browse Source

move Uart to vsky.libdsp

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
3aa4c47bc6
  1. 2
      .gitignore
  2. 1
      packages/vsky/libdsp/Uart.xdc
  3. 22
      packages/vsky/libdsp/driver/package.bld
  4. 4
      packages/vsky/libdsp/driver/package.xdc
  5. 50
      packages/vsky/libdsp/driver/uart.c
  6. 16
      packages/vsky/libdsp/inc/uart.h
  7. 3
      packages/vsky/libdsp/package.bld
  8. 1
      packages/vsky/libdsp/package.xdc
  9. 75
      packages/vsky/libdsp/serial.c

2
.gitignore

@ -17,3 +17,5 @@ packages/ti/csl/makefile
packages/ti/csl/package
packages/vsky/libdsp/driver/Uart.h
packages/vsky/libdsp/lib
packages/vsky/libdsp/Settings.h
packages/vsky/libdsp/Uart.h

1
packages/vsky/libdsp/driver/Uart.xdc → packages/vsky/libdsp/Uart.xdc

@ -1,5 +1,6 @@
import vsky.libdsp.Settings;
@ModuleStartup
module Uart {
/*
* default baudrate.

22
packages/vsky/libdsp/driver/package.bld

@ -1,22 +0,0 @@
Pkg.otherFiles = ["package.bld"];
var drvFiles = [
"uart.c",
];
for (var i = 0; i < Build.targets.length; i++) {
var targ = Build.targets[i];
var libName = "dspdrv";
var libOptions = {
incs: libdspPathInclude,
};
var lib = Pkg.addLibrary("lib/" + libName, targ, libOptions);
lib.addObjects(drvFiles);
}
Pkg.attrs.exportSrc = true;
Pkg.attrs.exportCfg = true;

4
packages/vsky/libdsp/driver/package.xdc

@ -1,4 +0,0 @@
package vsky.libdsp.driver {
module Uart;
}

50
packages/vsky/libdsp/driver/uart.c

@ -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;
}
}
}

16
packages/vsky/libdsp/inc/uart.h

@ -0,0 +1,16 @@
#ifndef __LIBDSP_DRV_UART_H__
#define __LIBDSP_DRV_UART_H__
#ifdef __cplusplus
extern "C" {
#endif
int uart_init(void);
unsigned char uart_read(void);
void uart_write(unsigned char ch);
int uart_is_ready();
void uart_set_baudrate(unsigned short rate);
unsigned short uart_get_baudrate(void);
#ifdef __cplusplus
}
#endif
#endif

3
packages/vsky/libdsp/package.bld

@ -3,9 +3,12 @@ Pkg.otherFiles = [
"package.xdc",
"package.inc",
"Settings.xdc",
"Uart.xdc",
];
var objFiles = [
"driver/uart.c",
"serial.c",
"settings.c",
];

1
packages/vsky/libdsp/package.xdc

@ -3,5 +3,6 @@
*/
package vsky.libdsp {
module Settings;
module Uart;
}

75
packages/vsky/libdsp/serial.c

@ -0,0 +1,75 @@
#include <ti/csl/csl_chip.h>
#include <ti/csl/cslr_uart.h>
#include <xdc/runtime/Startup.h>
#include <vsky/libdsp/Settings.h>
#include "package/internal/Uart.xdc.h"
#include "uart.h"
static Uint16 __to_regrate(Uint32 bps)
{
Uint32 uc = Settings_freq / 6;
return (Uint16)(uc / (bps * 16));
}
int Uart_init()
{
uart_init();
Uart_setBaudrate(Uart_baudrate);
return 0;
}
void Uart_setBaudrate(Uint32 bps)
{
Uint16 rate = __to_regrate(bps);
uart_set_baudrate(rate);
}
Uint32 Uart_getBaudrate(void)
{
Uint32 rate = 0;
Uint16 reg;
Uint32 uc = Settings_freq / 6;
reg = uart_get_baudrate();
if (reg > 0)
rate = uc / (reg * 16);
return rate;
}
Int32 Uart_get(void)
{
return uart_read();
}
void Uart_put(Int32 var)
{
UInt8 b = var & 0xff;
uart_write(b);
}
Bool Uart_isReady(void)
{
return uart_is_ready();
}
Void Uart_puts(String s)
{
Char ch;
if (s) {
while ((ch = *s) != '\0') {
Uart_put(ch);
++s;
}
}
}
Int Uart_Module_startup(Int state)
{
Uart_init();
return Startup_DONE;
}
Loading…
Cancel
Save