git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
PCI 16x50 UART Controller, O2 Enablement (#39)
[lunaix-os.git]
/
lunaix-os
/
usr
/
testp.c
diff --git
a/lunaix-os/usr/testp.c
b/lunaix-os/usr/testp.c
index 8011c304b028451d289a211a49a3f2bbe318601d..ee33fe6f69710ee37c05b6635dd2cb880a6763da 100644
(file)
--- a/
lunaix-os/usr/testp.c
+++ b/
lunaix-os/usr/testp.c
@@
-6,26
+6,32
@@
#include <unistd.h>
void
#include <unistd.h>
void
-test_serial()
+test_serial(
char* dev, int wr
)
{
{
- int fd = open(
"/dev/ttyS0"
, FO_WRONLY);
+ int fd = open(
dev
, FO_WRONLY);
if (fd < 0) {
if (fd < 0) {
- printf("tty
S0 not accessable (%d)\n"
, errno);
+ printf("tty
%s not accessable (%d)\n", dev
, errno);
return;
}
return;
}
- char buf[32];
int sz = 0;
int sz = 0;
+ char buf[256];
- printf("ttyS0 input: ");
+ if (!wr) {
+ printf("tty input: ");
- if ((sz = read(fd, buf, 31)) < 0) {
-
printf("write to ttyS0
failed (%d)\n", errno);
- }
+
if ((sz = read(fd, buf, 31)) < 0) {
+
printf("read to tty
failed (%d)\n", errno);
+
}
- buf[sz] = 0;
+
buf[sz] = 0;
- printf("%s", buf);
+ printf("%s", buf);
+ }
+ else {
+ int size = snprintf(buf, 256, "serial test: %s", dev);
+ write(fd, buf, size);
+ }
close(fd);
}
close(fd);
}
@@
-33,18
+39,14
@@
test_serial()
int
main(int argc, char* argv[])
{
int
main(int argc, char* argv[])
{
- if (argc <= 1) {
+ if (argc != 2) {
+ printf("usage: testp path_to_dev\n");
return 1;
}
char* target = argv[1];
return 1;
}
char* target = argv[1];
- if (!strcmp(target, "serial")) {
- test_serial();
- } else {
- printf("unknown test: %s\n", target);
- return 1;
- }
+ test_serial(target, 1);
return 0;
}
\ No newline at end of file
return 0;
}
\ No newline at end of file