Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
fc3cb873
Commit
fc3cb873
authored
Jun 11, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userspace/tools: added tiny serial terminal (com.c)
parent
e9c0485f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
202 additions
and
2 deletions
+202
-2
.gitignore
userspace/tools/.gitignore
+2
-1
Makefile
userspace/tools/Makefile
+4
-1
com.c
userspace/tools/com.c
+196
-0
No files found.
userspace/tools/.gitignore
View file @
fc3cb873
...
...
@@ -4,4 +4,5 @@ rtu_stat
wr_mon
spll_dbg_proxy
wr_phytool
build.sh
\ No newline at end of file
build.sh
com
\ No newline at end of file
userspace/tools/Makefile
View file @
fc3cb873
TOOLS
=
rtu_stat wr_mon wr_phytool spll_dbg_proxy load-lm32 load-virtex
TOOLS
=
rtu_stat wr_mon wr_phytool spll_dbg_proxy load-lm32 load-virtex
com
# # Standard stanza for cross-compilation (courtesy of the linux makefile)
...
...
@@ -46,6 +46,9 @@ load-virtex: load-virtex.o load-fpga.o
load-lm32
:
load-lm32.o lm32-loader.o
${
CC
}
-o
$@
$^
$(LDFLAGS)
com
:
com.o
${
CC
}
-o
$@
$^
$(LDFLAGS)
clean
:
rm
-f
$(TOOLS)
*
.o
*
~
...
...
userspace/tools/com.c
0 → 100644
View file @
fc3cb873
/*
* Building: cc -o com com.c
* Usage : ./com /dev/device [speed]
* Example : ./com /dev/ttyS0 [115200]
* Keys : Ctrl-A - exit, Ctrl-X - display control lines status
* Darcs : darcs get http://tinyserial.sf.net/
* Homepage: http://tinyserial.sourceforge.net
* Version : 2009-03-05
*
* Ivan Tikhonov, http://www.brokestream.com, kefeer@brokestream.com
* Patches by Jim Kou, Henry Nestler, Jon Miner, Alan Horstmann
*
*/
/* Copyright (C) 2007 Ivan Tikhonov
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Ivan Tikhonov, kefeer@brokestream.com
*/
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
int
transfer_byte
(
int
from
,
int
to
,
int
is_control
);
typedef
struct
{
char
*
name
;
int
flag
;
}
speed_spec
;
void
print_status
(
int
fd
)
{
int
status
;
unsigned
int
arg
;
status
=
ioctl
(
fd
,
TIOCMGET
,
&
arg
);
fprintf
(
stderr
,
"[STATUS]: "
);
if
(
arg
&
TIOCM_RTS
)
fprintf
(
stderr
,
"RTS "
);
if
(
arg
&
TIOCM_CTS
)
fprintf
(
stderr
,
"CTS "
);
if
(
arg
&
TIOCM_DSR
)
fprintf
(
stderr
,
"DSR "
);
if
(
arg
&
TIOCM_CAR
)
fprintf
(
stderr
,
"DCD "
);
if
(
arg
&
TIOCM_DTR
)
fprintf
(
stderr
,
"DTR "
);
if
(
arg
&
TIOCM_RNG
)
fprintf
(
stderr
,
"RI "
);
fprintf
(
stderr
,
"
\r\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
comfd
;
struct
termios
oldtio
,
newtio
;
//place for old and new port settings for serial port
struct
termios
oldkey
,
newkey
;
//place tor old and new port settings for keyboard teletype
char
*
devicename
=
argv
[
1
];
int
need_exit
=
0
;
speed_spec
speeds
[]
=
{
{
"1200"
,
B1200
},
{
"2400"
,
B2400
},
{
"4800"
,
B4800
},
{
"9600"
,
B9600
},
{
"19200"
,
B19200
},
{
"38400"
,
B38400
},
{
"57600"
,
B57600
},
{
"115200"
,
B115200
},
{
NULL
,
0
}
};
int
speed
=
B9600
;
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"example: %s /dev/ttyS0 [115200]
\n
"
,
argv
[
0
]);
exit
(
1
);
}
comfd
=
open
(
devicename
,
O_RDWR
|
O_NOCTTY
|
O_NONBLOCK
);
if
(
comfd
<
0
)
{
perror
(
devicename
);
exit
(
-
1
);
}
if
(
argc
>
2
)
{
speed_spec
*
s
;
for
(
s
=
speeds
;
s
->
name
;
s
++
)
{
if
(
strcmp
(
s
->
name
,
argv
[
2
])
==
0
)
{
speed
=
s
->
flag
;
fprintf
(
stderr
,
"setting speed %s
\n
"
,
s
->
name
);
break
;
}
}
}
fprintf
(
stderr
,
"C-a exit, C-x modem lines status
\n
"
);
tcgetattr
(
STDIN_FILENO
,
&
oldkey
);
newkey
.
c_cflag
=
B9600
|
CS8
|
CLOCAL
|
CREAD
;
newkey
.
c_iflag
=
IGNPAR
;
newkey
.
c_oflag
=
0
;
newkey
.
c_lflag
=
0
;
newkey
.
c_cc
[
VMIN
]
=
1
;
newkey
.
c_cc
[
VTIME
]
=
0
;
tcflush
(
STDIN_FILENO
,
TCIFLUSH
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
newkey
);
tcgetattr
(
comfd
,
&
oldtio
);
// save current port settings
newtio
.
c_cflag
=
speed
|
CS8
|
CLOCAL
|
CREAD
;
newtio
.
c_iflag
=
IGNPAR
;
newtio
.
c_oflag
=
0
;
newtio
.
c_lflag
=
0
;
newtio
.
c_cc
[
VMIN
]
=
1
;
newtio
.
c_cc
[
VTIME
]
=
0
;
tcflush
(
comfd
,
TCIFLUSH
);
tcsetattr
(
comfd
,
TCSANOW
,
&
newtio
);
print_status
(
comfd
);
char
seq
[
3
]
=
{
0x80
,
0x80
,
'#'
};
write
(
comfd
,
seq
,
3
);
while
(
!
need_exit
)
{
fd_set
fds
;
int
ret
;
FD_ZERO
(
&
fds
);
FD_SET
(
STDIN_FILENO
,
&
fds
);
FD_SET
(
comfd
,
&
fds
);
ret
=
select
(
comfd
+
1
,
&
fds
,
NULL
,
NULL
,
NULL
);
if
(
ret
==
-
1
)
{
perror
(
"select"
);
}
else
if
(
ret
>
0
)
{
if
(
FD_ISSET
(
STDIN_FILENO
,
&
fds
))
{
need_exit
=
transfer_byte
(
STDIN_FILENO
,
comfd
,
1
);
}
if
(
FD_ISSET
(
comfd
,
&
fds
))
{
need_exit
=
transfer_byte
(
comfd
,
STDIN_FILENO
,
0
);
}
}
}
tcsetattr
(
comfd
,
TCSANOW
,
&
oldtio
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
oldkey
);
close
(
comfd
);
return
0
;
}
int
transfer_byte
(
int
from
,
int
to
,
int
is_control
)
{
char
c
;
int
ret
;
do
{
ret
=
read
(
from
,
&
c
,
1
);
}
while
(
ret
<
0
&&
errno
==
EINTR
);
if
(
ret
==
1
)
{
if
(
is_control
)
{
if
(
c
==
'\x01'
)
{
// C-a
return
-
1
;
}
else
if
(
c
==
'\x18'
)
{
// C-x
print_status
(
to
);
return
0
;
}
}
while
(
write
(
to
,
&
c
,
1
)
==
-
1
)
{
if
(
errno
!=
EAGAIN
&&
errno
!=
EINTR
)
{
perror
(
"write failed"
);
break
;
}
}
}
else
{
fprintf
(
stderr
,
"
\n
nothing to read. probably port disconnected.
\n
"
);
return
-
2
;
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment