コード例 #1
0
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        for rate, mii in [(1, 0), (10, 0), (5, 1)]:
            clk_enable_rate.next = rate
            mii_select.next = mii

            yield delay(100)

            for payload_len in list(range(1, 18)) + list(range(64, 82)):
                yield clk.posedge
                print("test 1: test packet, length %d" % payload_len)
                current_test.next = 1

                test_frame = eth_ep.EthFrame()
                test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame.eth_src_mac = 0x5A5152535455
                test_frame.eth_type = 0x8000
                test_frame.payload = bytearray(range(payload_len))
                test_frame.update_fcs()

                axis_frame = test_frame.build_axis_fcs()
                gmii_frame = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame))

                source.send(gmii_frame)

                yield sink.wait()
                rx_frame = sink.recv()

                eth_frame = eth_ep.EthFrame()
                eth_frame.parse_axis(rx_frame)
                eth_frame.update_fcs()

                assert eth_frame == test_frame

                assert sink.empty()

                yield delay(100)

                yield clk.posedge
                print("test 2: back-to-back packets, length %d" % payload_len)
                current_test.next = 2

                test_frame1 = eth_ep.EthFrame()
                test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame1.eth_src_mac = 0x5A5152535455
                test_frame1.eth_type = 0x8000
                test_frame1.payload = bytearray(range(payload_len))
                test_frame1.update_fcs()
                test_frame2 = eth_ep.EthFrame()
                test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame2.eth_src_mac = 0x5A5152535455
                test_frame2.eth_type = 0x8000
                test_frame2.payload = bytearray(range(payload_len))
                test_frame2.update_fcs()

                axis_frame1 = test_frame1.build_axis_fcs()
                axis_frame2 = test_frame2.build_axis_fcs()
                gmii_frame1 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame1))
                gmii_frame2 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame2))

                source.send(gmii_frame1)
                source.send(gmii_frame2)

                yield sink.wait()
                rx_frame = sink.recv()

                eth_frame = eth_ep.EthFrame()
                eth_frame.parse_axis(rx_frame)
                eth_frame.update_fcs()

                assert eth_frame == test_frame1

                yield sink.wait()
                rx_frame = sink.recv()

                eth_frame = eth_ep.EthFrame()
                eth_frame.parse_axis(rx_frame)
                eth_frame.update_fcs()

                assert eth_frame == test_frame2

                assert sink.empty()

                yield delay(100)

                yield clk.posedge
                print("test 3: truncated frame, length %d" % payload_len)
                current_test.next = 3

                test_frame1 = eth_ep.EthFrame()
                test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame1.eth_src_mac = 0x5A5152535455
                test_frame1.eth_type = 0x8000
                test_frame1.payload = bytearray(range(payload_len))
                test_frame1.update_fcs()
                test_frame2 = eth_ep.EthFrame()
                test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame2.eth_src_mac = 0x5A5152535455
                test_frame2.eth_type = 0x8000
                test_frame2.payload = bytearray(range(payload_len))
                test_frame2.update_fcs()

                axis_frame1 = test_frame1.build_axis_fcs()
                axis_frame2 = test_frame2.build_axis_fcs()

                axis_frame1.data = axis_frame1.data[:-1]

                error_bad_frame_asserted.next = 0
                error_bad_fcs_asserted.next = 0

                gmii_frame1 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame1))
                gmii_frame2 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame2))

                source.send(gmii_frame1)
                source.send(gmii_frame2)

                yield sink.wait()
                rx_frame = sink.recv()

                assert error_bad_frame_asserted
                assert error_bad_fcs_asserted

                assert rx_frame.user[-1]

                yield sink.wait()
                rx_frame = sink.recv()

                eth_frame = eth_ep.EthFrame()
                eth_frame.parse_axis(rx_frame)
                eth_frame.update_fcs()

                assert eth_frame == test_frame2

                assert sink.empty()

                yield delay(100)

                yield clk.posedge
                print("test 4: errored frame, length %d" % payload_len)
                current_test.next = 4

                test_frame1 = eth_ep.EthFrame()
                test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame1.eth_src_mac = 0x5A5152535455
                test_frame1.eth_type = 0x8000
                test_frame1.payload = bytearray(range(payload_len))
                test_frame1.update_fcs()
                test_frame2 = eth_ep.EthFrame()
                test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
                test_frame2.eth_src_mac = 0x5A5152535455
                test_frame2.eth_type = 0x8000
                test_frame2.payload = bytearray(range(payload_len))
                test_frame2.update_fcs()

                axis_frame1 = test_frame1.build_axis_fcs()
                axis_frame2 = test_frame2.build_axis_fcs()

                error_bad_frame_asserted.next = 0
                error_bad_fcs_asserted.next = 0

                gmii_frame1 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame1))
                gmii_frame2 = gmii_ep.GMIIFrame(
                    b'\x55\x55\x55\x55\x55\x55\x55\xD5' +
                    bytearray(axis_frame2))

                gmii_frame1.error = 1

                source.send(gmii_frame1)
                source.send(gmii_frame2)

                yield sink.wait()
                rx_frame = sink.recv()

                assert error_bad_frame_asserted
                assert not error_bad_fcs_asserted

                assert rx_frame.user[-1]

                yield sink.wait()
                rx_frame = sink.recv()

                eth_frame = eth_ep.EthFrame()
                eth_frame.parse_axis(rx_frame)
                eth_frame.update_fcs()

                assert eth_frame == test_frame2

                assert sink.empty()

                yield delay(100)

        raise StopSimulation
コード例 #2
0
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        for payload_len in list(range(1, 18)) + list(range(64, 82)):
            yield clk.posedge
            print("test 1: test packet, length %d" % payload_len)
            current_test.next = 1

            test_frame = eth_ep.EthFrame()
            test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame.eth_src_mac = 0x5A5152535455
            test_frame.eth_type = 0x8000
            test_frame.payload = bytearray(range(payload_len))
            test_frame.update_fcs()

            axis_frame = test_frame.build_axis_fcs()
            gmii_frame = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame))

            source_queue.put(gmii_frame)
            yield clk.posedge
            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge
            yield clk.posedge
            yield clk.posedge

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            eth_frame = eth_ep.EthFrame()
            eth_frame.parse_axis(rx_frame)
            eth_frame.update_fcs()

            assert eth_frame == test_frame

            assert sink_queue.empty()

            yield delay(100)

            yield clk.posedge
            print("test 2: back-to-back packets, length %d" % payload_len)
            current_test.next = 2

            test_frame1 = eth_ep.EthFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x8000
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.update_fcs()
            test_frame2 = eth_ep.EthFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x8000
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.update_fcs()

            axis_frame1 = test_frame1.build_axis_fcs()
            axis_frame2 = test_frame2.build_axis_fcs()
            gmii_frame1 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame1))
            gmii_frame2 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame2))

            source_queue.put(gmii_frame1)
            source_queue.put(gmii_frame2)
            yield clk.posedge
            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge
            yield clk.posedge
            yield clk.posedge

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            eth_frame = eth_ep.EthFrame()
            eth_frame.parse_axis(rx_frame)
            eth_frame.update_fcs()

            assert eth_frame == test_frame1

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            eth_frame = eth_ep.EthFrame()
            eth_frame.parse_axis(rx_frame)
            eth_frame.update_fcs()

            assert eth_frame == test_frame2

            assert sink_queue.empty()

            yield delay(100)

            yield clk.posedge
            print("test 3: truncated frame, length %d" % payload_len)
            current_test.next = 3

            test_frame1 = eth_ep.EthFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x8000
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.update_fcs()
            test_frame2 = eth_ep.EthFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x8000
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.update_fcs()

            axis_frame1 = test_frame1.build_axis_fcs()
            axis_frame2 = test_frame2.build_axis_fcs()

            axis_frame1.data = axis_frame1.data[:-1]

            error_bad_frame_asserted.next = 0
            error_bad_fcs_asserted.next = 0

            gmii_frame1 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame1))
            gmii_frame2 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame2))

            source_queue.put(gmii_frame1)
            source_queue.put(gmii_frame2)
            yield clk.posedge
            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge
            yield clk.posedge
            yield clk.posedge

            assert error_bad_frame_asserted
            assert error_bad_fcs_asserted

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            assert rx_frame.user[-1]

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            eth_frame = eth_ep.EthFrame()
            eth_frame.parse_axis(rx_frame)
            eth_frame.update_fcs()

            assert eth_frame == test_frame2

            assert sink_queue.empty()

            yield delay(100)

            yield clk.posedge
            print("test 4: errored frame, length %d" % payload_len)
            current_test.next = 4

            test_frame1 = eth_ep.EthFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x8000
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.update_fcs()
            test_frame2 = eth_ep.EthFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x8000
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.update_fcs()

            axis_frame1 = test_frame1.build_axis_fcs()
            axis_frame2 = test_frame2.build_axis_fcs()

            error_bad_frame_asserted.next = 0
            error_bad_fcs_asserted.next = 0

            gmii_frame1 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame1))
            gmii_frame2 = gmii_ep.GMIIFrame(
                b'\x55\x55\x55\x55\x55\x55\x55\xD5' + bytearray(axis_frame2))

            gmii_frame1.error = 1

            source_queue.put(gmii_frame1)
            source_queue.put(gmii_frame2)
            yield clk.posedge
            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge

            while gmii_rx_dv or output_axis_tvalid or not source_queue.empty():
                yield clk.posedge

            yield clk.posedge
            yield clk.posedge
            yield clk.posedge

            assert error_bad_frame_asserted
            assert not error_bad_fcs_asserted

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            assert rx_frame.user[-1]

            rx_frame = None
            if not sink_queue.empty():
                rx_frame = sink_queue.get()

            eth_frame = eth_ep.EthFrame()
            eth_frame.parse_axis(rx_frame)
            eth_frame.update_fcs()

            assert eth_frame == test_frame2

            assert sink_queue.empty()

            yield delay(100)

        raise StopSimulation