Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
low-level-link-speed-tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jake Read
low-level-link-speed-tests
Commits
f519abd7
Commit
f519abd7
authored
1 year ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
prelim spi tests with mechanics intact
parent
54ac2a07
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpi_spi/code/spi_controller/pi_spi.py
+40
-8
40 additions, 8 deletions
rpi_spi/code/spi_controller/pi_spi.py
rpi_spi/code/spi_controller/plot_stamps.py
+43
-0
43 additions, 0 deletions
rpi_spi/code/spi_controller/plot_stamps.py
with
83 additions
and
8 deletions
rpi_spi/code/spi_controller/pi_spi.py
+
40
−
8
View file @
f519abd7
import
spidev
import
spidev
,
time
# import numpy as np
# from plot_stamps import plot_stamps
bitrate
=
1000000
bitrate
=
1000000
0
print
(
f
'
rate
{
bitrate
/
1e6
}
MBit/s bit period should be
{
1000000000
/
bitrate
}
ns
'
)
spi
=
spidev
.
SpiDev
()
spi
.
open
(
0
,
0
)
spi
.
max_speed_hz
=
bitrate
spi
.
mode
=
0b
0
0
spi
.
mode
=
0b
1
0
test_pck
=
bytearray
(
32
)
pck_len
=
64
stamp_count
=
10000
# stamps = np.zeros(stamp_count)
test_pck
=
bytearray
(
pck_len
)
for
b
in
range
(
len
(
test_pck
)):
test_pck
[
b
]
=
b
test_pck
[
b
]
=
b
+
1
print
(
test_pck
)
for
i
in
range
(
1000
):
# TODO will be to finish making these plots,
# need to install pandas and numpy here w a venv
# for now I'm just going to turn the rate up until things go wrong
bonked
=
False
for
i
in
range
(
stamp_count
):
if
bonked
:
break
ret
=
spi
.
xfer
(
test_pck
)
print
(
ret
)
# stamps[i] = time.perf_counter() * 1e6
start
=
-
1
for
j
in
range
(
len
(
ret
)):
if
start
==
-
1
:
if
ret
[
j
]
==
0
:
start
=
j
continue
else
:
if
ret
[
j
]
!=
j
-
start
:
print
(
f
'
BONK at
{
i
}
char
{
j
}
{
start
}
{
ret
[
j
]
}
'
)
print
(
ret
)
bonked
=
True
break
spi
.
close
()
# plot_stamps(stamps, stamp_count, pck_len)
spi
.
close
()
\ No newline at end of file
# 1Mbit seems solid,
# 2.5Mbit and we have very occasional starvation
# 5Mbit and we have at least one bad packet every run (1/1000?)
# 5Mbit with more F_CPU (250MHz) it is obviously improved (1/5000?)
# 10Mbit at 250MHz we are back to ~ (1/2000) starvations,
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rpi_spi/code/spi_controller/plot_stamps.py
0 → 100644
+
43
−
0
View file @
f519abd7
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
def
plot_stamps
(
stamps
,
stamp_count
,
pck_len
):
# make df from stamps
df
=
pd
.
DataFrame
({
'
timestamps
'
:
stamps
})
# calculate deltas between stamps
df
[
'
deltas
'
]
=
df
[
'
timestamps
'
].
diff
()
# clean NaN's
df
=
df
.
dropna
()
# wipe obviously-wrong deltas (i.e. the 1st, which goes 0-start-us)
df
=
df
[
df
[
'
deltas
'
]
<
10000
]
# Plotting
fig
,
ax1
=
plt
.
subplots
(
figsize
=
(
11
,
3
))
ax1
.
set_xlim
([
50
,
2000
])
# Primary x-axis (time deltas)
df
[
'
deltas
'
].
plot
(
kind
=
'
hist
'
,
bins
=
50
,
ax
=
ax1
)
ax1
.
set_xlabel
(
'
Time-Stamp Deltas (us) and equivalent (MBits/s)
'
)
ax1
.
set_ylabel
(
f
'
Frequency (of
{
stamp_count
}
)
'
)
# get axis ticks to calculate equivalent bandwidths
x_ticks
=
ax1
.
get_xticks
()
ax1
.
set_xticks
(
x_ticks
)
bandwidths
=
[((
pck_len
*
8
)
*
(
1e6
/
x
))
/
1e6
for
x
in
x_ticks
]
ticks
=
[]
for
i
in
range
(
len
(
x_ticks
)):
print
(
i
,
x_ticks
[
i
],
bandwidths
[
i
])
ticks
.
append
(
f
"
{
x_ticks
[
i
]
:
.
0
f
}
(
{
bandwidths
[
i
]
:
.
3
f
}
)
"
)
ax1
.
set_xticklabels
(
ticks
)
plt
.
title
(
f
'
Single-Source COBS Data Sink Deltas, pck_len=
{
pck_len
}
'
)
plt
.
tight_layout
()
plt
.
show
()
\ No newline at end of file
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