使用 cocotb 在列表中生成一个协程

我有一个协程,它等待一个事件被设置:


@cocotb.coroutine

def wb_RXDR_read(self):

    """ waiting util RXDR is read """

    if not self._RXDR_read_flag:

        while True:

            yield self._RXDR_read_event.wait()

            break

我想在超时的情况下“屈服”。然后要做到这一点,我这样做了:


        RXDR_timeout = Timer(250, units="us")

        ret = yield [RXDR_timeout, self.wb_RXDR_read()]

        if ret == RXDR_timeout:

            self._dut._log.error("Timeout on waiting RXDR to be read")

            raise TestError()

但我收到此错误:


2ns ERROR    Coroutine i2c_write yielded something the scheduler can't handle

                      Got type: <type 'list'> repr: [<cocotb.triggers.Timer object at 0x7f2098cb1350>, <cocotb.decorators.RunningCoroutine object at 0x7f2098cb1610>] str: [<cocotb.triggers.Timer object at 0x7f2098cb1350>, <cocotb.decorators.RunningCoroutine object at 0x7f2098cb1610>]

                      Did you forget to decorate with @cocotb.coroutine?

我的协程用@cocotb.coroutine 装饰。如果我单独屈服它有效:


yield self.wb_RXDR_read() # <- that works

但我不能把它放在一个列表中。是否可以将协程放在一个列表中以像 unix select() 那样阻塞?还是保留给 Trigger 类?


holdtom
浏览 290回答 1
1回答

aluckdog

我有一个协程,它等待一个事件被设置:@cocotb.coroutinedef wb_RXDR_read(self):&nbsp; &nbsp; """ waiting util RXDR is read """&nbsp; &nbsp; if not self._RXDR_read_flag:&nbsp; &nbsp; &nbsp; &nbsp; while True:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield self._RXDR_read_event.wait()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break我想在超时的情况下“屈服”。然后要做到这一点,我这样做了:&nbsp; &nbsp; &nbsp; &nbsp; RXDR_timeout = Timer(250, units="us")&nbsp; &nbsp; &nbsp; &nbsp; ret = yield [RXDR_timeout, self.wb_RXDR_read()]&nbsp; &nbsp; &nbsp; &nbsp; if ret == RXDR_timeout:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._dut._log.error("Timeout on waiting RXDR to be read")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise TestError()但我收到此错误:2ns ERROR&nbsp; &nbsp; Coroutine i2c_write yielded something the scheduler can't handle&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Got type: <type 'list'> repr: [<cocotb.triggers.Timer object at 0x7f2098cb1350>, <cocotb.decorators.RunningCoroutine object at 0x7f2098cb1610>] str: [<cocotb.triggers.Timer object at 0x7f2098cb1350>, <cocotb.decorators.RunningCoroutine object at 0x7f2098cb1610>]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Did you forget to decorate with @cocotb.coroutine?我的协程用@cocotb.coroutine 装饰。如果我单独屈服它有效:yield self.wb_RXDR_read() # <- that works但我不能把它放在一个列表中。是否可以将协程放在一个列表中以像 unix select() 那样阻塞?还是保留给 Trigger 类?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python