Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
eddr3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
eddr3
Commits
ef3e06aa
Commit
ef3e06aa
authored
Jun 08, 2014
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed directory
parent
896e116a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
210 additions
and
0 deletions
+210
-0
exp_gpio.py
python/exp_gpio.py
+57
-0
mem.py
python/mem.py
+53
-0
memdump.py
python/memdump.py
+52
-0
mon_gpio.py
python/mon_gpio.py
+48
-0
No files found.
python/exp_gpio.py
0 → 100755
View file @
ef3e06aa
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013, Elphel.inc.
# Export range of GPIO (EMIO)registers
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__
=
"Andrey Filippov"
__copyright__
=
"Copyright 2014, Elphel, Inc."
__license__
=
"GPL"
__version__
=
"3.0+"
__maintainer__
=
"Andrey Filippov"
__email__
=
"andrey@elphel.com"
__status__
=
"Development"
from
__future__
import
print_function
import
sys
if
len
(
sys
.
argv
)
<
3
or
(
sys
.
argv
[
1
]
!=
"in"
and
sys
.
argv
[
1
]
!=
"out"
)
:
print
(
"Usage: "
,
sys
.
argv
[
0
]
+
" <in|out> <gpio_number>[<gpio_max_number>]"
)
exit
(
0
)
mode
=
sys
.
argv
[
1
]
gpio_low_n
=
int
(
sys
.
argv
[
2
])
if
len
(
sys
.
argv
)
>
3
:
gpio_high_n
=
int
(
sys
.
argv
[
3
])
else
:
gpio_high_n
=
gpio_low_n
print
(
"exporting as
\"
"
+
mode
+
"
\"
:"
,
end
=
""
),
for
gpio_n
in
range
(
gpio_low_n
,
gpio_high_n
+
1
):
print
(
"
%
d"
%
gpio_n
,
end
=
""
)
print
()
# bash> echo 240 > /sys/class/gpio/export
# bash> echo out > /sys/class/gpio/gpio240/direction
# bash> echo 1 > /sys/class/gpio/gpio240/value
for
gpio_n
in
range
(
gpio_low_n
,
gpio_high_n
+
1
):
try
:
with
open
(
"/sys/class/gpio/export"
,
"w"
)
as
f
:
print
(
gpio_n
,
file
=
f
)
except
:
print
(
"failed
\"
echo
%
d > /sys/class/gpio/export"
%
gpio_n
)
try
:
with
open
(
"/sys/class/gpio/gpio
%
d/direction"
%
gpio_n
,
"w"
)
as
f
:
print
(
mode
,
file
=
f
)
except
:
print
(
"failed
\"
echo
%
s > /sys/class/gpio/gpio
%
d/direction"
%
(
mode
,
gpio_n
))
python/mem.py
0 → 100755
View file @
ef3e06aa
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013, Elphel.inc.
# Read/write memory locations as 32-bit values
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__
=
"Andrey Filippov"
__copyright__
=
"Copyright 2014, Elphel, Inc."
__license__
=
"GPL"
__version__
=
"3.0+"
__maintainer__
=
"Andrey Filippov"
__email__
=
"andrey@elphel.com"
__status__
=
"Development"
import
mmap
import
sys
import
struct
PAGE_SIZE
=
4096
endian
=
"<"
# little, ">" for big
if
len
(
sys
.
argv
)
<
2
:
print
"Usage: "
,
sys
.
argv
[
0
]
+
" address [data]"
exit
(
0
)
addr
=
int
(
sys
.
argv
[
1
],
16
)
&
0xfffffffc
data
=
0
writeMode
=
len
(
sys
.
argv
)
>
2
if
(
writeMode
):
data
=
int
(
sys
.
argv
[
2
],
16
)
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
page_addr
=
addr
&
(
~
(
PAGE_SIZE
-
1
))
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
PAGE_SIZE
,
offset
=
page_addr
)
if
writeMode
:
packedData
=
struct
.
pack
(
endian
+
"L"
,
data
)
d
=
struct
.
unpack
(
endian
+
"L"
,
packedData
)[
0
]
mm
[
page_offs
:
page_offs
+
4
]
=
packedData
print
(
"0x
%08
x <== 0x
%08
x (
%
d)"
%
(
addr
,
d
,
d
))
else
:
data
=
struct
.
unpack
(
endian
+
"L"
,
mm
[
page_offs
:
page_offs
+
4
])
d
=
data
[
0
]
print
(
"0x
%08
x ==> 0x
%08
x (
%
d)"
%
(
addr
,
d
,
d
))
mm
.
close
()
python/memdump.py
0 → 100755
View file @
ef3e06aa
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013, Elphel.inc.
# Dump a range of memory locations (physical)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__
=
"Andrey Filippov"
__copyright__
=
"Copyright 2014, Elphel, Inc."
__license__
=
"GPL"
__version__
=
"3.0+"
__maintainer__
=
"Andrey Filippov"
__email__
=
"andrey@elphel.com"
__status__
=
"Development"
import
mmap
import
sys
import
struct
PAGE_SIZE
=
4096
endian
=
"<"
# little, ">" for big
if
len
(
sys
.
argv
)
<=
1
:
print
"Usage: "
,
sys
.
argv
[
0
]
+
" start_address end_address"
exit
(
0
)
start_addr
=
int
(
sys
.
argv
[
1
],
16
)
&
0xfffffffc
if
len
(
sys
.
argv
)
>
2
:
end_addr
=
int
(
sys
.
argv
[
2
],
16
)
&
0xfffffffc
else
:
end_addr
=
start_addr
data
=
0
writeMode
=
len
(
sys
.
argv
)
>
2
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
for
addr
in
range
(
start_addr
,
end_addr
+
4
,
4
):
page_addr
=
addr
&
(
~
(
PAGE_SIZE
-
1
))
if
(
addr
==
start_addr
)
or
((
addr
&
0x3f
)
==
0
):
print
(
"
\n
0x
%08
x:"
%
addr
),
page_offs
=
addr
-
page_addr
if
(
page_addr
>=
0x80000000
):
page_addr
-=
(
1
<<
32
)
mm
=
mmap
.
mmap
(
f
.
fileno
(),
PAGE_SIZE
,
offset
=
page_addr
)
data
=
struct
.
unpack
(
endian
+
"L"
,
mm
[
page_offs
:
page_offs
+
4
])
d
=
data
[
0
]
print
(
"
%08
x"
%
d
),
mm
.
close
()
python/mon_gpio.py
0 → 100755
View file @
ef3e06aa
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2013, Elphel.inc.
# Monitor a range of GPIO bits (should be exported first)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__
=
"Andrey Filippov"
__copyright__
=
"Copyright 2014, Elphel, Inc."
__license__
=
"GPL"
__version__
=
"3.0+"
__maintainer__
=
"Andrey Filippov"
__email__
=
"andrey@elphel.com"
__status__
=
"Development"
from
__future__
import
print_function
import
sys
if
len
(
sys
.
argv
)
<
2
:
print
(
"Usage: "
,
sys
.
argv
[
0
]
+
" <gpio_number>[<gpio_max_number>]"
)
exit
(
0
)
gpio_low_n
=
int
(
sys
.
argv
[
1
])
if
len
(
sys
.
argv
)
>
2
:
gpio_high_n
=
int
(
sys
.
argv
[
2
])
else
:
gpio_high_n
=
gpio_low_n
print
(
"gpio
%
d.
%
d: "
%
(
gpio_high_n
,
gpio_low_n
),
end
=
""
),
# bash> echo 240 > /sys/class/gpio/export
# bash> echo out > /sys/class/gpio/gpio240/direction
# bash> echo 1 > /sys/class/gpio/gpio240/value
for
gpio_n
in
range
(
gpio_high_n
,
gpio_low_n
-
1
,
-
1
):
if
gpio_n
!=
gpio_high_n
and
((
gpio_n
-
gpio_low_n
+
1
)
%
4
)
==
0
:
print
(
"."
,
end
=
""
)
try
:
with
open
(
"/sys/class/gpio/gpio
%
d/value"
%
gpio_n
,
"r"
)
as
f
:
print
(
f
.
read
(
1
),
end
=
""
)
except
:
print
(
"X"
,
end
=
""
)
print
()
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