6#include "yahal_assert.h"
16uart_BBB::uart_BBB(
const char *dev){
19 _fd=open(dev, O_RDWR | O_NOCTTY);
20 yahal_assert(_fd > 0);
23 yahal_assert(ret > 0);
25 ret=tcgetattr(_fd, &config);
26 yahal_assert(ret == 0);
28 config.c_cflag = B9600 | HWFLOW | CS8 | STOP | PARITYON | PARITY | CLOCAL | CREAD;
30 config.c_iflag = IGNBRK | IGNCR;
31 config.c_iflag &= ~(IXON | IXOFF | IXANY);
42 cfsetospeed (&config, BAUDRATE);
43 cfsetispeed (&config, BAUDRATE);
45 tcflush(_fd, TCIFLUSH);
47 tcsetattr(_fd,TCSANOW, &config);
52 int ret = close( _fd );
53 yahal_assert(ret != -1);
56int16_t uart_BBB::write(uint8_t *txbuf, uint8_t len){
57 return ::write(_fd, txbuf, len);
60int16_t uart_BBB::read (uint8_t *rxbuf, uint8_t len){
61 return ::read(_fd, rxbuf, len);
64unsigned uart_BBB::switch_baud(
unsigned baud){
65 cfsetospeed (&config, baud);
66 cfsetispeed (&config, baud);
71void uart_BBB::flush(){
72 tcflush(_fd, TCIOFLUSH);
75void uart_BBB::setattributes(){
76 tcsetattr(_fd,TCSANOW, &config);
79void uart_BBB::setBytesToRead(
unsigned bytes){
80 config.c_cc[VMIN]=bytes;
84void uart_BBB::setReadTimeout(
unsigned timeout){
85 config.c_cc[VTIME]=timeout;