Python APIs
Common functions
- async interfaces.common_functions.test_functions.test_configure(dut: SimHandle, timeout_cycles=1000000, clk=25, timeout_precision=0.2, num_error=3, start_up=True) Caravel_env [source]
Configure caravel power, clock, and reset and setup the timeout watchdog then return object of caravel environment.
- Parameters:
dut (SimHandle) – dut handle
timeout_cycles (int) – Number of cycles before reporting timeout and exit the test default = 1000000 cycles
clk (int) – The clock period to be used in the design in
'ns'
default 12.5'ns'
timeout_precision (int) – Precision of logging how many cycle left until the timeout default is 0.2 meaning if time is 100 cycle every 20 cycles there would be a warning message for timeout
num_error (int) – Maximum number of errors reported before terminate the test
start_up (bool) – start up the test connecting power and reset
- Returns:
Object of type Caravel_env (caravel environment)
Caravel Environment
- class interfaces.caravel.Caravel_env(dut: SimHandleBase)[source]
Verification environment for caraval - provide APIs for monitoring and driving caravel GPIOs, power pins, clock and reset pins :param SimHandle dut: dut handle
- async disable_csb()[source]
Set the SPI CSB signal high to disable housekeeping SPI transmission pin E8 mprj[3]
- async enable_csb()[source]
Set the SPI CSB signal low to enable housekeeping SPI transmission pin E8 mprj[3]
- monitor_gpio(h_bit, l_bit=None) BinaryValue [source]
monitor GPIOs output value
- Parameters:
- Raises:
exception – If h_bit is lower than l_bit
- Returns:
cocotb.binary.BinaryValue
Example:
monitor_gpio(7) #get output value of GPIO 7 (GPIOs[7]) monitor_gpio(7,0) # get output value from GPIO 7 to 0 (GPIOs[7:0]) monitor_gpio((7,0)) #get output value from GPIO 7 to 0 (GPIOs[7:0])
- monitor_mgmt_gpio() str [source]
monitor management GPIO output
- Returns:
return the value of management GPIO in string format possible values
"0"
"1"
"X"
"Z"
- monitor_discontinuous_gpios(arr: list) str [source]
monitor discontinuous GPIOs output value
- Parameters:
arr (list(ints) or tuple(ints)) – highest GPIO number of the tuple of (high GPIO, low GPIO)
- Returns:
str
Example:
monitor_discontinuous_gpios([3,2,5]]) #return the value at 3,1,5 in str, str[0] = gpio[5], str[-1]=gpio[3]
- drive_gpio_in(bits, data) None [source]
drive input GPIOs with specific data
- Parameters:
Example:
drive_gpio_in(7,0x1) # drive GPIO 7 with 1 (GPIOs[7]=1) drive_gpio_in((31,0),0xFFFFFFFF) # drive GPIO 31 to 0 with ones (GPIOs[31:0]=32'hFFFFFFFF)
- release_gpio(bits)[source]
release driving the value of mprj bits :param bits: GPIOs to drive :type bits: int or tuple(int, int)
- drive_mgmt_gpio(data)[source]
drive GPIO management with specific data
- Parameters:
data (int) – data to drive the GPIOs with
SPI Environment
- class interfaces.SPI.SPI(caravelEnv: Caravel_env, clk_period=None, spi_pins={'CSB': 3, 'SCK': 4, 'SDI': 1, 'SDO': 2})[source]
The interface is acting as an spi master. It communicates mainly with the slave inside the housekeeping
- Parameters:
caravelEnv (Caravel_env) – The Caravel environment object to use.
clk_period (float or None) – The clock period in microseconds, or None to use the default (3 times the Caravel clock period).
spi_pins (dict[str, int]) – The SPI pins to use, as a dictionary with keys “CSB”, “SCK”, “SDO”, and “SDI”.
- async disable_csb()[source]
Disables the housekeeping SPI transmission by driving the CSB line high.
Note: The function waits for 2 clock cycles before disabling to ensure that the previous writing command has been applied. It then drives the CSB line high and kills the SPI clock.Finally, the function waits for some time to ensure that the disable has taken effect.
- async enable_csb()[source]
Enable the chip select bar (CSB) pin for SPI transmission.
Note: This method drives the CSB pin low and sets up the SPI clock. It also waits for some time after disabling the CSB pin for the changes to take effect.
- async write_reg_spi(address, data, disable_csb: bool = True)[source]
Writes a register over SPI using the housekeeping SPI bus.
- async read_reg_spi(address, disable_csb: bool = True)[source]
Reads a byte from a register at the given address over the housekeeping SPI interface.
- async read_write_reg_spi(address, data, disable_csb: bool = True)[source]
Writes to and reads from a register at the given SPI address using the housekeeping SPI.
- Parameters:
- Returns:
int: The data read from the register.
- Examples:
>>> result = await read_write_reg_spi(0x14, 0xAB) >>> print(hex(result)) 0x42 >>> result = await read_write_reg_spi(0x14, 0xD7) >>> print(hex(result)) 0xAB
- async write_reg_spi_nbytes(address, data, n_bytes, disable_csb: bool = True)[source]
Writes to n_bytes bytes starting from the register at address over the housekeeping SPI.
- async read_reg_spi_nbytes(address, n_bytes, disable_csb: bool = True)[source]
Read n_bytes bytes starting from the register at address over the housekeeping SPI.
- async read_write_reg_nbytes(address, data_in, n_bytes, disable_csb: bool = True)[source]
Read and write n_bytes bytes starting from the register at address over the housekeeping SPI.
- Parameters:
- Returns:
A list with n_bytes integers, where each integer is a byte read from the register.
- async reg_spi_user_pass_thru(send_data: list, read_byte_num: int = 0, disable_csb: bool = True)[source]
Sends SPI data to a housekeeping SPI using user pass-thru command.
- Parameters:
- Returns:
A list of read data if read_byte_num is not 0.
- async reg_spi_mgmt_pass_thru_read(address: int, read_byte_num: int = 1, disable_csb: bool = True)[source]
Sends SPI read data command to a housekeeping SPI using managment pass-thru command.
- async reg_spi_op(command, address, disable_csb: bool = True)[source]
Perform a register SPI operation.
- class SPI_COMMAND(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
enum class representing SPI command bytes.
- members:
- NO_OP:
A command byte representing a no-op operation.
- WRITE_STREAM:
A command byte representing a write stream operation.
- READ_STREAM:
A command byte representing a read stream operation.
- WRITE_READ:
A command byte representing a write-and-read operation.
- USER_PASS_THRU:
A command byte representing a user pass-through operation.
- MGMT_PATH_THRU:
A command byte representing a management path pass-through operation.
UART Environment
- class interfaces.UART.UART(caravelEnv: Caravel_env, uart_pins={'rx': 5, 'tx': 6})[source]
UART Verification environment to provide APIs to communicate with caravel UART through caravel gpios
- Parameters:
caravelEnv (Caravel_env) – caravel environment
- async get_line()[source]
Read line sent through UART (msg is sent by the software)
Line is a bunch of ASCII sybmols ended by linefeed ‘\n’
- async get_char()[source]
Read character sent through UART (character is sent by the software)
Character is a 8 bit ASCII symbol