surenyi
6 years ago
8 changed files with 121 additions and 0 deletions
@ -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; |
|||
} |
@ -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; |
|||
}; |
|||
} |
@ -0,0 +1,4 @@ |
|||
function module$use() |
|||
{ |
|||
xdc.useModule('xdc.runtime.Error'); |
|||
} |
Loading…
Reference in new issue