Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python_test_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
python_test_scripts
Commits
110f86a6
Commit
110f86a6
authored
4 years ago
by
Gijs Schoonderbeek
Browse files
Options
Downloads
Patches
Plain Diff
Added MDIO read function.
parent
6bf954bc
Branches
Branches containing commit
No related tags found
1 merge request
!2
Modified the scripts to run on Raspberry Pi.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mdio.py
+153
-70
153 additions, 70 deletions
mdio.py
with
153 additions
and
70 deletions
mdio.py
+
153
−
70
View file @
110f86a6
...
@@ -6,6 +6,8 @@ import time as time
...
@@ -6,6 +6,8 @@ import time as time
ClockPin
=
23
ClockPin
=
23
DataPin
=
22
DataPin
=
22
def
write_mdio
(
wr_data
=
0x16
):
print
(
"
write data
"
)
print
(
"
write data
"
)
phy_reg
=
0x16
phy_reg
=
0x16
...
@@ -18,7 +20,7 @@ phy_addr_bits = "{:0>5b}".format(phy_addr)
...
@@ -18,7 +20,7 @@ phy_addr_bits = "{:0>5b}".format(phy_addr)
stri
=
"
Phy addr bits is {}
"
.
format
(
phy_addr_bits
)
stri
=
"
Phy addr bits is {}
"
.
format
(
phy_addr_bits
)
print
(
stri
)
print
(
stri
)
phy_data
=
0x16
phy_data
=
wr_data
phy_data_bits
=
"
{:0>16b}
"
.
format
(
phy_reg
)
phy_data_bits
=
"
{:0>16b}
"
.
format
(
phy_reg
)
stri
=
"
Phy data bits is {}
"
.
format
(
phy_data_bits
)
stri
=
"
Phy data bits is {}
"
.
format
(
phy_data_bits
)
print
(
stri
)
print
(
stri
)
...
@@ -43,15 +45,15 @@ GPIO.output(ClockPin, True)
...
@@ -43,15 +45,15 @@ GPIO.output(ClockPin, True)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
DataPin
,
True
)
GPIO
.
output
(
DataPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
Tru
e
)
GPIO
.
output
(
ClockPin
,
Fals
e
)
# Operant Write
# Operant Write
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
DataPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
# Phy address
# Phy address
for
bit
in
phy_addr_bits
:
for
bit
in
phy_addr_bits
:
...
@@ -85,5 +87,86 @@ for bit in phy_data_bits:
...
@@ -85,5 +87,86 @@ for bit in phy_data_bits:
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
cleanup
()
def
read_mdio
():
print
(
"
write data
"
)
phy_reg
=
0x16
phy_reg_bits
=
"
{:0>5b}
"
.
format
(
phy_reg
)
stri
=
"
Phy reg bits is {}
"
.
format
(
phy_reg_bits
)
print
(
stri
)
phy_addr
=
0x1E
phy_addr_bits
=
"
{:0>5b}
"
.
format
(
phy_addr
)
stri
=
"
Phy addr bits is {}
"
.
format
(
phy_addr_bits
)
print
(
stri
)
# Set IO pins to right mode
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setup
(
ClockPin
,
GPIO
.
OUT
)
GPIO
.
setup
(
DataPin
,
GPIO
.
OUT
)
# Preamble
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
False
)
for
preamble_cnt
in
range
(
32
):
GPIO
.
output
(
ClockPin
,
True
)
# time.sleep(0.1)
GPIO
.
output
(
ClockPin
,
False
)
# time.sleep(0.1)
# Start of Frame
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
DataPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
# Operant Read
GPIO
.
output
(
DataPin
,
True
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
# Phy address
for
bit
in
phy_addr_bits
:
if
bit
==
'
1
'
:
GPIO
.
output
(
DataPin
,
True
)
else
:
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
# phy reg
for
bit
in
phy_reg_bits
:
if
bit
==
'
1
'
:
GPIO
.
output
(
DataPin
,
True
)
else
:
GPIO
.
output
(
DataPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
setup
(
DataPin
,
GPIO
.
IN
)
# TA
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
GPIO
.
output
(
ClockPin
,
True
)
GPIO
.
output
(
ClockPin
,
False
)
# data
data
=
[]
for
bit
in
phy_data_bits
:
GPIO
.
output
(
ClockPin
,
True
)
data
.
append
(
GPIO
.
input
(
DataPin
))
GPIO
.
output
(
ClockPin
,
False
)
print
(
data
)
GPIO
.
cleanup
()
GPIO
.
cleanup
()
write_mdio
(
0x16
)
read_mdio
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment