def host_expect_packet(self, packet, msg=None):
        self.monitor.prime()
        result = yield self.monitor.wait_for_recv(1e9)  # 1 ms max
        if result is None:
            current = get_sim_time("us")
            raise TestFailure(f"No full packet received @{current}")

        yield RisingEdge(self.dut.clk48_host)
        self.dut.usb_d_p = 1
        self.dut.usb_d_n = 0

        # Check the packet received matches
        expected = pp_packet(wrap_packet(packet))
        actual = pp_packet(result)
        nak = pp_packet(wrap_packet(handshake_packet(PID.NAK)))
        if (actual == nak) and (expected != nak):
            self.dut._log.warning("Got NAK, retry")
            yield Timer(self.RETRY_INTERVAL, 'us')
            return
        else:
            self.retry = False
            if expected == actual:
                #self.dut._log.info("Received expected {}".format(msg))
                Analyze.received(actual)
            else:
                #self.dut._log.warning(msg)
                Analyze.explain(actual, expected)
                raise TestError(msg)
Esempio n. 2
0
    def host_send(self, data01, addr, epnum, data, expected=PID.ACK):
        """Send data out the virtual USB connection, including an OUT token."""
        self.retry = True
        while self.retry:
            # Do we still have time?
            current = get_sim_time("us")
            self.dut._log.info("Sending data at {:.0f}, deadline {:.0f}"
                               .format(current, self.packet_deadline))
            if current > self.packet_deadline:
                raise TestFailure("Did not finish data transfer in time")

            yield self.host_send_token_packet(PID.OUT, addr, epnum)
            yield self.host_send_data_packet(data01, data)
            yield self.host_expect_packet(handshake_packet(expected),
                                          "Expected {} packet."
                                          .format(expected))
Esempio n. 3
0
 def host_expect_stall(self):
     """Expect a STALL packet."""
     yield self.host_expect_packet(handshake_packet(PID.STALL),
                                   "Expected STALL packet.")
Esempio n. 4
0
 def host_expect_nak(self):
     """Expect a NAK packet."""
     yield self.host_expect_packet(handshake_packet(PID.NAK),
                                   "Expected NAK packet.")
Esempio n. 5
0
 def host_expect_ack(self):
     """Expect an ACK packet."""
     yield self.host_expect_packet(handshake_packet(PID.ACK),
                                   "Expected ACK packet.")
Esempio n. 6
0
 def host_send_ack(self):
     yield self._host_send_packet(handshake_packet(PID.ACK))