Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x393_sata
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
x393_sata
Commits
0a15e1e3
Commit
0a15e1e3
authored
Feb 06, 2016
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated scripts to work with current yocto/python
parent
7194dbb0
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
344 additions
and
22 deletions
+344
-22
x393_mem.py
py393sata/x393_mem.py
+47
-19
x393_vsc3304.py
py393sata/x393_vsc3304.py
+17
-2
x393sata.py
py393sata/x393sata.py
+280
-1
No files found.
py393sata/x393_mem.py
View file @
0a15e1e3
...
...
@@ -43,6 +43,8 @@ class X393Mem(object):
MAXI0_BASE
=
0x40000000
MAXI1_BASE
=
0x80000000
MAXI_BASE
=
MAXI0_BASE
USE_NEGATIVE
=
True
# Old versions of Python (2.7.3) required mmap offset to fit into 32 bits, so upper half had to be negative
# 2.7.11 does not need subtraction(and reports error if negative)
def
__init__
(
self
,
debug_mode
=
1
,
dry_mode
=
False
,
maxi_port
=
0
):
if
maxi_port
:
...
...
@@ -65,6 +67,26 @@ class X393Mem(object):
maxi_port
=
(
0
,
1
)[
self
.
MAXI_BASE
==
self
.
MAXI1_BASE
]
print
(
"MAXI port =
%
d (0x
%08
x)"
%
(
maxi_port
,
self
.
MAXI_BASE
))
def
wrap_mm
(
self
,
f
,
page_addr
):
if
page_addr
>=
0x80000000
:
if
(
self
.
USE_NEGATIVE
):
try
:
return
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
-
(
1
<<
32
))
except
:
self
.
USE_NEGATIVE
=
False
print
(
"Turning OFF use of negative offsets in mmap"
)
return
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
else
:
try
:
return
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
except
:
print
(
"Turning ON use of negative offsets in mmap"
)
self
.
USE_NEGATIVE
=
True
return
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
-
(
1
<<
32
))
else
:
return
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
def
write_mem
(
self
,
addr
,
data
,
quiet
=
1
):
"""
Write 32-bit word to physical memory
...
...
@@ -78,9 +100,10 @@ class X393Mem(object):
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
page_addr
=
addr
&
(
~
(
self
.
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
packedData
=
struct
.
pack
(
self
.
ENDIAN
+
"L"
,
data
)
d
=
struct
.
unpack
(
self
.
ENDIAN
+
"L"
,
packedData
)[
0
]
mm
[
page_offs
:
page_offs
+
4
]
=
packedData
...
...
@@ -108,9 +131,10 @@ class X393Mem(object):
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
page_addr
=
addr
&
(
~
(
self
.
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
data
=
struct
.
unpack
(
self
.
ENDIAN
+
"L"
,
mm
[
page_offs
:
page_offs
+
4
])
d
=
data
[
0
]
if
quiet
<
1
:
...
...
@@ -149,9 +173,10 @@ class X393Mem(object):
for
addr
in
range
(
start_addr
,
end_addr
+
byte_mode
,
byte_mode
):
page_addr
=
addr
&
(
~
(
self
.
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
data
=
struct
.
unpack_from
(
self
.
ENDIAN
+
frmt_bytes
[
byte_mode
],
mm
,
page_offs
)
rslt
.
append
(
data
[
0
])
...
...
@@ -202,9 +227,10 @@ class X393Mem(object):
if
page_num
==
last_page
:
end_offset
=
start_addr
+
length
-
self
.
PAGE_SIZE
*
page_num
page_addr
=
page_num
*
self
.
PAGE_SIZE
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
bf
.
write
(
mm
[
start_offset
:
end_offset
])
def
mem_clear
(
self
,
start_addr
,
length
,
word32
):
...
...
@@ -229,9 +255,10 @@ class X393Mem(object):
if
page_num
==
last_page
:
end_offset
=
start_addr
+
length
-
self
.
PAGE_SIZE
*
page_num
page_addr
=
page_num
*
self
.
PAGE_SIZE
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
mm
[
start_offset
:
end_offset
]
=
patt
[
start_offset
:
end_offset
]
...
...
@@ -273,9 +300,10 @@ class X393Mem(object):
data
=
(
start_data
+
((
addr
-
start_addr
)
//
byte_mode
)
*
inc_data
)
&
data_mask
page_addr
=
addr
&
(
~
(
self
.
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
PAGE_SIZE
,
offset
=
page_addr
)
mm
=
self
.
wrap_mm
(
f
,
page_addr
)
# if (page_addr>=0x80000000):
# page_addr-= (1<<32)
# mm = mmap.mmap(f.fileno(), self.PAGE_SIZE, offset=page_addr)
struct
.
pack_into
(
self
.
ENDIAN
+
frmt_bytes
[
byte_mode
],
mm
,
page_offs
,
data
)
'''
...
...
py393sata/x393_vsc3304.py
View file @
0a15e1e3
...
...
@@ -32,9 +32,10 @@ import os
from
x393_mem
import
X393Mem
#from time import sleep
#import shutil
VSC_DIR
=
"/sys/devices/amba.0/e0004000.ps7-i2c/i2c-0/0-0001"
VSC_DIR_OLD
=
"/sys/devices/amba.0/e0004000.ps7-i2c/i2c-0/0-0001"
VSC_DIR_NEW
=
"/sys/devices/soc0/amba@0/e0004000.ps7-i2c/i2c-0/0-0001"
# 10389 rev "0"
VSC_DIR
=
None
class
x393_vsc3304
(
object
):
DRY_MODE
=
True
# True
DEBUG_MODE
=
1
...
...
@@ -88,17 +89,31 @@ class x393_vsc3304(object):
PCB_REV
=
"10389"
current_mode
=
"ESATA<->SSD"
def
__init__
(
self
,
debug_mode
=
1
,
dry_mode
=
False
,
pcb_rev
=
"10389"
):
global
VSC_DIR
self
.
DEBUG_MODE
=
debug_mode
if
not
dry_mode
:
if
not
os
.
path
.
exists
(
"/dev/xdevcfg"
):
dry_mode
=
True
print
(
"Program is forced to run in SIMULATED mode as '/dev/xdevcfg' does not exist (not a camera)"
)
else
:
if
os
.
path
.
exists
(
VSC_DIR_OLD
):
print
(
'x393_vsc3304: Running on OLD system'
)
VSC_DIR
=
VSC_DIR_OLD
elif
os
.
path
.
exists
(
VSC_DIR_NEW
):
print
(
'x393_vsc3304: Running on NEW system'
)
VSC_DIR
=
VSC_DIR_NEW
else
:
print
(
"Does not seem to be a known system - both
%
s (old) and
%
s (new) are not found"
%
(
VSC_DIR_OLD
,
VSC_DIR_NEW
))
return
self
.
DRY_MODE
=
dry_mode
self
.
x393_mem
=
X393Mem
(
debug_mode
,
dry_mode
,
1
)
if
not
pcb_rev
in
self
.
PCB_CONNECTIONS
:
print
(
"Unknown PCB/rev:
%
s (defined:
%
s), using
%
s"
%
(
pcb_rev
,
str
(
self
.
PCB_CONNECTIONS
.
keys
()),
self
.
PCB_REV
))
else
:
self
.
PCB_REV
=
pcb_rev
def
echo
(
self
,
what
,
where
):
if
self
.
DRY_MODE
:
print
(
"'
%
s' -> '
%
s'"
%
(
str
(
what
),
VSC_DIR
+
"/"
+
where
))
...
...
py393sata/x393sata.py
View file @
0a15e1e3
This diff is collapsed.
Click to expand it.
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