Browse Source

add Serial module

Signed-off-by: surenyi <surenyi82@qq.com>
master
surenyi 6 years ago
parent
commit
616426213b
  1. 1
      .gitignore
  2. 46
      packages/vsky/libdsp/Serial.c
  3. 52
      packages/vsky/libdsp/Serial.xdc
  4. 4
      packages/vsky/libdsp/Serial.xs
  5. 13
      packages/vsky/libdsp/driver/uart.cpp
  6. 2
      packages/vsky/libdsp/inc/uart.h
  7. 2
      packages/vsky/libdsp/package.bld
  8. 1
      packages/vsky/libdsp/package.xdc

1
.gitignore

@ -25,6 +25,7 @@ packages/vsky/libdsp/driver/Uart.h
packages/vsky/libdsp/lib
packages/vsky/libdsp/Settings.h
packages/vsky/libdsp/Uart.h
packages/vsky/libdsp/Serial.h
packages/vsky/libdsp/SerialSystem.h
packages/vsky/libdsp/Interrupt.h
packages/vsky/libdsp/driver/cfi_flash.orig.c

46
packages/vsky/libdsp/Serial.c

@ -0,0 +1,46 @@
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include "inc/uart.h"
#include "package/internal/Serial.xdc.h"
Int Serial_Instance_init(Serial_Object *obj, Int p, const Serial_Params *param, Error_Block *eb)
{
obj->_uart = uart_open(p);
if (obj->_uart == NULL) {
if (eb) {
Error_raise(eb, Error_E_generic, 0, 0);
}
return -1;
}
uart_set_baudrate(obj->_uart, param->baudrate);
uart_set_databits(obj->_uart, param->databits);
uart_set_stopbits(obj->_uart, param->stopbits);
return 0;
}
void Serial_Instance_finalize(Serial_Object *obj, Int state)
{
if (state == 0) {
uart_close(obj->_uart);
}
}
UInt8 Serial_Instance_read(Serial_Object *obj)
{
return uart_read(obj->_uart);
}
void Serial_Instance_write(Serial_Object *obj, UInt8 ch)
{
uart_write(obj->_uart, ch);
}
Bool Serial_Instance_isReady(Serial_Object *obj)
{
return uart_is_ready(obj->_uart);
}
Ptr Serial_Instance_uart(Serial_Object *obj)
{
return obj->_uart;
}

52
packages/vsky/libdsp/Serial.xdc

@ -0,0 +1,52 @@
@InstanceFinalize
@InstanceInitError
module Serial {
/*
* Serial Port driver.
*/
instance:
config UInt32 baudrate = 115200;
config UInt32 databits = 8;
config UInt32 stopbits = 1;
/*!
* Create serial port.
*
* @p(html)
* Serial_Handle h;
* Serial_Params p;
* Serial_Params_init(&p);
*
* h = Serial_create(0, &p);
* if (h != NULL) {
* ...
* }
* @p
*/
create(Int port);
/*!
* read a byte from serial.
*/
UInt8 read();
/*!
* write a byte to serial.
*/
void write(UInt8 ch);
/*!
* data is comming.
*
Bool isReady();
/*!
* get the lowlevel uart handle.
*/
Ptr uart();
internal:
@Opaque struct Instance_State {
Ptr _uart;
};
}

4
packages/vsky/libdsp/Serial.xs

@ -0,0 +1,4 @@
function module$use()
{
xdc.useModule('xdc.runtime.Error');
}

13
packages/vsky/libdsp/driver/uart.cpp

@ -21,6 +21,14 @@ struct Uart : public UartImpl {
return 0;
}
void reset()
{
_baudrate = 115200;
_databits = DATA_BITS_8;
_stopbits = STOP_BITS_1;
_parity = PARITY_NONE;
}
void set_baudrate(int rate)
{
this->setBaudrate(rate);
@ -87,6 +95,11 @@ uart_t uart_open(int bus)
return _uart;
}
void uart_close(uart_t _uart)
{
_uart->reset();
}
void uart_set_baudrate(uart_t _uart, int rate)
{
_uart->set_baudrate(rate);

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

@ -21,6 +21,8 @@ typedef struct Uart * uart_t;
uart_t uart_open(int uart);
void uart_close(uart_t _uart);
/* data in */
int uart_is_ready(uart_t);

2
packages/vsky/libdsp/package.bld

@ -9,6 +9,7 @@ Pkg.otherFiles = [
"GPIO.xdc",
"Board.xdc",
"board.xdt",
"Serial.xdc",
];
var drvFiles = [
@ -35,6 +36,7 @@ var emacFiles = [
var xdcFiles = [
"Board.c",
"Serial.c",
"SerialSystem.c",
"NorFlash.c",
"GPIO.c",

1
packages/vsky/libdsp/package.xdc

@ -8,6 +8,7 @@
*/
package vsky.libdsp [0, 9, 9, 0] {
module Settings;
module Serial;
module SerialSystem;
module NorFlash;
module GPIO;

Loading…
Cancel
Save