3 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
6 * Faculty of Computer Science, Mathematics and Natural Sciences,
7 * Leipzig University of Applied Sciences (HTWK Leipzig)
12 #include <sys/types.h>
20 int open_sport(int number
)
29 memset(port_name
, 0, sizeof(port_name
));
30 sprintf(port_name
, "/dev/ttyS%d", number
);
31 info("Opening port %s!\n", port_name
);
33 fd
= open(port_name
, O_RDWR
| O_NOCTTY
| O_NDELAY
);
35 panic("Cannot open serial port!\n");
38 tcflush(fd
, TCIFLUSH
);
40 term
.c_cflag
= B9600
| CS8
|CREAD
| CLOCAL
| HUPCL
;
42 cfsetospeed(&term
, B9600
);
43 tcsetattr(fd
, TCSANOW
, &term
);
45 info("cflag=%08x\n", term
.c_cflag
);
46 info("oflag=%08x\n", term
.c_oflag
);
47 info("iflag=%08x\n", term
.c_iflag
);
48 info("lflag=%08x\n", term
.c_lflag
);
49 info("line=%02x\n", term
.c_line
);
54 ssize_t
write_sport(int fd
, char *out
, size_t len
)
56 return write(fd
, out
, len
);
59 ssize_t
read_sport(int fd
, char *in
, size_t len
)
61 return read(fd
, in
, len
);
64 void close_sport(int fd
)