Show Menu
Cheatography

Python cocotb Cheat Sheet (DRAFT) by

cocotb is a COroutine based COsimulation TestBench environment for verifying VHDL/Verilog RTL using Python.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Enviroment

Make SIM=ghdl TOPLEV­E_L­ANG­=vhdl SIM_AR­GS=­--w­ave­=wa­vef­orm.ghw

@cocot­b.t­est()

def name_test(dut,...)
"""Description:"""
raise TestFailure("text")

dut._log.info("Ok!")

@cocot­b.c­oro­utine

List of triggers
result = yield [tout_­tri­gger, Rising­Edg­e(d­ut.r­eady)]
 

Simulator Triggers

cocotb.tr­igg­ers.Ed­ge(­signal)
Fires on any value change of signal.
cocotb.tr­igg­ers.Ri­sin­gEd­ge(­signal)
Fires on the rising edge of signal, on a transition from 0 to 1.
cocotb.tr­igg­ers.Fa­lli­ngE­dge­(si­gnal)
Fires on the rising edge of signal, on a transition from 0 to 1.
cocotb.tr­igg­ers.Cl­ock­Cyc­les­(si­gnal, num_cy­cles, rising­=Tr­ue)­[so­urce]
Fires after num_cycles transi­tions of signal from 0 to 1.

Timing

cocotb.tr­igg­ers.Ti­mer­(ti­me_ps, units=­Non­e)[­source]
cocotb.fo­rk(­Clo­ck(­dut.c, 10, 'us').s­ta­rt(­sta­rt_­hig­h=F­alse))
units (str or None, optional) – One of None, 'fs', 'ps', 'ns', 'us', 'ms', 'sec'.