Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel LiteX
migen
Commits
7d0e179a
Commit
7d0e179a
authored
12 years ago
by
Sebastien Bourdeauducq
Browse files
Options
Download
Email Patches
Plain Diff
actorlib: structuring (untested)
parent
1576cb09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
migen/actorlib/structuring.py
migen/actorlib/structuring.py
+90
-0
No files found.
migen/actorlib/structuring.py
0 → 100644
View file @
7d0e179a
from
migen.fhdl.structure
import
*
from
migen.flow.actor
import
*
class
Cast
(
CombinatorialActor
):
def
__init__
(
self
,
layout_from
,
layout_to
):
super
().
__init__
(
(
"sink"
,
Sink
,
layout_from
),
(
"source"
,
Source
,
layout_to
))
def
get_process_fragment
(
self
):
sigs_from
=
self
.
token
(
"sink"
).
flatten
()
sigs_to
=
self
.
token
(
"source"
).
flatten
()
if
sum
(
len
(
s
)
for
s
in
sigs_from
)
!=
sum
(
len
(
s
)
for
s
in
sigs_to
):
raise
TypeError
return
Fragment
([
Cat
(
*
sigs_to
).
eq
(
Cat
(
*
sigs_from
))
])
class
Chop
(
Actor
):
def
__init__
(
self
,
n
,
layout_to
):
self
.
n
=
n
layout_from
=
[(
"chunk{0}"
.
format
(
i
),
layout_to
)
for
i
in
range
(
self
.
n
)]
super
().
__init__
(
(
"sink"
,
Sink
,
layout_from
),
(
"source"
,
Source
,
layout_to
))
def
get_fragment
(
self
):
muxbits
=
bits_for
(
self
.
n
-
1
)
mux
=
Signal
(
BV
(
muxbits
))
last
=
Signal
()
comb
=
[
last
.
eq
(
mux
==
(
self
.
n
-
1
)),
self
.
endpoints
[
"source"
].
stb
.
eq
(
self
.
endpoints
[
"sink"
].
stb
),
self
.
endpoints
[
"sink"
].
ack
.
eq
(
last
&
self
.
endpoints
[
"source"
].
ack
)
]
sync
=
[
If
(
self
.
endpoints
[
"source"
].
stb
&
self
.
endpoints
[
"source"
].
ack
,
If
(
last
,
mux
.
eq
(
0
)
).
Else
(
mux
.
eq
(
mux
+
1
)
)
)
]
cases
=
[(
Constant
(
i
,
BV
(
muxbits
)),
Cat
(
*
self
.
token
(
"source"
).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()))
for
i
in
range
(
self
.
n
)]
cases
[
-
1
][
0
]
=
Default
()
comb
.
append
(
Case
(
mux
,
*
cases
))
return
Fragment
(
comb
,
sync
)
class
Pack
(
Actor
):
def
__init__
(
self
,
layout_from
,
n
):
self
.
n
=
n
layout_to
=
[(
"chunk{0}"
.
format
(
i
),
layout_from
)
for
i
in
range
(
self
.
n
)]
super
().
__init__
(
(
"sink"
,
Sink
,
layout_from
),
(
"source"
,
Source
,
layout_to
))
def
get_fragment
(
self
):
demuxbits
=
bits_for
(
self
.
n
-
1
)
demux
=
Signal
(
BV
(
demuxbits
))
load_part
=
Signal
()
strobe_all
=
Signal
()
cases
=
[(
Constant
(
i
,
BV
(
demuxbits
)),
Cat
(
*
self
.
token
(
"source"
).
subrecord
(
"chunk{0}"
.
format
(
i
)).
flatten
()).
eq
(
*
self
.
token
(
"sink"
).
flatten
())
for
i
in
range
(
self
.
n
)]
comb
=
[
self
.
endpoints
[
"sink"
].
ack
.
eq
(
~
strobe_all
|
self
.
endpoints
[
"source"
].
ack
),
self
.
endpoints
[
"source"
].
stb
.
eq
(
strobe_all
),
load_part
.
eq
(
self
.
endpoints
[
"sink"
].
stb
&
self
.
endpoints
[
"sink"
].
ack
)
]
sync
=
[
If
(
self
.
endpoints
[
"source"
].
ack
,
strobe_all
.
eq
(
0
)
),
If
(
load_part
,
Case
(
demux
,
*
cases
),
If
(
demux
==
(
self
.
n
-
1
),
demux
.
eq
(
0
),
strobe_all
.
eq
(
1
)
).
Else
(
demux
.
eq
(
demux
+
1
)
)
)
]
return
Fragment
(
comb
,
sync
)
This diff is collapsed.
Click to expand it.
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