Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
SPEC7
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Projects
SPEC7
Commits
968517cd
Commit
968517cd
authored
Sep 07, 2020
by
Ton Damen
Committed by
Pascal Bos
Sep 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update sw/vuart/spec7_vuart.py
parent
9937dc8e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
spec7_vuart.py
sw/vuart/spec7_vuart.py
+88
-0
No files found.
sw/vuart/spec7_vuart.py
0 → 100644
View file @
968517cd
#!/usr/bin/python3
#
# Simple terminal interface to the uart of the WR core
#
# Depending on the presents of the Xilinx XDMA driver
# Based on the Single AXI4 memory mapped (MM) user interface of the The Xilinx
# DMA/Bridge Subsystem for PCI Express (pg195)
#
# Author: Ton Damen, tond@nikhef.nl
# Date: 8/4/2020
#
import
os
import
sys
import
argparse
import
time
import
termios
import
pdb
syscon_addr
=
0x20400
vuart_addr
=
0x20500
xmda_user_fd
=
0
;
parser
=
argparse
.
ArgumentParser
(
description
=
'Terminal interface to the uart of the wr core on the SPEC card'
)
parser
.
add_argument
(
'--device'
,
'-d'
,
default
=
'/dev/xdma0_user'
,
help
=
'device path name, default is /dev/xdma0_user'
)
args
=
parser
.
parse_args
()
def
str2int
(
s
):
try
:
if
(
len
(
s
)
>
0
and
s
[
0
:
2
]
==
'0x'
):
val
=
int
(
s
[
2
:],
16
)
else
:
val
=
int
(
s
)
return
val
except
ValueError
:
sys
.
exit
(
'Invalid value: {}'
.
format
(
s
))
def
vuart_getc
():
while
True
:
data
=
os
.
pread
(
xdma_user_fd
,
4
,
vuart_addr
+
0x14
)
rx_reg
=
int
.
from_bytes
(
data
,
"little"
)
if
(
rx_reg
&
0x100
)
!=
0
:
return
rx_reg
&
0xff
else
:
return
-
1
def
vuart_putc
(
c
):
while
True
:
data
=
os
.
pread
(
xdma_user_fd
,
4
,
vuart_addr
+
0x10
)
if
(
int
.
from_bytes
(
data
,
"little"
)
&
0x100
)
!=
0
:
break
time
.
sleep
(
0.1
)
os
.
pwrite
(
xdma_user_fd
,
c
.
to_bytes
(
4
,
'little'
),
vuart_addr
+
0x10
)
stdio_fd
=
sys
.
stdin
.
fileno
()
old
=
termios
.
tcgetattr
(
stdio_fd
)
new
=
termios
.
tcgetattr
(
stdio_fd
)
# [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
new
[
0
]
=
termios
.
IGNPAR
new
[
1
]
=
0
new
[
2
]
=
termios
.
B9600
|
termios
.
CS8
|
termios
.
CLOCAL
|
termios
.
CREAD
new
[
3
]
=
0
new
[
6
][
termios
.
VMIN
]
=
0
new
[
6
][
termios
.
VTIME
]
=
0
print
(
'Type C-a to exit
\n
'
)
try
:
termios
.
tcsetattr
(
stdio_fd
,
termios
.
TCSADRAIN
,
new
)
xdma_user_fd
=
os
.
open
(
args
.
device
,
os
.
O_RDWR
)
while
True
:
key
=
sys
.
stdin
.
read
(
1
)
if
(
len
(
key
)
>
0
):
if
key
==
chr
(
1
):
break
else
:
vuart_putc
(
ord
(
key
))
c
=
vuart_getc
()
if
c
>
0
:
sys
.
stdout
.
write
(
chr
(
c
))
sys
.
stdout
.
flush
()
except
OSError
as
error
:
sys
.
exit
(
'Device i/o failed: {}'
.
format
(
error
))
finally
:
termios
.
tcsetattr
(
stdio_fd
,
termios
.
TCSADRAIN
,
old
)
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