Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC DEL 1ns 2cha
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC DEL 1ns 2cha
Commits
6a247f09
Commit
6a247f09
authored
Aug 15, 2016
by
Jan Pospisil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added debug trace for SV testbench; added WaitForNotBusy function
parent
75016619
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
9 deletions
+55
-9
FFPG_driver.py
sw/FFPG_driver.py
+55
-9
No files found.
sw/FFPG_driver.py
View file @
6a247f09
#!/usr/bin/env python
import
sys
import
time
sys
.
path
.
append
(
'/usr/local/encore'
)
import
encoreio
...
...
@@ -19,7 +20,17 @@ class ConColors:
m
=
encoreio
.
Module
.
get_instance
(
'fmc_fpg'
,
0
)
WB_DEBUG
=
False
WB_DEBUG
=
True
WB_DEBUG_2_SV
=
True
WB_DEBUG_2_SV_FILE
=
'wb_trace.svh'
###################################################################
## debug preparation
###################################################################
if
WB_DEBUG_2_SV
:
WB_DEBUG_2_SV_FP
=
open
(
WB_DEBUG_2_SV_FILE
,
'w'
)
WB_DEBUG_2_SV_FP
.
write
(
'uint32_t dataOut; // how to not-to-use output port from task?
\n\n
'
)
###################################################################
## WishBone access overlay
...
...
@@ -29,11 +40,18 @@ def WbRead(register):
result
=
m
.
read
(
register
)[
0
]
if
WB_DEBUG
:
print
(
ConColors
.
MAGENTA
+
'WB_READ:'
+
ConColors
.
NONE
+
' ['
+
register
+
'] = '
+
hex
(
result
))
if
WB_DEBUG_2_SV
:
address
=
int
(
m
[
register
][
'offset'
],
16
)
WB_DEBUG_2_SV_FP
.
write
(
'WbRead('
+
str
(
address
)
+
', dataOut, "WB_READ: '
+
register
+
':");
\n
'
)
WB_DEBUG_2_SV_FP
.
write
(
'assert (dataOut == '
+
str
(
result
)
+
') else $error("WB_READ different, result should be '
+
hex
(
int
(
result
))
+
'!");
\n
'
)
return
result
def
WbWrite
(
register
,
data
):
if
WB_DEBUG
:
print
(
ConColors
.
CYAN
+
'WB_WRITE:'
+
ConColors
.
NONE
+
' ['
+
register
+
'] <- '
+
hex
(
data
))
if
WB_DEBUG_2_SV
:
address
=
int
(
m
[
register
][
'offset'
],
16
)
WB_DEBUG_2_SV_FP
.
write
(
'WbWrite('
+
str
(
address
)
+
', '
+
str
(
data
)
+
', "WB_WRITE: '
+
register
+
':");
\n
'
)
m
.
write
(
register
,
(
data
,))
def
WbSetBits
(
register
,
mask
,
bits
):
...
...
@@ -64,7 +82,25 @@ def WbSetBitsMulti(register, mask, bits, start = 0, to = -1):
values
[
i
]
&=
(
~
mask
[
i
])
values
[
i
]
|=
(
bits
[
i
]
&
mask
[
i
])
WbWriteMulti
(
register
,
values
,
start
,
to
)
# timeOut in [s] (floating point)
# polarity = 1: (register.bit == 1) <=> BUSY, wait for 0
# polarity = 0: (register.bit == 0) <=> BUSY, wait for 1
def
WaitForNotBusy
(
register
,
bit
,
timeOut
,
tries
,
message
=
''
,
polarity
=
1
):
busy
=
True
for
i
in
range
(
tries
):
if
(
WbRead
(
register
)
&
(
1
<<
bit
))
!=
polarity
:
busy
=
False
break
# wait for timeOut seconds
timeToWait
=
timeOut
while
timeToWait
>
0
:
timeBegin
=
time
.
time
()
time
.
sleep
(
timeToWait
)
timeToWait
-=
time
.
time
()
-
timeBegin
if
busy
:
raise
Exception
(
'WaitForNotBusy error: '
+
message
)
###################################################################
## SPI functions
###################################################################
...
...
@@ -75,12 +111,14 @@ def SpiInit():
WbWrite
(
'spi_ctrl'
,
0x2618
)
def
SpiRead
(
register
):
WaitForNotBusy
(
'spi_ctrl'
,
8
,
0.001
,
2
,
'SPI read'
)
inst
=
0x800000
|
((
register
&
0xff
)
<<
8
)
WbWrite
(
'spi_tx_rx_0'
,
inst
)
WbSetBits
(
'spi_ctrl'
,
0x100
,
0x100
)
return
WbRead
(
'spi_tx_rx_0'
)
def
SpiWrite
(
register
,
data
):
WaitForNotBusy
(
'spi_ctrl'
,
8
,
0.001
,
2
,
'SPI write'
)
inst
=
0x000000
|
((
register
&
0xff
)
<<
8
)
|
(
data
&
0xff
)
WbWrite
(
'spi_tx_rx_0'
,
inst
)
WbSetBits
(
'spi_ctrl'
,
0x100
,
0x100
)
...
...
@@ -94,7 +132,7 @@ def Ad9512Init():
SpiWrite
(
0x3f
,
0x03
)
# fine delay
SpiWrite
(
0x34
,
0x0
)
# use fine delay
delay
=
2
# 0-31
delay
=
1
# 0-31
SpiWrite
(
0x36
,
(
delay
&
0x1f
)
<<
1
)
# set fine delay
# select CLK1 input, power down CLK2 input
SpiWrite
(
0x45
,
0x05
)
...
...
@@ -264,7 +302,7 @@ def Init():
WbWrite
(
'control'
,
0
)
SpiInit
()
Ad9512Init
()
SetTriggerThreshold
(
0.5
)
SetTriggerThreshold
(
1
)
SelectClock
(
0
)
SetVcxoFrequency
(
-
0.2105
)
# 125.0000 MHz
ClearMemory
(
0
,
'*'
)
...
...
@@ -275,17 +313,25 @@ def TestPulse(channel = 1):
WbWrite
(
'trig_latency'
,
8
)
start
=
5
length
=
1
length
=
20
stop
=
start
+
length
CreatePulse
(
channel
,
start
+
2
*
channel
,
stop
+
2
*
channel
)
# CreatePulse(channel, 2, 2, 1)
start
+=
1
CreatePulse
(
channel
,
start
+
2
*
channel
,
stop
+
2
*
channel
)
start
+=
1
CreatePulse
(
channel
,
start
+
2
*
channel
,
stop
+
2
*
channel
)
start
+=
1
CreatePulse
(
channel
,
start
+
2
*
channel
,
stop
+
2
*
channel
)
start
+=
1
CreatePulse
(
channel
,
start
+
2
*
channel
,
stop
+
2
*
channel
)
# CreatePulse(channel, 0, 0, 1)
# CreatePulse(channel, 5, 10)
# CreatePulse(channel, 25, 30)
# CreatePulse(channel, 125, 130)
WbWrite
(
'ch'
+
str
(
channel
)
+
'_delay_set'
,
1
)
WbWrite
(
'ch'
+
str
(
channel
)
+
'_delay_res'
,
1
00
)
WbWrite
(
'ch'
+
str
(
channel
)
+
'_delay_set'
,
1
00
)
WbWrite
(
'ch'
+
str
(
channel
)
+
'_delay_res'
,
5
00
)
# start channel
channel
-=
1
channel
%=
2
...
...
@@ -297,6 +343,6 @@ Init()
Control
()
Status
()
TestPulse
(
1
)
TestPulse
(
2
)
#
TestPulse(2)
Control
()
Status
()
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