Skip to content

components

General stream components.

Serializer

Bases: Component

Serializer converting a stream with an array payload into a stream of individual elements.

Parameters:

Name Type Description Default
shape ArrayLayout

Shape of the input stream.

required

Attributes:

Name Type Description
input stream

Input stream with an array payload.

output stream

Output stream of individual elements.

Source code in katsuo/stream/components.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Serializer(wiring.Component):
    '''Serializer converting a stream with an array payload into a stream of individual elements.

    Args:
        shape: Shape of the input stream.

    Attributes:
        input (stream): Input stream with an array payload.
        output (stream): Output stream of individual elements.
    '''

    def __init__(self, shape: data.ArrayLayout):
        assert isinstance(shape, data.ArrayLayout)

        super().__init__({
            'input': wiring.In(stream.Signature(shape)),
            'output': wiring.Out(stream.Signature(shape.elem_shape)),
        })

        self.shape = shape

    def elaborate(self, platform):
        m = Module()

        idx = Signal(range(self.shape.length))

        m.d.comb += [
            self.input.ready.eq(self.output.ready & (idx == self.shape.length - 1)),
            self.output.valid.eq(self.input.valid),
            self.output.payload.eq(self.input.payload[idx]),
        ]

        with m.If(self.output.valid & self.output.ready):
            m.d.sync += idx.eq(idx + 1)

            with m.If(idx == self.shape.length - 1):
                m.d.sync += idx.eq(0)

        return m