Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
python-elphel-extensions
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
python-elphel-extensions
Commits
a58c228e
Commit
a58c228e
authored
Mar 20, 2015
by
YuriNenakhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
0 deletions
+126
-0
.project
.project
+17
-0
.pydevproject
.pydevproject
+8
-0
elphel.py
elphel.py
+81
-0
libelphel.c
libelphel.c
+20
-0
No files found.
.project
0 → 100644
View file @
a58c228e
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
python_elphel_extensions
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.python.pydev.PyDevBuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.python.pydev.pythonNature
</nature>
</natures>
</projectDescription>
.pydevproject
0 → 100644
View file @
a58c228e
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_pathproperty
name=
"org.python.pydev.PROJECT_SOURCE_PATH"
>
<path>
/${PROJECT_DIR_NAME}
</path>
</pydev_pathproperty>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_VERSION"
>
python 2.7
</pydev_property>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_INTERPRETER"
>
Default
</pydev_property>
</pydev_project>
elphel.py
0 → 100644
View file @
a58c228e
'''
Created on Mar 20, 2015
@author: yuri
'''
import
ctypes
import
os
import
mmap
import
struct
class
phys_mem
:
'''
For the allocated physical memory not to be accidentially
re-allocated by any other process, the process which
allocated it should remain working
'''
def
__init__
(
self
,
buf_size
=
4096
):
ctypes_alloc
=
ctypes
.
CDLL
(
'libelphel.so'
)
.
malloc_and_mlock
ctypes_alloc
.
restype
=
ctypes
.
c_void_p
ctypes_alloc
.
argtypes
=
ctypes
.
c_size_t
,
self
.
endian
=
"<"
# little, ">" for big
self
.
page_size
=
int
(
os
.
sysconf
(
"SC_PAGE_SIZE"
))
&
0x7FFFFFFFFFFFFF
self
.
pagemap_entry_size
=
8
self
.
size
=
buf_size
if
self
.
size
>
self
.
page_size
:
print
(
"Only one page can be continuously
\
allocated from userspace
\n
"
)
self
.
size
=
self
.
page_size
self
.
virt_start_addr
=
ctypes_alloc
(
self
.
size
)
self
.
pid
=
os
.
getpid
()
self
.
__get_pagemap_entry
()
self
.
offset
=
self
.
virt_start_addr
&
(
self
.
page_size
-
1
)
self
.
start_addr
=
int
(
self
.
page
*
self
.
page_size
+
self
.
offset
)
&
0x7FFFFFFFFFFFFF
self
.
end_addr
=
int
(
self
.
start_addr
+
self
.
size
)
&
0x7FFFFFFFFFFFFF
def
__get_pagemap_entry
(
self
):
maps_path
=
"/proc/{0}/pagemap"
.
format
(
self
.
pid
)
if
not
os
.
path
.
isfile
(
maps_path
):
print
(
"Process {0} doesn't exist."
.
format
(
self
.
pid
))
return
offset
=
(
self
.
virt_start_addr
/
self
.
page_size
)
*
\
self
.
pagemap_entry_size
with
open
(
maps_path
,
'r'
)
as
f
:
f
.
seek
(
offset
,
0
)
self
.
page
=
\
(
struct
.
unpack
(
'Q'
,
f
.
read
(
self
.
pagemap_entry_size
))[
0
])
\
&
0x7FFFFFFFFFFFFF
def
display
(
self
):
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
for
addr
in
range
(
self
.
start_addr
,
self
.
end_addr
+
4
,
4
):
page_addr
=
addr
&
(
~
(
self
.
page_size
-
1
))
if
(
addr
==
self
.
start_addr
)
or
((
addr
&
0x3f
)
==
0
):
print
(
"
\n
0x
%08
x:"
%
addr
),
page_offs
=
addr
-
page_addr
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
]
print
(
"
%08
x"
%
d
),
mm
.
close
()
def
fill
(
self
,
value
=
0x1e
):
with
open
(
"/dev/mem"
,
"r+b"
)
as
f
:
count
=
0
for
addr
in
range
(
self
.
start_addr
,
self
.
end_addr
,
1
):
page_addr
=
addr
&
(
~
(
self
.
page_size
-
1
))
if
page_addr
!=
self
.
start_addr
&
(
~
(
self
.
page_size
-
1
)):
break
page_offs
=
addr
-
page_addr
mm
=
mmap
.
mmap
(
f
.
fileno
(),
self
.
page_size
,
offset
=
page_addr
)
mm
[
page_offs
]
=
struct
.
pack
(
"B"
,
value
)
count
+=
1
mm
.
close
()
print
(
str
(
count
)
+
" bytes written."
)
def
get_address
(
self
):
return
self
.
start_addr
def
get_size
(
self
):
return
self
.
size
\ No newline at end of file
libelphel.c
0 → 100644
View file @
a58c228e
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/mman.h>
char
*
malloc_and_mlock
(
size_t
size
)
{
char
*
buffer
;
unsigned
long
i
;
buffer
=
(
char
*
)
valloc
(
size
);
if
(
buffer
!=
0
)
{
mlockall
(
MCL_CURRENT
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
buffer
[
i
]
=
0x1e
;
}
}
return
buffer
;
}
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