remove cocotb directory since it is moved under other repos

This commit is contained in:
M0stafaRady 2023-09-19 23:08:03 +03:00 committed by GitHub
parent 7f820d899a
commit 0e3b9dded8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
116 changed files with 0 additions and 13899 deletions

View File

@ -1,12 +0,0 @@
*.log
sim_build
sim
__pycache__
*.
./wb_models/housekeepingWB/__pycache__
*.xml
*.yml
*.hex*
*.elf
AN.DB
includes.v

View File

@ -1,89 +0,0 @@
Overview
========
Cocotb environment (CTN) is a dynamic simulation testing environment. It's purpose is to speed testing simulation time and get coverage data. The environment is developed using cocotb, an open source coroutine-based co simulation testbench environment for verifying VHDL and SystemVerilog RTL using Python. CTN has 2 main layers: tests and whitebox models. Tests layer contain multiple tests and sequences that can communicate with the caravel (dut) through drivers shown in read at fig 1. Whitebox models layer contain multiple models that should mimic the behavior of each main block inside caravel see fig1. Model is supposed to check if the model is working as expected, if its registers contain the expected values all the time and report coverage of features provided by this block if its tested or not.
<img src="doc/CTN.png" alt="Alt text" title="fig1. caravel testbench environment (read lines are drivers )">
fig1. caravel testbench environment (read lines are drivers )
Prerequisites
=============================
- Docker: [Linux](https://hub.docker.com/search?q=&type=edition&offering=community&operating_system=linux&utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=header) || [Windows](https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=header) || [Mac with Intel Chip](https://desktop.docker.com/mac/main/amd64/Docker.dmg?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=header) || [Mac with M1 Chip](https://desktop.docker.com/mac/main/arm64/Docker.dmg?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=header)
- Python 3.6+ with PIP
- ```docker pull efabless/dv:cocotb```
- iverilog or vcs
- export CARAVEL_ROOT= \<caravel repo root\>
- export MCW_ROOT= \<caravel_mgmt_soc_litex repo root\>
- export PDK_ROOT= \<PDK repo root\>
- export PDK= \<PDK variant sky130A,sky130B,.... \>
run a test
=============================
Use script verify_cocotb.py
```
-h, --help show this help message and exit
-regression REGRESSION, -r REGRESSION
name of regression can found in tests.json
-test TEST [TEST ...], -t TEST [TEST ...]
name of test if no --sim provided RTL will be run
<takes list as input>
-sim SIM [SIM ...] Simulation type to be run RTL,GL&GL_SDF provided only
when run -test <takes list as input>
-testlist TESTLIST, -tl TESTLIST
path of testlist to be run
-tag TAG provide tag of the run default would be regression
name and if no regression is provided would be
run_<random float>_<timestamp>_
-maxerr MAXERR max number of errors for every test before simulation
breaks default = 3
-vcs, -v use vcs as compiler if not used iverilog would be used
-cov enable code coverage
-corner CORNER [CORNER ...], -c CORNER [CORNER ...]
Corner type in case of GL_SDF run has to be provided
-keep_pass_unzip Normally the waves and logs of passed tests would be
zipped. Using this option they wouldn't be zipped
```
Refer to [examples](doc/commands_example/README.md)
Tests
===============
Refer to [tests doc](doc/tests/README.md) for tests list
cocotb directory tree
===============
```
├── caravel.py -> contains driving and mentoring functions for caravel interface
├── caravel_top.sv -> testbench top level
├── cpu.py -> contains driving and mentoring functions for wishbone when disable the cpu
├── hex_files -> folder that contains hex files
├── verify_cocotb.py -> script that run tests and regressions
├── sim -> directory get generate when run a test
│   └── <tag> -> tag of the run
│   ├── <sim type>-<test name> -> test result directory contain all logs and wave related to the test
│   ├── command.log -> command use for this run
│   └── runs.log -> contains status of the run fails and passes tests
├── tests -> directory contains all the tests
├── tests.json -> test list have all the tests, regressions and contain small description about every test
└── wb_models -> contains checkers and models for some caravel blocks
```
How to debug
===============
` TO BE ADDED`

View File

@ -1,432 +0,0 @@
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
import cocotb.simulator
from cocotb.handle import SimHandleBase
from cocotb.handle import Force
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import enum
from cocotb.handle import (
ConstantObject,
HierarchyArrayObject,
HierarchyObject,
ModifiableObject,
NonHierarchyIndexableObject,
SimHandle,
)
from itertools import groupby, product
import interfaces.common as common
from common import GPIO_MODE
from common import MASK_GPIO_CTRL
from common import Macros
def gpio_mode(gpios_values:list):
gpios=[]
for array in gpios_values:
gpio_value = GPIO_MODE(array[1]).name
for gpio in array[0]:
gpios.append((gpio,gpio_value))
cocotb.log.info(f'[caravel][gpio_mode] gpios {gpios}')
return gpios
Carvel_Coverage = coverage_section (
CoverPoint("top.caravel.gpio", vname="gpios mode", xf = lambda gpio ,gpio_mode: (gpio,gpio_mode) ,
bins = list(product(range(38),[e.name for e in GPIO_MODE])))
)
class Caravel_env:
def __init__(self,dut:SimHandleBase):
self.dut = dut
self.clk = dut.clock_tb
self.caravel_hdl = dut.uut
self.hk_hdl = dut.uut.housekeeping
"""start carvel by insert power then reset"""
async def start_up(self):
await self.power_up()
# await self.disable_csb() # no need for this anymore as default for gpio3 is now pullup
await self.reset()
await self.disable_bins()
common.fill_macros(self.dut.macros) # get macros value
async def disable_bins(self):
for i in range(38):
common.drive_hdl(self.dut._id(f"bin{i}_en",False),(0,0),0)
"""setup the vdd and vcc power bins"""
async def power_up(self):
cocotb.log.info(f' [caravel] start powering up')
self.set_vdd(0)
self.set_vcc(0)
await ClockCycles(self.clk, 10)
cocotb.log.info(f' [caravel] power up -> connect vdd' )
self.set_vdd(1)
# await ClockCycles(self.clk, 10)
cocotb.log.info(f' [caravel] power up -> connect vcc' )
self.set_vcc(1)
await ClockCycles(self.clk, 10)
""""reset caravel"""
async def reset(self):
cocotb.log.info(f' [caravel] start resetting')
self.dut.resetb_tb.value = 0
await ClockCycles(self.clk, 20)
self.dut.resetb_tb.value = 1
await ClockCycles(self.clk, 1)
cocotb.log.info(f' [caravel] finish resetting')
def set_vdd(self,value:bool):
self.dut.vddio_tb.value = value
self.dut.vssio_tb.value = 0
self.dut.vddio_2_tb.value = value
self.dut.vssio_2_tb.value = 0
self.dut.vdda_tb.value = value
self.dut.vssa_tb.value = 0
self.dut.vdda1_tb.value = value
self.dut.vssa1_tb.value = 0
self.dut.vdda1_2_tb.value = value
self.dut.vssa1_2_tb.value = 0
self.dut.vdda2_tb.value = value
self.dut.vssa2_tb.value = 0
def set_vcc(self , value:bool):
self.dut.vccd_tb.value = value
self.dut.vssd_tb.value = 0
self.dut.vccd1_tb.value = value
self.dut.vssd1_tb.value = 0
self.dut.vccd2_tb.value = value
self.dut.vssd2_tb.value = 0
"""drive csb signal bin E8 mprj[3]"""
async def drive_csb(self,bit):
self.drive_gpio_in((3,3),bit)
self.drive_gpio_in((2,2),0)
await ClockCycles(self.clk, 1)
"""set the spi vsb signal high to disable housekeeping spi transmission bin E8 mprj[3]"""
async def disable_csb(self ):
cocotb.log.info(f' [caravel] disable housekeeping spi transmission')
await self.drive_csb(1)
"""set the spi vsb signal high impedance """
async def release_csb(self ):
cocotb.log.info(f' [caravel] release housekeeping spi transmission')
self.release_gpio(3)
self.release_gpio(2)
await ClockCycles(self.clk, 1)
"""set the spi vsb signal low to enable housekeeping spi transmission bin E8 mprj[3]"""
async def enable_csb(self ):
cocotb.log.info(f' [caravel] enable housekeeping spi transmission')
await self.drive_csb(0)
"""return the value of mprj in bits used tp monitor the output gpios value"""
def monitor_gpio(self,bits:tuple):
mprj = self.dut.mprj_io_tb.value
size =mprj.n_bits -1 #size of bins array
mprj_out= self.dut.mprj_io_tb.value[size - bits[0]:size - bits[1]]
if(mprj_out.is_resolvable):
cocotb.log.debug(f' [caravel] Monitor : mprj[{bits[0]}:{bits[1]}] = {hex(mprj_out)}')
else:
cocotb.log.debug(f' [caravel] Monitor : mprj[{bits[0]}:{bits[1]}] = {mprj_out}')
return mprj_out
"""return the value of management gpio"""
def monitor_mgmt_gpio(self):
data = self.dut.gpio_tb.value
cocotb.log.debug(f' [caravel] Monitor mgmt gpio = {data}')
return data
"""change the configration of the gpios by overwrite their defaults value then reset
need to take at least 1 cycle for reset """
### dont use back door accessing
async def configure_gpio_defaults(self,gpios_values: list):
gpio_defaults = self.caravel_hdl.gpio_defaults.value
cocotb.log.info(f' [caravel] start cofigure gpio gpios ')
size = gpio_defaults.n_bits -1 #number of bins in gpio_defaults
# list example [[(gpios),value],[(gpios),value],[(gpios),value]]
for array in gpios_values:
gpio_value = array[1]
for gpio in array[0]:
self.cov_configure_gpios(gpio,gpio_value.name)
gpio_defaults[size - (gpio*13 + 12): size -gpio*13] = gpio_value.value
#cocotb.log.info(f' [caravel] gpio_defaults[{size - (gpio*13 + 12)}:{size -gpio*13}] = {gpio_value.value} ')
self.caravel_hdl.gpio_defaults.value = gpio_defaults
#reset
self.caravel_hdl.gpio_resetn_1_shifted.value = 0
self.caravel_hdl.gpio_resetn_2_shifted.value = 0
await ClockCycles(self.clk, 1)
self.caravel_hdl.gpio_resetn_1_shifted.value = 1
self.caravel_hdl.gpio_resetn_2_shifted.value = 1
cocotb.log.info(f' [caravel] finish configuring gpios, the curret gpios value: ')
self.print_gpios_ctrl_val()
"""change the configration of the gpios by overwrite the register value
in control registers and housekeeping regs, don't consume simulation cycles"""
### dont use back door accessing
def configure_gpios_regs(self,gpios_values: list):
cocotb.log.info(f' [caravel] start cofigure gpio gpios ')
control_modules = self.control_blocks_paths()
# list example [[(gpios),value],[(gpios),value],[(gpios),value]]
for array in gpios_values:
gpio_value = array[1]
for gpio in array[0]:
self.cov_configure_gpios(gpio,gpio_value.name)
self.gpio_control_reg_write(control_modules[gpio],gpio_value.value) # for control blocks regs
self.caravel_hdl.housekeeping.gpio_configure[gpio].value = gpio_value.value # for house keeping regs
cocotb.log.info(f' [caravel] finish configuring gpios, the curret gpios value: ')
self.print_gpios_ctrl_val()
self.print_gpios_HW_val()
"""dummy function for coverage sampling"""
@Carvel_Coverage
def cov_configure_gpios(self,gpio,gpio_mode):
cocotb.log.debug(f' [caravel] gpio [{gpio}] = {gpio_mode} ')
pass
def print_gpios_default_val(self,print=1):
gpio_defaults = self.caravel_hdl.gpio_defaults.value
size = gpio_defaults.n_bits -1 #number of bins in gpio_defaults
gpios = []
for gpio in range(Macros['MPRJ_IO_PADS']):
gpio_value = gpio_defaults[size - (gpio*13 + 12): size -gpio*13]
gpio_enum = GPIO_MODE(gpio_value.integer)
gpios.append((gpio,gpio_enum))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
"""print the values return in the gpio of control block mode in GPIO Mode format"""
def print_gpios_ctrl_val(self, print=1):
control_modules = self.control_blocks_paths()
gpios = []
for i , gpio in enumerate(control_modules):
gpios.append((i,self.gpio_control_reg_read(gpio)))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
def _check_gpio_ctrl_eq_HW(self):
assert self.print_gpios_ctrl_val(1) == self.print_gpios_HW_val(1), f'there is an issue while configuration the control block register value isn\'t the same as the house keeping gpio register'
"""print the values return in the gpio of housekeeping block mode in GPIO Mode format"""
def print_gpios_HW_val(self,print=1):
gpios = []
for pin in range(Macros['MPRJ_IO_PADS']):
gpios.append((pin,GPIO_MODE(self.caravel_hdl.housekeeping.gpio_configure[pin].value)))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
"""return the paths of the control blocks"""
def control_blocks_paths(self)-> list:
car = self.caravel_hdl
control_modules =[car._id("gpio_control_bidir_1[0]",False),car._id("gpio_control_bidir_1[1]",False)]
#add gpio_control_in_1a (GPIO 2 to 7)
for i in range(6):
control_modules.append(car._id(f'gpio_control_in_1a[{i}]',False))
#add gpio_control_in_1 (GPIO 8 to 18)
for i in range(Macros['MPRJ_IO_PADS_1']-9+1):
control_modules.append(car._id(f'gpio_control_in_1[{i}]',False))
#add gpio_control_in_2 (GPIO 19 to 34)
for i in range(Macros['MPRJ_IO_PADS_2']-4+1):
control_modules.append(car._id(f'gpio_control_in_2[{i}]',False))
# Last three GPIOs (spi_sdo, flash_io2, and flash_io3) gpio_control_bidir_2
for i in range(3):
control_modules.append(car._id(f'gpio_control_bidir_2[{i}]',False))
return control_modules
"""read the control register and return a GPIO Mode it takes the path to the control reg"""
def gpio_control_reg_read(self,path:SimHandleBase) -> GPIO_MODE:
gpio_mgmt_en = path.mgmt_ena.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_MGMT_EN.value
gpio_out_dis = path.gpio_outenb.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_OUT_DIS.value
gpio_holdover = path.gpio_holdover.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_OVERRIDE.value
gpio_in_dis = path.gpio_inenb.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_INP_DIS.value
gpio_mode_sel = path.gpio_ib_mode_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_MOD_SEL.value
gpio_anlg_en = path.gpio_ana_en.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_EN.value
gpio_anlg_sel = path.gpio_ana_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_SEL.value
gpio_anlg_pol = path.gpio_ana_pol.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_POL.value
gpio_slow_sel = path.gpio_slow_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_SLOW.value
gpio_vtrip_sel = path.gpio_vtrip_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_TRIP.value
gpio_dgtl_mode = path.gpio_dm.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value
control_reg = (gpio_mgmt_en | gpio_out_dis | gpio_holdover| gpio_in_dis | gpio_mode_sel | gpio_anlg_en
|gpio_anlg_sel|gpio_anlg_pol|gpio_slow_sel|gpio_vtrip_sel|gpio_dgtl_mode)
return(GPIO_MODE(control_reg))
"""read the control register and return a GPIO Mode it takes the path to the control reg"""
def gpio_control_reg_write(self,path:SimHandleBase,data) :
bits =common.int_to_bin_list(data,14)
path.mgmt_ena.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_MGMT_EN.value]
path.gpio_outenb.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_OUT_DIS.value]
path.gpio_holdover.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_OVERRIDE.value]
path.gpio_inenb.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_INP_DIS.value]
path.gpio_ib_mode_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_MOD_SEL.value]
path.gpio_ana_en.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_EN.value]
path.gpio_ana_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_SEL.value]
path.gpio_ana_pol.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_POL.value]
path.gpio_slow_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_SLOW.value]
path.gpio_vtrip_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_TRIP.value]
gpio_dm =bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value:MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value+3]
gpio_dm =sum(d * 2**i for i, d in enumerate(gpio_dm)) # convert list to binary int
path.gpio_dm.value = gpio_dm
# """drive the value of mprj bits with spicific data from input pad at the top"""
# def release_gpio(self):
# io = self.caravel_hdl.padframe.mprj_pads.io
# mprj , n_bits = common.signal_valueZ_size(io)
# io.value = mprj
# cocotb.log.info(f' [caravel] drive_gpio_in pad mprj with {mprj}')
"""drive the value of mprj bits with spicific data from input pad at the top"""
def drive_gpio_in(self,bits,data):
# io = self.caravel_hdl.padframe.mprj_pads.io
# mprj , n_bits = common.signal_value_size(io)
# cocotb.log.debug(f' [caravel] before mprj with {mprj} and data = {data} bit [{n_bits-1-bits[0]}]:[{n_bits-1-bits[1]}]')
# mprj[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
# io.value = mprj
# cocotb.log.info(f' [caravel] drive_gpio_in pad mprj with {mprj}')
data_bits = []
is_list = isinstance(bits, (list,tuple))
if is_list :
cocotb.log.debug(f'[caravel] [drive_gpio_in] start bits[1] = {bits[1]} bits[0]= {bits[0]}')
data_bits = BinaryValue(value = data, n_bits =bits[0]-bits[1]+1 ,bigEndian=(bits[0]<bits[1]))
for i,bits2 in enumerate(range(bits[1],bits[0]+1)):
self.dut._id(f"bin{bits2}",False).value = data_bits[i]
self.dut._id(f"bin{bits2}_en",False).value = 1
cocotb.log.debug(f'[caravel] [drive_gpio_in] drive bin{bits2} with {data_bits[i]} and bin{bits2}_en with 1')
else:
self.dut._id(f'bin{bits}',False).value = data
self.dut._id(f'bin{bits}_en',False).value = 1
cocotb.log.debug(f'[caravel] [drive_gpio_in] drive bin{bits} with {data} and bin{bits}_en with 1')
""" release driving the value of mprj bits """
def release_gpio(self,bits):
data_bits = []
is_list = isinstance(bits, (list,tuple))
if is_list :
cocotb.log.debug(f'[caravel] [drive_gpio_disable] start bits[1] = {bits[1]} bits[0]= {bits[0]}')
for i,bits2 in enumerate(range(bits[1],bits[0]+1)):
self.dut._id(f"bin{bits2}_en",False).value = 0
cocotb.log.debug(f'[caravel] [drive_gpio_disable] release driving bin{bits2}')
else:
self.dut._id(f'bin{bits}_en',False).value = 0
cocotb.log.debug(f'[caravel] [drive_gpio_disable] release driving bin{bits}')
"""drive the value of gpio management"""
def drive_mgmt_gpio(self,data):
mgmt_io = self.dut.gpio_tb
mgmt_io.value = data
cocotb.log.info(f' [caravel] drive_mgmt_gpio through management area mprj with {data}')
"""update the value of mprj bits with spicific data then after certain number of cycle drive z to free the signal"""
async def drive_gpio_in_with_cycles(self,bits,data,num_cycles):
self.drive_gpio_in(bits,data)
cocotb.log.info(f' [caravel] wait {num_cycles} cycles')
await cocotb.start(self.wait_then_undrive(bits,num_cycles))
cocotb.log.info(f' [caravel] finish drive_gpio_with_in_cycles ')
"""drive the value of mprj bits with spicific data from management area then after certain number of cycle drive z to free the signal"""
async def drive_mgmt_gpio_with_cycles(self,bits,data,num_cycles):
self.drive_mgmt_gpio(bits,data)
cocotb.log.info(f' [caravel] wait {num_cycles} cycles')
await cocotb.start(self.wait_then_undrive(bits,num_cycles))
cocotb.log.info(f' [caravel] finish drive_gpio_with_in_cycles ')
async def wait_then_undrive(self,bits,num_cycles):
await ClockCycles(self.clk, num_cycles)
n_bits = bits[0]-bits[1]+1
self.drive_gpio_in(bits, (n_bits)* 'z')
cocotb.log.info(f' [caravel] finish wait_then_drive ')
async def hk_write_byte(self, data):
self.path = self.dut.mprj_io_tb
data_bit = BinaryValue(value = data , n_bits = 8,bigEndian=False)
for i in range(7,-1,-1):
await FallingEdge(self.clk)
#common.drive_hdl(self.path,[(4,4),(2,2)],[0,int(data_bit[i])]) # 2 = SDI 4 = SCK
self.drive_gpio_in((2,2),int(data_bit[i]))
self.drive_gpio_in((4,4),0)
await RisingEdge(self.clk)
self.drive_gpio_in((4,4),1)
await FallingEdge(self.clk)
""" read byte using housekeeping spi
when writing to SCK we can't use mprj[4] as there is a limitation in cocotb for accessing pack array #2587
so use back door access to write the clock then read the output from the SDO mprj[1] value"""
async def hk_read_byte(self,last_read= False):
read_data =''
for i in range(8,0,-1):
self.drive_gpio_in((4,4),1)# SCK
await FallingEdge(self.clk)
self.drive_gpio_in((4,4),0)# SCK
await RisingEdge(self.clk)
read_data= f'{read_data}{self.dut.mprj_io_tb.value[37-1]}'
await FallingEdge(self.clk)
self.drive_gpio_in((4,4),0) # SCK
# if (last_read):
# common.drive_hdl(self.dut.bin4_en,(0,0),'z') #4 = SCK
# common.drive_hdl(self.path,[(1,1)],'z')
return int(read_data,2)
"""write to the house keeping registers by back door no need for commands and waiting for the data to show on mprj"""
async def hk_write_backdoor(self,addr, data):
await RisingEdge(self.dut.wb_clk_i)
self.hk_hdl.wb_stb_i.value = 1
self.hk_hdl.wb_cyc_i.value = 1
self.hk_hdl.wb_sel_i.value = 0xF
self.hk_hdl.wb_we_i.value = 1
self.hk_hdl.wb_adr_i.value = addr
self.hk_hdl.wb_dat_i.value = data
cocotb.log.info(f'Monitor: Start Writing to {hex(addr)} -> {data}')
await FallingEdge(self.dut.wb_ack_o) # wait for acknowledge
self.hk_hdl.wb_stb_i.value = 0
self.hk_hdl.wb_cyc_i.value = 0
cocotb.log.info(f'Monitor: End writing {hex(addr)} -> {data}')
"""read from the house keeping registers by back door no need for commands and waiting for the data to show on mprj"""
async def hk_read_backdoor(self,addr):
await RisingEdge(self.clk)
self.hk_hdl.wb_stb_i.value = 1
self.hk_hdl.wb_cyc_i.value = 1
self.hk_hdl.wb_sel_i.value = 0
self.hk_hdl.wb_we_i.value = 0
self.hk_hdl.wb_adr_i.value = addr
cocotb.log.info(f' [housekeeping] Monitor: Start reading from {hex(addr)}')
await FallingEdge(self.hk_hdl.wb_ack_o)
self.hk_hdl.wb_stb_i.value = 0
self.hk_hdl.wb_cyc_i.value = 0
cocotb.log.info(f' [housekeeping] Monitor: read from {hex(addr)} value {(self.hk_hdl.wb_dat_o.value)}')
return self.hk_hdl.wb_dat_o.value

View File

@ -1,207 +0,0 @@
from cgitb import handler
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
import cocotb.simulator
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import interfaces.caravel
from interfaces.logic_analyzer import LA
from interfaces.caravel import GPIO_MODE, Caravel_env
from wb_models.housekeepingWB.housekeepingWB import HK_whiteBox
import interfaces.common as common
import logging
from interfaces.cpu import RiskV
from cocotb.log import SimTimeContextFilter
from cocotb.log import SimLogFormatter
from interfaces.defsParser import Regs
from tests.common_functions.Timeout import Timeout
from cocotb.result import TestSuccess
import inspect
import os
# tests
from tests.bitbang.bitbang_tests import *
from tests.bitbang.bitbang_tests_cpu import *
from tests.housekeeping.housekeeping_regs.housekeeping_regs_tests import *
from tests.housekeeping.housekeeping_spi.user_pass_thru import *
from tests.housekeeping.housekeeping_spi.spi import *
from tests.housekeeping.general.pll import *
from tests.housekeeping.general.sys_ctrl import *
from tests.temp_partial_test.partial import *
from tests.hello_world.helloWorld import *
from tests.cpu.cpu_stress import *
from tests.mem.mem_stress import *
from tests.irq.IRQ_external import *
from tests.irq.IRQ_timer import *
from tests.irq.IRQ_uart import *
from tests.gpio.gpio import *
from tests.gpio_caravan.gpio_caravan import *
from tests.gpio.gpio_user import *
from tests.mgmt_gpio.mgmt_gpio import *
from tests.timer.timer import *
from tests.uart.uart import *
from tests.spi_master.spi_master import *
from tests.logicAnalyzer.la import *
from tests.debug.debug import *
from tests.cpu.cpu_reset import *
# archive tests
@cocotb.test()
async def cpu_drive(dut):
TestName = inspect.stack()[0][3]
if not os.path.exists(f'sim/{TestName}'):
os.mkdir(f'sim/{TestName}') # create test folder
cocotb.log.setLevel(logging.INFO)
handler = logging.FileHandler(f"sim/{TestName}/{TestName}.log",mode='w')
handler.addFilter(SimTimeContextFilter())
handler.setFormatter(SimLogFormatter())
cocotb.log.addHandler(handler)
caravelEnv = caravel.Caravel_env(dut)
Timeout(caravelEnv.clk,1000000,0.1)
la = LA(dut)
clock = Clock(caravelEnv.clk, 12.5, units="ns") # Create a 10ns period clock on port clk
cpu = RiskV(dut)
cpu.cpu_force_reset()
cocotb.start_soon(clock.start()) # Start the clock
await caravelEnv.start_up()
hk = HK_whiteBox(dut)
reg = Regs()
time_out_count =0
await ClockCycles(caravelEnv.clk, 100)
address = reg.get_addr('reg_wb_enable')
await cpu.drive_data2address(address,1)
address = reg.get_addr('reg_debug_2')
await cpu.drive_data2address(address,0xdFF0)
await ClockCycles(caravelEnv.clk, 10)
cpu.cpu_release_reset()
await ClockCycles(caravelEnv.clk, 10)
raise TestSuccess(f" TEST {TestName} passed")
while True:
await ClockCycles(caravelEnv.clk, 1)
if (cpu.read_debug_reg1() == 0xFFF0):
break
cocotb.log.info(f"[TEST][cpu_drive] debug reg1 = 0xFFF0")
await ClockCycles(caravelEnv.clk, 10)
address = reg.get_addr('reg_debug_2')
await cpu.drive_data2address(address,0xdFF0)
await ClockCycles(caravelEnv.clk, 50)
# address = reg.get_addr('reg_mprj_io_0')
# await cpu.drive_data2address(address,0x0c03)
cocotb.log.info(f"[TEST][cpu_drive] wait debug reg1 = 0xddd0")
while True:
await ClockCycles(caravelEnv.clk, 1)
if (cpu.read_debug_reg1() == 0xddd0):
break
cocotb.log.info(f"[TEST][cpu_drive] debug reg1 = 0xddd0")
await ClockCycles(caravelEnv.clk, 10)
caravelEnv.print_gpios_HW_val()
coverage_db.export_to_yaml(filename="coverage.yalm")
@cocotb.test()
async def spi_drive(dut):
cocotb.log.setLevel(logging.INFO)
handler = logging.FileHandler(f"test.log",mode='w')
handler.addFilter(SimTimeContextFilter())
handler.setFormatter(SimLogFormatter())
cocotb.log.addHandler(handler)
caravelEnv = caravel.Caravel_env(dut)
la = LA(dut)
clock = Clock(caravelEnv.clk, 12.5, units="ns") # Create a 10ns period clock on port clk
cocotb.start_soon(clock.start()) # Start the clock
await caravelEnv.start_up()
hk = HK_whiteBox(dut,True)
caravelEnv.enable_csb()
await ClockCycles(caravelEnv.clk,1)
# caravelEnv.configure_gpios_regs([[tuple(range(0,6)),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT]])
await ClockCycles(caravelEnv.clk,1)
await caravelEnv.hk_write_byte(0x40) # read command
# await caravelEnv.hk_write_byte(0x80) # command write
await caravelEnv.hk_write_byte(0x0) # address
# await caravelEnv.hk_write_byte(0x03) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte() # read value
print(read_data)
read_data = await caravelEnv.hk_read_byte(True) # read value
caravelEnv.disable_csb()
await ClockCycles(caravelEnv.clk,1)
caravelEnv.enable_csb()
await ClockCycles(caravelEnv.clk,1)
# caravelEnv.configure_gpios_regs([[tuple(range(0,6)),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT]])
await ClockCycles(caravelEnv.clk,1)
await caravelEnv.hk_write_byte(0x40) # read command
# await caravelEnv.hk_write_byte(0x80) # command write
await caravelEnv.hk_write_byte(0x8) # address
# await caravelEnv.hk_write_byte(0x03) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
# await caravelEnv.hk_write_byte(0xaa) # data
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
read_data = await caravelEnv.hk_read_byte() # read value
# caravelEnv.drive_gpio_in([5,5],1)
await ClockCycles(caravelEnv.clk,40)
coverage_db.export_to_yaml(filename="coverage.yml")
coverage_db.export_to_xml(filename="coverage.xml")
return

View File

@ -1,380 +0,0 @@
`timescale 1 ns / 1 ps
`ifdef VCS
`ifndef GL
`include "includes.v" // in case of RTL coverage is needed and it doesn't work correctly without include files by this way
`endif // ~ GL
`ifndef ENABLE_SDF
`include "libs.ref/sky130_fd_io/verilog/sky130_fd_io.v"
`include "libs.ref/sky130_fd_io/verilog/sky130_ef_io.v"
`include "libs.ref/sky130_fd_sc_hd/verilog/primitives.v"
`include "libs.ref/sky130_fd_sc_hd/verilog/sky130_fd_sc_hd.v"
`include "libs.ref/sky130_fd_sc_hvl/verilog/primitives.v"
`include "libs.ref/sky130_fd_sc_hvl/verilog/sky130_fd_sc_hvl.v"
`else
`include "cvc-pdk/sky130_ef_io.v"
`include "cvc-pdk/sky130_fd_io.v"
`include "cvc-pdk/primitives_hd.v"
`include "cvc-pdk/sky130_fd_sc_hd.v"
`include "cvc-pdk/primitives_hvl.v"
`include "cvc-pdk/sky130_fd_sc_hvl.v"
`endif // ~ ENABLE_SDF
`endif // VCS
module caravel_top ;
// parameter FILENAME = {"hex_files/",`TESTNAME,".hex"};
parameter FILENAME={"hex_files/",`TESTNAME,".hex"};
initial begin
`ifdef VCS
`ifdef ENABLE_SDF
$vcdplusfile({`MAIN_PATH,"/sim/",`TAG,"/",`FTESTNAME,"/",`TESTNAME , `CORNER,"-",`SDF_POSTFIX, ".vpd"});
`else
$vcdplusfile({`MAIN_PATH,"/sim/",`TAG,"/",`FTESTNAME,"/",`TESTNAME ,".vpd"});
`endif
$vcdpluson();
`else
$dumpfile ({"sim/",`TAG,"/",`SIM,"-",`TESTNAME,"/",`SIM,"-",`TESTNAME,".vcd"});
$dumpvars (0, caravel_top);
`endif
end
`ifdef VCS
`ifdef ENABLE_SDF
`include "sdf_includes.v"
`endif
`endif // VCS
wire vddio_tb; // Common 3.3V padframe/ESD power
wire vddio_2_tb; // Common 3.3V padframe/ESD power
wire vssio_tb; // Common padframe/ESD ground
wire vssio_2_tb; // Common padframe/ESD ground
wire vdda_tb; // Management 3.3V power
wire vssa_tb; // Common analog ground
wire vccd_tb; // Management/Common 1.8V power
wire vssd_tb; // Common digital ground
wire vdda1_tb; // User area 1 3.3V power
wire vdda1_2_tb; // User area 1 3.3V power
wire vdda2_tb; // User area 2 3.3V power
wire vssa1_tb; // User area 1 analog ground
wire vssa1_2_tb; // User area 1 analog ground
wire vssa2_tb; // User area 2 analog ground
wire vccd1_tb; // User area 1 1.8V power
wire vccd2_tb; // User area 2 1.8V power
wire vssd1_tb; // User area 1 digital ground
wire vssd2_tb; // User area 2 digital ground
wire gpio_tb; // Used for external LDO control
wire [38-1:0] mprj_io_tb;
reg clock_tb; // CMOS core clock input; not a crystal
wire resetb_tb; // Reset input (sense inverted)
// Note that only two flash data pins are dedicated to the
// management SoC wrapper. The management SoC exports the
// quad SPI mode status to make use of the top two mprj_io
// pins for io2 and io3.
wire flash_csb_tb;
wire flash_clk_tb;
wire flash_io0_tb;
wire flash_io1_tb;
`ifdef CARAVAN
caravan uut (
`else
caravel uut (
`endif
.vddio (vddio_tb),
.vddio_2 (vddio_2_tb),
.vssio (vssio_tb),
.vssio_2 (vssio_2_tb),
.vdda (vdda_tb),
.vssa (vssa_tb),
.vccd (vccd_tb),
.vssd (vssd_tb),
.vdda1 (vdda1_tb),
.vdda1_2 (vdda1_2_tb),
.vdda2 (vdda2_tb),
.vssa1 (vssa1_tb),
.vssa1_2 (vssa1_2_tb),
.vssa2 (vssa2_tb),
.vccd1 (vccd1_tb),
.vccd2 (vccd2_tb),
.vssd1 (vssd1_tb),
.vssd2 (vssd2_tb),
.clock (clock_tb),
.gpio (gpio_tb),
.mprj_io (mprj_io_tb),
.flash_csb(flash_csb_tb),
.flash_clk(flash_clk_tb),
.flash_io0(flash_io0_tb),
.flash_io1(flash_io1_tb),
.resetb (resetb_tb)
);
spiflash #(
FILENAME
) spiflash (
.csb(flash_csb_tb),
.clk(flash_clk_tb),
.io0(flash_io0_tb),
.io1(flash_io1_tb),
.io2(), // not used
.io3() // not used
);
mac macros();
// make speical variables for the mprj input to assign the input without writing to the output gpios
// cocotb limitation #2587: iverilog deal with array as 1 object not multiple of objects so can't write to only 1 element
wire bin0;
wire bin0_en;
wire bin1;
wire bin1_en;
wire bin2;
wire bin2_en;
wire bin3;
wire bin3_en;
wire bin4;
wire bin4_en;
wire bin5;
wire bin5_en;
wire bin6;
wire bin6_en;
wire bin7;
wire bin7_en;
wire bin8;
wire bin8_en;
wire bin9;
wire bin9_en;
wire bin10;
wire bin10_en;
wire bin11;
wire bin11_en;
wire bin12;
wire bin12_en;
wire bin13;
wire bin13_en;
wire bin14;
wire bin14_en;
wire bin15;
wire bin15_en;
wire bin16;
wire bin16_en;
wire bin17;
wire bin17_en;
wire bin18;
wire bin18_en;
wire bin19;
wire bin19_en;
wire bin20;
wire bin20_en;
wire bin21;
wire bin21_en;
wire bin22;
wire bin22_en;
wire bin23;
wire bin23_en;
wire bin24;
wire bin24_en;
wire bin25;
wire bin25_en;
wire bin26;
wire bin26_en;
wire bin27;
wire bin27_en;
wire bin28;
wire bin28_en;
wire bin29;
wire bin29_en;
wire bin30;
wire bin30_en;
wire bin31;
wire bin31_en;
wire bin32;
wire bin32_en;
wire bin33;
wire bin33_en;
wire bin34;
wire bin34_en;
wire bin35;
wire bin35_en;
wire bin36;
wire bin36_en;
wire bin37;
wire bin37_en;
assign mprj_io_tb[0] = (bin0_en) ? bin0 : 1'bz;
assign mprj_io_tb[1] = (bin1_en) ? bin1 : 1'bz;
assign mprj_io_tb[2] = (bin2_en) ? bin2 : 1'bz;
assign mprj_io_tb[3] = (bin3_en) ? bin3 : 1'bz;
assign mprj_io_tb[4] = (bin4_en) ? bin4 : 1'bz;
assign mprj_io_tb[5] = (bin5_en) ? bin5 : 1'bz;
assign mprj_io_tb[6] = (bin6_en) ? bin6 : 1'bz;
assign mprj_io_tb[7] = (bin7_en) ? bin7 : 1'bz;
assign mprj_io_tb[8] = (bin8_en) ? bin8 : 1'bz;
assign mprj_io_tb[9] = (bin9_en) ? bin9 : 1'bz;
assign mprj_io_tb[10] = (bin10_en) ? bin10 : 1'bz;
assign mprj_io_tb[11] = (bin11_en) ? bin11 : 1'bz;
assign mprj_io_tb[12] = (bin12_en) ? bin12 : 1'bz;
assign mprj_io_tb[13] = (bin13_en) ? bin13 : 1'bz;
assign mprj_io_tb[14] = (bin14_en) ? bin14 : 1'bz;
assign mprj_io_tb[15] = (bin15_en) ? bin15 : 1'bz;
assign mprj_io_tb[16] = (bin16_en) ? bin16 : 1'bz;
assign mprj_io_tb[17] = (bin17_en) ? bin17 : 1'bz;
assign mprj_io_tb[18] = (bin18_en) ? bin18 : 1'bz;
assign mprj_io_tb[19] = (bin19_en) ? bin19 : 1'bz;
assign mprj_io_tb[20] = (bin20_en) ? bin20 : 1'bz;
assign mprj_io_tb[21] = (bin21_en) ? bin21 : 1'bz;
assign mprj_io_tb[22] = (bin22_en) ? bin22 : 1'bz;
assign mprj_io_tb[23] = (bin23_en) ? bin23 : 1'bz;
assign mprj_io_tb[24] = (bin24_en) ? bin24 : 1'bz;
assign mprj_io_tb[25] = (bin25_en) ? bin25 : 1'bz;
assign mprj_io_tb[26] = (bin26_en) ? bin26 : 1'bz;
assign mprj_io_tb[27] = (bin27_en) ? bin27 : 1'bz;
assign mprj_io_tb[28] = (bin28_en) ? bin28 : 1'bz;
assign mprj_io_tb[29] = (bin29_en) ? bin29 : 1'bz;
assign mprj_io_tb[30] = (bin30_en) ? bin30 : 1'bz;
assign mprj_io_tb[31] = (bin31_en) ? bin31 : 1'bz;
assign mprj_io_tb[32] = (bin32_en) ? bin32 : 1'bz;
assign mprj_io_tb[33] = (bin33_en) ? bin33 : 1'bz;
assign mprj_io_tb[34] = (bin34_en) ? bin34 : 1'bz;
assign mprj_io_tb[35] = (bin35_en) ? bin35 : 1'bz;
assign mprj_io_tb[36] = (bin36_en) ? bin36 : 1'bz;
assign mprj_io_tb[37] = (bin37_en) ? bin37 : 1'bz;
// to read from mprj array with iverilog
wire bin0_monitor;
wire bin1_monitor;
wire bin2_monitor;
wire bin3_monitor;
wire bin4_monitor;
wire bin5_monitor;
wire bin6_monitor;
wire bin7_monitor;
wire bin8_monitor;
wire bin9_monitor;
wire bin10_monitor;
wire bin11_monitor;
wire bin12_monitor;
wire bin13_monitor;
wire bin14_monitor;
wire bin15_monitor;
wire bin16_monitor;
wire bin17_monitor;
wire bin18_monitor;
wire bin19_monitor;
wire bin20_monitor;
wire bin21_monitor;
wire bin22_monitor;
wire bin23_monitor;
wire bin24_monitor;
wire bin25_monitor;
wire bin26_monitor;
wire bin27_monitor;
wire bin28_monitor;
wire bin29_monitor;
wire bin30_monitor;
wire bin31_monitor;
wire bin32_monitor;
wire bin33_monitor;
wire bin34_monitor;
wire bin35_monitor;
wire bin36_monitor;
wire bin37_monitor;
assign bin0_monitor = mprj_io_tb[0];
assign bin1_monitor = mprj_io_tb[1];
assign bin2_monitor = mprj_io_tb[2];
assign bin3_monitor = mprj_io_tb[3];
assign bin4_monitor = mprj_io_tb[4];
assign bin5_monitor = mprj_io_tb[5];
assign bin6_monitor = mprj_io_tb[6];
assign bin7_monitor = mprj_io_tb[7];
assign bin8_monitor = mprj_io_tb[8];
assign bin9_monitor = mprj_io_tb[9];
assign bin10_monitor = mprj_io_tb[10];
assign bin11_monitor = mprj_io_tb[11];
assign bin12_monitor = mprj_io_tb[12];
assign bin13_monitor = mprj_io_tb[13];
assign bin14_monitor = mprj_io_tb[14];
assign bin15_monitor = mprj_io_tb[15];
assign bin16_monitor = mprj_io_tb[16];
assign bin17_monitor = mprj_io_tb[17];
assign bin18_monitor = mprj_io_tb[18];
assign bin19_monitor = mprj_io_tb[19];
assign bin20_monitor = mprj_io_tb[20];
assign bin21_monitor = mprj_io_tb[21];
assign bin22_monitor = mprj_io_tb[22];
assign bin23_monitor = mprj_io_tb[23];
assign bin24_monitor = mprj_io_tb[24];
assign bin25_monitor = mprj_io_tb[25];
assign bin26_monitor = mprj_io_tb[26];
assign bin27_monitor = mprj_io_tb[27];
assign bin28_monitor = mprj_io_tb[28];
assign bin29_monitor = mprj_io_tb[29];
assign bin30_monitor = mprj_io_tb[30];
assign bin31_monitor = mprj_io_tb[31];
assign bin32_monitor = mprj_io_tb[32];
assign bin33_monitor = mprj_io_tb[33];
assign bin34_monitor = mprj_io_tb[34];
assign bin35_monitor = mprj_io_tb[35];
assign bin36_monitor = mprj_io_tb[36];
assign bin37_monitor = mprj_io_tb[37];
endmodule
// module that has all needed macros by cocotb
module mac;
reg [7:0] MPRJ_IO_PADS_1 = `ifdef MPRJ_IO_PADS_1 `MPRJ_IO_PADS_1 `else 0 `endif; /* number of user GPIO pads on user1 side */
reg [7:0] MPRJ_IO_PADS_2 = `ifdef MPRJ_IO_PADS_2 `MPRJ_IO_PADS_2 `else 0 `endif; /* number of user GPIO pads on user2 side */
reg [7:0] MPRJ_IO_PADS = `ifdef MPRJ_IO_PADS `MPRJ_IO_PADS `else 0 `endif;
reg [7:0] MPRJ_PWR_PADS_1 =`ifdef MPRJ_PWR_PADS_1 `MPRJ_PWR_PADS_1 `else 0 `endif; /* vdda1, vccd1 enable/disable control */
reg [7:0] MPRJ_PWR_PADS_2 = `ifdef MPRJ_PWR_PADS_2 `MPRJ_PWR_PADS_2 `else 0 `endif; /* vdda2, vccd2 enable/disable control */
reg [7:0] MPRJ_PWR_PADS =`ifdef MPRJ_PWR_PADS `MPRJ_PWR_PADS `else 0 `endif;
// Analog pads are only used by the "caravan" module and associated
// modules such as user_analog_project_wrapper and chip_io_alt.
reg [7:0] ANALOG_PADS_1 = `ifdef ANALOG_PADS_1 `ANALOG_PADS_1 `else 0 `endif;
reg [7:0] ANALOG_PADS_2 = `ifdef ANALOG_PADS_2 `ANALOG_PADS_2 `else 0 `endif;
reg [7:0] ANALOG_PADS = `ifdef ANALOG_PADS `ANALOG_PADS `else 0 `endif;
// Type and size of soc_mem
reg USE_CUSTOM_DFFRAM = `ifdef USE_CUSTOM_DFFRAM 1 `else 0 `endif;
// don't change the following without double checking addr widths
reg [7:0] MEM_WORDS = `ifdef MEM_WORDS `MEM_WORDS `else 0 `endif;
// Number of columns in the custom memory; takes one of three values:
// 1 column : 1 KB, 2 column: 2 KB, 4 column: 4KB
reg [7:0] DFFRAM_WSIZE = `ifdef DFFRAM_WSIZE `DFFRAM_WSIZE `else 0 `endif;
reg [7:0] DFFRAM_USE_LATCH = `ifdef DFFRAM_USE_LATCH `DFFRAM_USE_LATCH `else 0 `endif;
// not really parameterized but just to easily keep track of the number
// of ram_block across different modules
reg [7:0] RAM_BLOCKS = `ifdef RAM_BLOCKS `RAM_BLOCKS `else 0 `endif;
// Clock divisor default value
reg [7:0] CLK_DIV = `ifdef CLK_DIV `CLK_DIV `else 0 `endif;
// GPIO control default mode and enable for most I/Os
// Most I/Os set to be user bidirectional pins on power-up.
reg [7:0] MGMT_INIT = `ifdef MGMT_INIT `MGMT_INIT `else 0 `endif;
reg [7:0] OENB_INIT = `ifdef OENB_INIT `OENB_INIT `else 0 `endif;
reg [7:0] DM_INIT = `ifdef DM_INIT `DM_INIT `else 0 `endif;
// GL
reg GL = `ifdef GL 1 `else 0 `endif;
reg CARAVAN = `ifdef CARAVAN 1 `else 0 `endif;
endmodule

View File

@ -1,232 +0,0 @@
from operator import add
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
import cocotb.simulator
from cocotb.handle import SimHandleBase
from cocotb.handle import Force
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import enum
from cocotb.handle import (
ConstantObject,
HierarchyArrayObject,
HierarchyObject,
ModifiableObject,
NonHierarchyIndexableObject,
SimHandle,
)
from itertools import groupby, product
import interfaces.common as common
from common import GPIO_MODE
from common import MASK_GPIO_CTRL
from common import Macros
class RiskV:
def __init__(self,dut:SimHandleBase):
self.dut = dut
self.clk = dut.clock_tb
if not Macros['GL']:
self.cpu_hdl = dut.uut.soc.core.VexRiscv
else:
self.cpu_hdl = dut.uut.soc.core
self.debug_hdl = dut.uut.mprj.debug
self.force_reset = 0
cocotb.scheduler.add(self.force_reset_fun())
""" """
async def drive_data_with_address(self,address,data,SEL=0xF):
self.cpu_hdl.dBusWishbone_CYC.value = 1
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 1
self.cpu_hdl.dBusWishbone_SEL.value = SEL
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = data
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = BinaryValue(value = 'z')
self.cpu_hdl.iBusWishbone_CYC.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_STB.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_WE.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_SEL.value = BinaryValue(value = 'zzzz')
self.cpu_hdl.dBusWishbone_ADR.value = common.signal_valueZ_size(self.cpu_hdl.dBusWishbone_ADR)[0]
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = common.signal_valueZ_size(self.cpu_hdl.dBusWishbone_DAT_MOSI)[0]
""" """
async def drive_data2address(self,address,data,SEL=0xF):
cocotb.log.info(f"[RiskV][drive_data2address] start driving address {hex(address)} with {hex(data)}")
# print(dir(self.cpu_hdl))
dBusWishbone_CYC = self.cpu_hdl.dBusWishbone_CYC.value
if not Macros['GL']:
iBusWishbone_CYC = self.cpu_hdl.iBusWishbone_CYC.value
dBusWishbone_STB = self.cpu_hdl.dBusWishbone_STB.value
dBusWishbone_WE = self.cpu_hdl.dBusWishbone_WE.value
if not Macros['GL']:
dBusWishbone_SEL = self.cpu_hdl.dBusWishbone_SEL.value
else:
dBusWishbone_SEL0 = self.cpu_hdl.net2121.value
dBusWishbone_SEL1 = self.cpu_hdl.net1979.value
dBusWishbone_SEL2 = self.cpu_hdl.net848.value
dBusWishbone_SEL3 = self.cpu_hdl.net1956.value
if not Macros['GL']:
dBusWishbone_ADR = self.cpu_hdl.dBusWishbone_ADR.value
dBusWishbone_DAT_MOSI = self.cpu_hdl.dBusWishbone_DAT_MOSI.value
self.cpu_hdl.dBusWishbone_CYC.value = 1
if not Macros['GL']:
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_SEL.value = SEL
else:
self.cpu_hdl.net2121.value = (SEL >>0 ) &1
self.cpu_hdl.net1979.value = (SEL >>1 ) &1
self.cpu_hdl.net848.value = (SEL >>2 ) &1
self.cpu_hdl.net1956.value = (SEL >>3 ) &1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
else:
address_temp = address >> 2
for i in range(30):
self.cpu_hdl._id(f'dBusWishbone_ADR[{i}]',False).value = (address_temp >> i) & 1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = data
else:
for i in range(32):
self.cpu_hdl._id(f'dBusWishbone_DAT_MOSI[{i}]',False).value = (data >> i) & 1
if not Macros['GL']:
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
else:
# await RisingEdge(self.cpu_hdl._id("_07019_",False) & (self.cpu_hdl._id("grant[0]",False)))
await RisingEdge(self.cpu_hdl._id("_07019_",False) )
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = dBusWishbone_CYC
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = dBusWishbone_ADR
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = dBusWishbone_DAT_MOSI
self.cpu_hdl.iBusWishbone_CYC.value = iBusWishbone_CYC
self.cpu_hdl.dBusWishbone_STB.value = dBusWishbone_STB
self.cpu_hdl.dBusWishbone_WE.value = dBusWishbone_WE
self.cpu_hdl.dBusWishbone_SEL.value = dBusWishbone_SEL
await ClockCycles(self.clk, 1)
cocotb.log.info(f"[RiskV][drive_data2address] finish driving address {hex(address)} with {hex(data)}")
""" """
async def read_address(self,address,SEL=0xF):
cocotb.log.info(f"[RiskV][read_address] start reading address {hex(address)}")
# print(dir(self.cpu_hdl))
dBusWishbone_CYC = self.cpu_hdl.dBusWishbone_CYC.value
if not Macros['GL']:
iBusWishbone_CYC = self.cpu_hdl.iBusWishbone_CYC.value
dBusWishbone_STB = self.cpu_hdl.dBusWishbone_STB.value
dBusWishbone_WE = self.cpu_hdl.dBusWishbone_WE.value
if not Macros['GL']:
dBusWishbone_SEL = self.cpu_hdl.dBusWishbone_SEL.value
else:
dBusWishbone_SEL0 = self.cpu_hdl.net2121.value
dBusWishbone_SEL1 = self.cpu_hdl.net1979.value
dBusWishbone_SEL2 = self.cpu_hdl.net848.value
dBusWishbone_SEL3 = self.cpu_hdl.net1956.value
if not Macros['GL']:
dBusWishbone_ADR = self.cpu_hdl.dBusWishbone_ADR.value
dBusWishbone_DAT_MOSI = self.cpu_hdl.dBusWishbone_DAT_MOSI.value
self.cpu_hdl.dBusWishbone_CYC.value = 1
if not Macros['GL']:
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 0
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_SEL.value = SEL
else:
self.cpu_hdl.net2121.value = (SEL >>0 ) &1
self.cpu_hdl.net1979.value = (SEL >>1 ) &1
self.cpu_hdl.net848.value = (SEL >>2 ) &1
self.cpu_hdl.net1956.value = (SEL >>3 ) &1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
else:
address_temp = address >> 2
for i in range(30):
self.cpu_hdl._id(f'dBusWishbone_ADR[{i}]',False).value = (address_temp >> i) & 1
if not Macros['GL']:
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
else:
# await RisingEdge(self.cpu_hdl._id("_07019_",False) & (self.cpu_hdl._id("grant[0]",False)))
await RisingEdge(self.cpu_hdl._id("_07019_",False) )
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = dBusWishbone_CYC
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = dBusWishbone_ADR
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = dBusWishbone_DAT_MOSI
self.cpu_hdl.iBusWishbone_CYC.value = iBusWishbone_CYC
self.cpu_hdl.dBusWishbone_STB.value = dBusWishbone_STB
self.cpu_hdl.dBusWishbone_WE.value = dBusWishbone_WE
self.cpu_hdl.dBusWishbone_SEL.value = dBusWishbone_SEL
data = self.cpu_hdl.dBusWishbone_DAT_MISO.value
await ClockCycles(self.clk, 1)
cocotb.log.info(f"[RiskV][read_address] finish reading address {hex(address)} data = {data}")
# return data
return int(str(bin(data.integer)[2:]).zfill(32),2)
# return int(str(bin(data.integer)[2:]).zfill(32)[::-1],2)
def read_debug_reg1(self):
return self.debug_hdl.debug_reg_1.value.integer
def read_debug_reg2(self):
return self.debug_hdl.debug_reg_2.value.integer
# writing debug registers using backdoor because in GL cpu can't be disabled for now because of different netlist names
def write_debug_reg1_backdoor(self,data):
self.debug_hdl.debug_reg_1.value = data
def write_debug_reg2_backdoor(self,data):
self.debug_hdl.debug_reg_2.value = data
async def force_reset_fun(self):
first_time_force = True
first_time_release = True
while True:
if self.force_reset:
if first_time_force:
cocotb.log.info(f"[RiskV][force_reset_fun] Force CPU reset")
first_time_force = False
first_time_release = True
self.cpu_hdl.reset.value =1
if not Macros['GL']:
common.drive_hdl(self.cpu_hdl.reset,(0,0),1)
else:
common.drive_hdl(self.cpu_hdl.mgmtsoc_vexriscv_debug_reset,(0,0),1)
else:
if first_time_release:
first_time_force = True
first_time_release = False
if not Macros['GL']:
common.drive_hdl(self.cpu_hdl.reset,(0,0),0)
else:
common.drive_hdl(self.cpu_hdl.mgmtsoc_vexriscv_debug_reset,(0,0),0)
cocotb.log.info(f"[RiskV][force_reset_fun] release CPU reset")
await ClockCycles(self.clk, 1)
def cpu_force_reset(self):
self.force_reset = True
def cpu_release_reset(self):
self.force_reset = False

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

View File

@ -1 +0,0 @@

View File

@ -1,22 +0,0 @@
# tests commands
## run one test in RTL
``` python3 verify_cocotb.py -t uart_tx -tag uart_tx_rtl ```
``` python3 verify_cocotb.py -t uart_tx -sim RTL -tag uart_tx_rtl ```
## run one test in GL
``` python3 verify_cocotb.py -t uart_tx -sim GL -tag uart_tx_gl ```
## run one test in more than 1 corner
``` python3 verify_cocotb.py -t uart_tx -sim RTL GL -tag uart_tx_rtl_gl ```
## run more than 1 test
``` python3 verify_cocotb.py -t uart_tx uart_rx -tag uart_tx_rx_rtl ```
``` python3 verify_cocotb.py -t uart_tx uart_rx -sim RTL GL -tag uart_tx_rx_rtl_gl ```
# Regressions commands
## running all RTl tests
``` python3 verify_cocotb.py -r r_rtl -tag all_rtl ```
## running all GL tests
``` python3 verify_cocotb.py -r r_gl -tag all_gl ```
# tests and regression
``` python3 verify_cocotb.py -r r_rtl -t uart_tx uart_rx -sim GL -tag all_rtl_and_uart_gl ```

View File

@ -1,105 +0,0 @@
# gpio
### gpio_all_i
```configure all gpios as mgmt input using automatic approach firmware and check them```
### gpio_all_i_user
```configure all gpios as user input using automatic approach firmware and check them```
### gpio_all_i_pu
```configure all gpios as mgmt input pull up using automatic approach firmware and check them```
### gpio_all_i_pu_user
```configure all gpios as user input pull up using automatic approach firmware and check them```
### gpio_all_i_pd
```configure all gpios as mgmt input pull down using automatic approach firmware and check them```
### gpio_all_i_pd_user
```configure all gpios as user input pull down using automatic approach firmware and check them```
### gpio_all_bidir_user
```configure all gpios as user bidir using automatic approach firmware and check them```
### gpio_all_o
```configure all gpios as mgmt output using automatic approach firmware and check them```
### gpio_all_o_user
```configure all gpios as user output using automatic approach firmware and check them```
### mgmt_gpio_out
```tests blinking of mgmt gpio bit as an output```
### mgmt_gpio_in
```tests blinking of mgmt gpio bit as an output```
### mgmt_gpio_bidir
```send random number of blinks through mgmt_gpio and expect to recieve the same number back ```
# housekeeping
### hk_disable
```check Housekeeping SPI disable register is working```
### hk_regs_rst_spi
```check reset value of house keeping registers by reading them trough the spi housekeeping```
### hk_regs_wr_wb_cpu
```bit bash test for housekeeping registers```
### hk_regs_wr_spi
```write then read(the written value) from random housekeeping registers through the SPI housekeeping```
### hk_regs_wr_wb
```write then read (the written value) from random housekeeping registers through the firmware but without using CPU, the SPI and system regs can't be read using firmware so the test only GPIO regs inside housekeeping ```
# uart
### uart_rx
```test uart reception```
### uart_loopback
```test uart in loopback mode input and output is shorted```
### uart_tx
```test uart transmit```
# irq
### IRQ_timer
```test timer0 interrupt```
### IRQ_external
```test external interrupt by mprj 7```
### IRQ_uart
```test timer0 interrupt```
# bitbang
### bitbang_cpu_all_i
``` configure gpio[0:37] as mgmt input using bitbang and check them```
### bitbang_spi_o
```Same as bitbang_cpu_all but configure the gpio using the SPI not the firmware```
### bitbang_spi_i
```Same as bitbang_cpu_all_i but configure the gpio using the SPI not the firmware```
### bitbang_cpu_all_o
```configure all gpios as mgmt output using bitbang and check them```
### bitbang_cpu_all_01
```shift all the register with 01```
### bitbang_cpu_all_10
```shift all the register with 10```
### bitbang_cpu_all_1100
```shift all the register with 1100```
### bitbang_cpu_all_0011
```shift all the register with 0011```
### bitbang_no_cpu_all_o
```test disable CPU and control the wishbone to configure gpio[4:37] as mgmt output using bitbang and check them```
### bitbang_no_cpu_all_i
```test disable CPU and control the wishbone to configure gpio[0:31] as mgmt input using bitbang and check them```
# timer
### timer0_oneshot
```check timer0 oneshot mode```
### timer0_periodic
```check timer0 periodic mode```
# general
### debug
```use caravel in debug mode and check reading and writing from dff2 RAM```
### clock_redirect
```check clock redirect is working as expected```
### mem_dff
```Memory stress for all space of dff```
### mem_dff2
```Memory stress for all space of dff2```
### helloWorld
```hello world test```
# housekeeping_spi
### spi_master_rd
```using SPI master for reading from external memory```
### user_pass_thru_rd
```use the housekeeping spi in user pass thru mode to read from external mem```
### spi_master_temp
```To be deleted```
### spi_rd_wr_nbyte
```try housekeeping spi Write and Read in n-byte mode ```
# la
### la
```check logic analyzer input and output enable```
# pll
### pll
```Check pll diffrent configuration```
# cpu
### cpu_stress
```stress the cpu with heavy processing```

View File

@ -1,52 +0,0 @@
#!/usr/bin/python3
import json
import os
from fnmatch import fnmatch
import collections
"""This script is for updating the README file with tests from test.json"""
with open('../../tests.json') as f:
tests_json = json.load(f)["Tests"]
tests = collections.defaultdict(lambda : collections.defaultdict()) #key is testname and value is list of sim types
for test,test_elements in tests_json.items():
if fnmatch(test,"_*"):
continue
elif fnmatch(test,"*bitbang*"):
tests["bitbang"][test] = test_elements["description"]
elif fnmatch(test,"*gpio*"):
tests["gpio"][test] = test_elements["description"]
elif fnmatch(test,"*hk*"):
tests["housekeeping"][test] = test_elements["description"]
elif fnmatch(test,"*spi*") or fnmatch(test,"*user_pass_thru*"):
tests["housekeeping_spi"][test] = test_elements["description"]
elif fnmatch(test,"*cpu*"):
tests["cpu"][test] = test_elements["description"]
elif fnmatch(test,"*irq*") or fnmatch(test,"*IRQ*"):
tests["irq"][test] = test_elements["description"]
elif fnmatch(test,"*timer*"):
tests["timer"][test] = test_elements["description"]
elif fnmatch(test,"*spi_master*"):
tests["spi_master"][test] = test_elements["description"]
elif fnmatch(test,"*uart*"):
tests["uart"][test] = test_elements["description"]
elif fnmatch(test,"*la*"):
tests["la"][test] = test_elements["description"]
elif fnmatch(test,"*pll*"):
tests["pll"][test] = test_elements["description"]
else:
tests["general"][test] = test_elements["description"]
with open("README.md", 'w') as file:
for key, value in tests.items():
file.write(f"# {key}\n")
for test,test_elements in value.items():
file.write(f"### {test} \n")
file.write(f"```{test_elements}``` \n")
for key, value in tests.items():
print(key)
print(value)

View File

@ -1,437 +0,0 @@
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
import cocotb.log
import cocotb.simulator
from cocotb.handle import SimHandleBase
from cocotb.handle import Force
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import enum
from cocotb.handle import (
ConstantObject,
HierarchyArrayObject,
HierarchyObject,
ModifiableObject,
NonHierarchyIndexableObject,
SimHandle,
)
from itertools import groupby, product
import interfaces.common as common
from interfaces.common import GPIO_MODE
from interfaces.common import MASK_GPIO_CTRL
from interfaces.common import Macros
def gpio_mode(gpios_values:list):
gpios=[]
for array in gpios_values:
gpio_value = GPIO_MODE(array[1]).name
for gpio in array[0]:
gpios.append((gpio,gpio_value))
cocotb.log.info(f'[caravel][gpio_mode] gpios {gpios}')
return gpios
Carvel_Coverage = coverage_section (
CoverPoint("top.caravel.gpio", vname="gpios mode", xf = lambda gpio ,gpio_mode: (gpio,gpio_mode) ,
bins = list(product(range(38),[e.name for e in GPIO_MODE])))
)
class Caravel_env:
def __init__(self,dut:SimHandleBase):
self.dut = dut
self.clk = dut.clock_tb
self.caravel_hdl = dut.uut
self.hk_hdl = dut.uut.housekeeping
"""start carvel by insert power then reset"""
async def start_up(self):
await self.power_up()
await self.disable_csb() # no need for this anymore as default for gpio3 is now pullup
await self.reset()
await self.disable_bins()
common.fill_macros(self.dut.macros) # get macros value
async def disable_bins(self):
for i in range(38):
if i in [3,4]: #CSB and SCK
continue
common.drive_hdl(self.dut._id(f"bin{i}_en",False),(0,0),0)
"""setup the vdd and vcc power bins"""
async def power_up(self):
cocotb.log.info(f' [caravel] start powering up')
self.set_vdd(0)
self.set_vcc(0)
await ClockCycles(self.clk, 10)
cocotb.log.info(f' [caravel] power up -> connect vdd' )
self.set_vdd(1)
# await ClockCycles(self.clk, 10)
cocotb.log.info(f' [caravel] power up -> connect vcc' )
self.set_vcc(1)
await ClockCycles(self.clk, 10)
""""reset caravel"""
async def reset(self):
cocotb.log.info(f' [caravel] start resetting')
self.dut.resetb_tb.value = 0
await ClockCycles(self.clk, 20)
self.dut.resetb_tb.value = 1
await ClockCycles(self.clk, 1)
cocotb.log.info(f' [caravel] finish resetting')
def set_vdd(self,value:bool):
self.dut.vddio_tb.value = value
self.dut.vssio_tb.value = 0
self.dut.vddio_2_tb.value = value
self.dut.vssio_2_tb.value = 0
self.dut.vdda_tb.value = value
self.dut.vssa_tb.value = 0
self.dut.vdda1_tb.value = value
self.dut.vssa1_tb.value = 0
self.dut.vdda1_2_tb.value = value
self.dut.vssa1_2_tb.value = 0
self.dut.vdda2_tb.value = value
self.dut.vssa2_tb.value = 0
def set_vcc(self , value:bool):
self.dut.vccd_tb.value = value
self.dut.vssd_tb.value = 0
self.dut.vccd1_tb.value = value
self.dut.vssd1_tb.value = 0
self.dut.vccd2_tb.value = value
self.dut.vssd2_tb.value = 0
"""drive csb signal bin E8 mprj[3]"""
async def drive_csb(self,bit):
self.drive_gpio_in((3,3),bit)
self.drive_gpio_in((4,4),0)
await ClockCycles(self.clk, 1)
"""set the spi vsb signal high to disable housekeeping spi transmission bin E8 mprj[3]"""
async def disable_csb(self ):
cocotb.log.info(f' [caravel] disable housekeeping spi transmission')
await self.drive_csb(1)
"""set the spi vsb signal high impedance """
async def release_csb(self ):
cocotb.log.info(f' [caravel] release housekeeping spi transmission')
self.release_gpio(3)
self.release_gpio(4)
await ClockCycles(self.clk, 1)
"""set the spi vsb signal low to enable housekeeping spi transmission bin E8 mprj[3]"""
async def enable_csb(self ):
cocotb.log.info(f' [caravel] enable housekeeping spi transmission')
await self.drive_csb(0)
"""return the value of mprj in bits used tp monitor the output gpios value"""
def monitor_gpio(self,bits:tuple):
mprj = self.dut.mprj_io_tb.value
size =mprj.n_bits -1 #size of bins array
mprj_out= self.dut.mprj_io_tb.value[size - bits[0]:size - bits[1]]
if(mprj_out.is_resolvable):
cocotb.log.debug(f' [caravel] Monitor : mprj[{bits[0]}:{bits[1]}] = {hex(mprj_out)}')
else:
cocotb.log.debug(f' [caravel] Monitor : mprj[{bits[0]}:{bits[1]}] = {mprj_out}')
return mprj_out
"""return the value of management gpio"""
def monitor_mgmt_gpio(self):
data = self.dut.gpio_tb.value
cocotb.log.debug(f' [caravel] Monitor mgmt gpio = {data}')
return data
"""change the configration of the gpios by overwrite their defaults value then reset
need to take at least 1 cycle for reset """
### dont use back door accessing
async def configure_gpio_defaults(self,gpios_values: list):
gpio_defaults = self.caravel_hdl.gpio_defaults.value
cocotb.log.info(f' [caravel] start cofigure gpio gpios ')
size = gpio_defaults.n_bits -1 #number of bins in gpio_defaults
# list example [[(gpios),value],[(gpios),value],[(gpios),value]]
for array in gpios_values:
gpio_value = array[1]
for gpio in array[0]:
self.cov_configure_gpios(gpio,gpio_value.name)
gpio_defaults[size - (gpio*13 + 12): size -gpio*13] = gpio_value.value
#cocotb.log.info(f' [caravel] gpio_defaults[{size - (gpio*13 + 12)}:{size -gpio*13}] = {gpio_value.value} ')
self.caravel_hdl.gpio_defaults.value = gpio_defaults
#reset
self.caravel_hdl.gpio_resetn_1_shifted.value = 0
self.caravel_hdl.gpio_resetn_2_shifted.value = 0
await ClockCycles(self.clk, 1)
self.caravel_hdl.gpio_resetn_1_shifted.value = 1
self.caravel_hdl.gpio_resetn_2_shifted.value = 1
cocotb.log.info(f' [caravel] finish configuring gpios, the curret gpios value: ')
self.print_gpios_ctrl_val()
"""change the configration of the gpios by overwrite the register value
in control registers and housekeeping regs, don't consume simulation cycles"""
### dont use back door accessing
def configure_gpios_regs(self,gpios_values: list):
cocotb.log.info(f' [caravel] start cofigure gpio gpios ')
control_modules = self.control_blocks_paths()
# list example [[(gpios),value],[(gpios),value],[(gpios),value]]
for array in gpios_values:
gpio_value = array[1]
for gpio in array[0]:
self.cov_configure_gpios(gpio,gpio_value.name)
self.gpio_control_reg_write(control_modules[gpio],gpio_value.value) # for control blocks regs
self.caravel_hdl.housekeeping.gpio_configure[gpio].value = gpio_value.value # for house keeping regs
cocotb.log.info(f' [caravel] finish configuring gpios, the curret gpios value: ')
self.print_gpios_ctrl_val()
self.print_gpios_HW_val()
"""dummy function for coverage sampling"""
@Carvel_Coverage
def cov_configure_gpios(self,gpio,gpio_mode):
cocotb.log.debug(f' [caravel] gpio [{gpio}] = {gpio_mode} ')
pass
def print_gpios_default_val(self,print=1):
gpio_defaults = self.caravel_hdl.gpio_defaults.value
size = gpio_defaults.n_bits -1 #number of bins in gpio_defaults
gpios = []
for gpio in range(Macros['MPRJ_IO_PADS']):
gpio_value = gpio_defaults[size - (gpio*13 + 12): size -gpio*13]
gpio_enum = GPIO_MODE(gpio_value.integer)
gpios.append((gpio,gpio_enum))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
"""print the values return in the gpio of control block mode in GPIO Mode format"""
def print_gpios_ctrl_val(self, print=1):
control_modules = self.control_blocks_paths()
gpios = []
for i , gpio in enumerate(control_modules):
gpios.append((i,self.gpio_control_reg_read(gpio)))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
def _check_gpio_ctrl_eq_HW(self):
assert self.print_gpios_ctrl_val(1) == self.print_gpios_HW_val(1), f'there is an issue while configuration the control block register value isn\'t the same as the house keeping gpio register'
"""print the values return in the gpio of housekeeping block mode in GPIO Mode format"""
def print_gpios_HW_val(self,print=1):
gpios = []
for pin in range(Macros['MPRJ_IO_PADS']):
gpios.append((pin,GPIO_MODE(self.caravel_hdl.housekeeping.gpio_configure[pin].value)))
group_bins = groupby(gpios,key=lambda x: x[1])
for key,value in group_bins:
gpios=[]
for gpio in list(value):
gpios.append(gpio[0])
if (print):
cocotb.log.info(f' [caravel] gpios[{gpios}] are {key} ')
return gpios
"""return the paths of the control blocks"""
def control_blocks_paths(self)-> list:
car = self.caravel_hdl
control_modules =[car._id("gpio_control_bidir_1[0]",False),car._id("gpio_control_bidir_1[1]",False)]
#add gpio_control_in_1a (GPIO 2 to 7)
for i in range(6):
control_modules.append(car._id(f'gpio_control_in_1a[{i}]',False))
#add gpio_control_in_1 (GPIO 8 to 18)
for i in range(Macros['MPRJ_IO_PADS_1']-9+1):
control_modules.append(car._id(f'gpio_control_in_1[{i}]',False))
#add gpio_control_in_2 (GPIO 19 to 34)
for i in range(Macros['MPRJ_IO_PADS_2']-4+1):
control_modules.append(car._id(f'gpio_control_in_2[{i}]',False))
# Last three GPIOs (spi_sdo, flash_io2, and flash_io3) gpio_control_bidir_2
for i in range(3):
control_modules.append(car._id(f'gpio_control_bidir_2[{i}]',False))
return control_modules
"""read the control register and return a GPIO Mode it takes the path to the control reg"""
def gpio_control_reg_read(self,path:SimHandleBase) -> GPIO_MODE:
gpio_mgmt_en = path.mgmt_ena.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_MGMT_EN.value
gpio_out_dis = path.gpio_outenb.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_OUT_DIS.value
gpio_holdover = path.gpio_holdover.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_OVERRIDE.value
gpio_in_dis = path.gpio_inenb.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_INP_DIS.value
gpio_mode_sel = path.gpio_ib_mode_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_MOD_SEL.value
gpio_anlg_en = path.gpio_ana_en.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_EN.value
gpio_anlg_sel = path.gpio_ana_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_SEL.value
gpio_anlg_pol = path.gpio_ana_pol.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_POL.value
gpio_slow_sel = path.gpio_slow_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_SLOW.value
gpio_vtrip_sel = path.gpio_vtrip_sel.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_TRIP.value
gpio_dgtl_mode = path.gpio_dm.value << MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value
control_reg = (gpio_mgmt_en | gpio_out_dis | gpio_holdover| gpio_in_dis | gpio_mode_sel | gpio_anlg_en
|gpio_anlg_sel|gpio_anlg_pol|gpio_slow_sel|gpio_vtrip_sel|gpio_dgtl_mode)
return(GPIO_MODE(control_reg))
"""read the control register and return a GPIO Mode it takes the path to the control reg"""
def gpio_control_reg_write(self,path:SimHandleBase,data) :
bits =common.int_to_bin_list(data,14)
path.mgmt_ena.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_MGMT_EN.value]
path.gpio_outenb.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_OUT_DIS.value]
path.gpio_holdover.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_OVERRIDE.value]
path.gpio_inenb.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_INP_DIS.value]
path.gpio_ib_mode_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_MOD_SEL.value]
path.gpio_ana_en.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_EN.value]
path.gpio_ana_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_SEL.value]
path.gpio_ana_pol.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_ANLG_POL.value]
path.gpio_slow_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_SLOW.value]
path.gpio_vtrip_sel.value = bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_TRIP.value]
gpio_dm =bits[MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value:MASK_GPIO_CTRL.MASK_GPIO_CTRL_DGTL_MODE.value+3]
gpio_dm =sum(d * 2**i for i, d in enumerate(gpio_dm)) # convert list to binary int
path.gpio_dm.value = gpio_dm
# """drive the value of mprj bits with spicific data from input pad at the top"""
# def release_gpio(self):
# io = self.caravel_hdl.padframe.mprj_pads.io
# mprj , n_bits = common.signal_valueZ_size(io)
# io.value = mprj
# cocotb.log.info(f' [caravel] drive_gpio_in pad mprj with {mprj}')
"""drive the value of mprj bits with spicific data from input pad at the top"""
def drive_gpio_in(self,bits,data):
# io = self.caravel_hdl.padframe.mprj_pads.io
# mprj , n_bits = common.signal_value_size(io)
# cocotb.log.debug(f' [caravel] before mprj with {mprj} and data = {data} bit [{n_bits-1-bits[0]}]:[{n_bits-1-bits[1]}]')
# mprj[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
# io.value = mprj
# cocotb.log.info(f' [caravel] drive_gpio_in pad mprj with {mprj}')
data_bits = []
is_list = isinstance(bits, (list,tuple))
if is_list :
cocotb.log.debug(f'[caravel] [drive_gpio_in] start bits[1] = {bits[1]} bits[0]= {bits[0]}')
data_bits = BinaryValue(value = data, n_bits =bits[0]-bits[1]+1 ,bigEndian=(bits[0]<bits[1]))
for i,bits2 in enumerate(range(bits[1],bits[0]+1)):
self.dut._id(f"bin{bits2}",False).value = data_bits[i]
self.dut._id(f"bin{bits2}_en",False).value = 1
cocotb.log.debug(f'[caravel] [drive_gpio_in] drive bin{bits2} with {data_bits[i]} and bin{bits2}_en with 1')
else:
self.dut._id(f'bin{bits}',False).value = data
self.dut._id(f'bin{bits}_en',False).value = 1
cocotb.log.debug(f'[caravel] [drive_gpio_in] drive bin{bits} with {data} and bin{bits}_en with 1')
""" release driving the value of mprj bits """
def release_gpio(self,bits):
data_bits = []
is_list = isinstance(bits, (list,tuple))
if is_list :
cocotb.log.debug(f'[caravel] [drive_gpio_disable] start bits[1] = {bits[1]} bits[0]= {bits[0]}')
for i,bits2 in enumerate(range(bits[1],bits[0]+1)):
self.dut._id(f"bin{bits2}_en",False).value = 0
cocotb.log.debug(f'[caravel] [drive_gpio_disable] release driving bin{bits2}')
else:
self.dut._id(f'bin{bits}_en',False).value = 0
cocotb.log.debug(f'[caravel] [drive_gpio_disable] release driving bin{bits}')
"""drive the value of gpio management"""
def drive_mgmt_gpio(self,data):
mgmt_io = self.dut.gpio_tb
mgmt_io.value = data
cocotb.log.info(f' [caravel] drive_mgmt_gpio through management area mprj with {data}')
"""update the value of mprj bits with spicific data then after certain number of cycle drive z to free the signal"""
async def drive_gpio_in_with_cycles(self,bits,data,num_cycles):
self.drive_gpio_in(bits,data)
cocotb.log.info(f' [caravel] wait {num_cycles} cycles')
await cocotb.start(self.wait_then_undrive(bits,num_cycles))
cocotb.log.info(f' [caravel] finish drive_gpio_with_in_cycles ')
"""drive the value of mprj bits with spicific data from management area then after certain number of cycle drive z to free the signal"""
async def drive_mgmt_gpio_with_cycles(self,bits,data,num_cycles):
self.drive_mgmt_gpio(bits,data)
cocotb.log.info(f' [caravel] wait {num_cycles} cycles')
await cocotb.start(self.wait_then_undrive(bits,num_cycles))
cocotb.log.info(f' [caravel] finish drive_gpio_with_in_cycles ')
async def wait_then_undrive(self,bits,num_cycles):
await ClockCycles(self.clk, num_cycles)
n_bits = bits[0]-bits[1]+1
self.drive_gpio_in(bits, (n_bits)* 'z')
cocotb.log.info(f' [caravel] finish wait_then_drive ')
async def hk_write_byte(self, data):
self.path = self.dut.mprj_io_tb
data_bit = BinaryValue(value = data , n_bits = 8,bigEndian=False)
for i in range(7,-1,-1):
# for j in range(4):
# await FallingEdge(self.clk)
# await Timer(7, units='ns')
await FallingEdge(self.clk)
#common.drive_hdl(self.path,[(4,4),(2,2)],[0,int(data_bit[i])]) # 2 = SDI 4 = SCK
self.drive_gpio_in((2,2),int(data_bit[i]))
self.drive_gpio_in((4,4),0)
await RisingEdge(self.clk)
self.drive_gpio_in((4,4),1)
await FallingEdge(self.clk)
""" read byte using housekeeping spi
when writing to SCK we can't use mprj[4] as there is a limitation in cocotb for accessing pack array #2587
so use back door access to write the clock then read the output from the SDO mprj[1] value"""
async def hk_read_byte(self,last_read= False):
read_data =''
for i in range(8,0,-1):
self.drive_gpio_in((4,4),1)# SCK
await FallingEdge(self.clk)
self.drive_gpio_in((4,4),0)# SCK
await RisingEdge(self.clk)
read_data= f'{read_data}{self.dut.mprj_io_tb.value[37-1]}'
await FallingEdge(self.clk)
self.drive_gpio_in((4,4),0) # SCK
# if (last_read):
# common.drive_hdl(self.dut.bin4_en,(0,0),'z') #4 = SCK
# common.drive_hdl(self.path,[(1,1)],'z')
return int(read_data,2)
"""write to the house keeping registers by back door no need for commands and waiting for the data to show on mprj"""
async def hk_write_backdoor(self,addr, data):
await RisingEdge(self.dut.wb_clk_i)
self.hk_hdl.wb_stb_i.value = 1
self.hk_hdl.wb_cyc_i.value = 1
self.hk_hdl.wb_sel_i.value = 0xF
self.hk_hdl.wb_we_i.value = 1
self.hk_hdl.wb_adr_i.value = addr
self.hk_hdl.wb_dat_i.value = data
cocotb.log.info(f'Monitor: Start Writing to {hex(addr)} -> {data}')
await FallingEdge(self.dut.wb_ack_o) # wait for acknowledge
self.hk_hdl.wb_stb_i.value = 0
self.hk_hdl.wb_cyc_i.value = 0
cocotb.log.info(f'Monitor: End writing {hex(addr)} -> {data}')
"""read from the house keeping registers by back door no need for commands and waiting for the data to show on mprj"""
async def hk_read_backdoor(self,addr):
await RisingEdge(self.clk)
self.hk_hdl.wb_stb_i.value = 1
self.hk_hdl.wb_cyc_i.value = 1
self.hk_hdl.wb_sel_i.value = 0
self.hk_hdl.wb_we_i.value = 0
self.hk_hdl.wb_adr_i.value = addr
cocotb.log.info(f' [housekeeping] Monitor: Start reading from {hex(addr)}')
await FallingEdge(self.hk_hdl.wb_ack_o)
self.hk_hdl.wb_stb_i.value = 0
self.hk_hdl.wb_cyc_i.value = 0
cocotb.log.info(f' [housekeeping] Monitor: read from {hex(addr)} value {(self.hk_hdl.wb_dat_o.value)}')
return self.hk_hdl.wb_dat_o.value

View File

@ -1,80 +0,0 @@
from cocotb.handle import SimHandleBase
from cocotb.binary import BinaryValue
from enum import Enum
import cocotb
"""return the value and the size of the signal"""
def signal_value_size(path:SimHandleBase):
value = path.value
size = value.n_bits
return value, size
"""
Create a binaryValue object with all Z that helps when drive to drive only the bits needed
return value with all z and the size
"""
def signal_valueZ_size(path:SimHandleBase):
value = path.value
size = value.n_bits
value = BinaryValue(value = int(size) * 'z',n_bits=size)
return value, size
def int_to_bin_list(number:bin,number_of_bits)-> list:
data = bin(number)
data = data[2:].zfill(number_of_bits)[::-1]
bits = [int(bit) for bit in data]
return bits
def drive_hdl(path,bits,data):
hdl , n_bits = signal_value_size(path)
is_list_of_lists = all(isinstance(x, list) for x in bits)
is_list_of_tuples = all(isinstance(x, tuple) for x in bits)
if is_list_of_lists | is_list_of_tuples:
for i,bits2 in enumerate(bits):
hdl[n_bits-1-bits2[0]:n_bits-1-bits2[1]] = data[i]
else:
hdl[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
path.value = hdl
cocotb.log.debug(f' [common] drive { path._path } with {hdl}')
"""Enum for GPIO modes valus used to configured the pins"""
class GPIO_MODE(Enum):
GPIO_MODE_MGMT_STD_INPUT_NOPULL = 0x0403
GPIO_MODE_MGMT_STD_INPUT_PULLDOWN = 0x0803
GPIO_MODE_MGMT_STD_INPUT_PULLUP = 0x0c03
GPIO_MODE_MGMT_STD_OUTPUT = 0x1809
GPIO_MODE_MGMT_STD_INPUT = 0x1803 # TODO: ask if this legal the default value for first 2 bin is like that
GPIO_MODE_MGMT_STD_BIDIRECTIONAL = 0x1801
GPIO_MODE_MGMT_STD_ANALOG = 0x000b
GPIO_MODE_USER_STD_INPUT_NOPULL = 0x0402
GPIO_MODE_USER_STD_INPUT_PULLDOWN = 0x0802
GPIO_MODE_USER_STD_INPUT_PULLUP = 0x0c02
GPIO_MODE_USER_STD_OUTPUT = 0x1808
GPIO_MODE_USER_STD_BIDIRECTIONAL = 0x1800
GPIO_MODE_USER_STD_OUT_MONITORED = 0x1802
GPIO_MODE_USER_STD_ANALOG = 0x000a
class MASK_GPIO_CTRL(Enum):
MASK_GPIO_CTRL_MGMT_EN = 0
MASK_GPIO_CTRL_OUT_DIS = 1
MASK_GPIO_CTRL_OVERRIDE = 2
MASK_GPIO_CTRL_INP_DIS = 3
MASK_GPIO_CTRL_MOD_SEL = 4
MASK_GPIO_CTRL_ANLG_EN = 5
MASK_GPIO_CTRL_ANLG_SEL = 6
MASK_GPIO_CTRL_ANLG_POL = 7
MASK_GPIO_CTRL_SLOW = 8
MASK_GPIO_CTRL_TRIP = 9
MASK_GPIO_CTRL_DGTL_MODE = 10
Macros= {}
def fill_macros(macros_hdl):
Macros['MPRJ_IO_PADS_1'] = macros_hdl.MPRJ_IO_PADS_1.value.integer
Macros['MPRJ_IO_PADS_2'] = macros_hdl.MPRJ_IO_PADS_2.value.integer
Macros['MPRJ_IO_PADS'] = macros_hdl.MPRJ_IO_PADS.value.integer
Macros['GL'] = macros_hdl.GL.value.integer
Macros['CARAVAN'] = macros_hdl.CARAVAN.value.integer

View File

@ -1,238 +0,0 @@
from operator import add
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
import cocotb.simulator
from cocotb.handle import SimHandleBase
from cocotb.handle import Force
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import enum
from cocotb.handle import (
ConstantObject,
HierarchyArrayObject,
HierarchyObject,
ModifiableObject,
NonHierarchyIndexableObject,
SimHandle,
)
from itertools import groupby, product
import interfaces.common as common
from interfaces.common import GPIO_MODE
from interfaces.common import MASK_GPIO_CTRL
from interfaces.common import Macros
class RiskV:
def __init__(self,dut:SimHandleBase):
self.dut = dut
self.clk = dut.clock_tb
if not Macros['GL']:
self.cpu_hdl = dut.uut.soc.core.VexRiscv
else:
self.cpu_hdl = dut.uut.soc
self.debug_hdl = dut.uut.mprj.debug
self.force_reset = 0
if not Macros['GL']:
cocotb.scheduler.add(self.force_reset_fun())
""" """
async def drive_data_with_address(self,address,data,SEL=0xF):
self.cpu_hdl.dBusWishbone_CYC.value = 1
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 1
self.cpu_hdl.dBusWishbone_SEL.value = SEL
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = data
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = BinaryValue(value = 'z')
self.cpu_hdl.iBusWishbone_CYC.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_STB.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_WE.value = BinaryValue(value = 'z')
self.cpu_hdl.dBusWishbone_SEL.value = BinaryValue(value = 'zzzz')
self.cpu_hdl.dBusWishbone_ADR.value = common.signal_valueZ_size(self.cpu_hdl.dBusWishbone_ADR)[0]
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = common.signal_valueZ_size(self.cpu_hdl.dBusWishbone_DAT_MOSI)[0]
""" """
async def drive_data2address(self,address,data,SEL=0xF):
cocotb.log.info(f"[RiskV][drive_data2address] start driving address {hex(address)} with {hex(data)}")
# print(dir(self.cpu_hdl))
dBusWishbone_CYC = self.cpu_hdl.dBusWishbone_CYC.value
if not Macros['GL']:
iBusWishbone_CYC = self.cpu_hdl.iBusWishbone_CYC.value
dBusWishbone_STB = self.cpu_hdl.dBusWishbone_STB.value
dBusWishbone_WE = self.cpu_hdl.dBusWishbone_WE.value
if not Macros['GL']:
dBusWishbone_SEL = self.cpu_hdl.dBusWishbone_SEL.value
else:
dBusWishbone_SEL0 = self.cpu_hdl.net2121.value
dBusWishbone_SEL1 = self.cpu_hdl.net1979.value
dBusWishbone_SEL2 = self.cpu_hdl.net848.value
dBusWishbone_SEL3 = self.cpu_hdl.net1956.value
if not Macros['GL']:
dBusWishbone_ADR = self.cpu_hdl.dBusWishbone_ADR.value
dBusWishbone_DAT_MOSI = self.cpu_hdl.dBusWishbone_DAT_MOSI.value
self.cpu_hdl.dBusWishbone_CYC.value = 1
if not Macros['GL']:
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_SEL.value = SEL
else:
self.cpu_hdl.net2121.value = (SEL >>0 ) &1
self.cpu_hdl.net1979.value = (SEL >>1 ) &1
self.cpu_hdl.net848.value = (SEL >>2 ) &1
self.cpu_hdl.net1956.value = (SEL >>3 ) &1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
else:
address_temp = address >> 2
for i in range(30):
self.cpu_hdl._id(f'dBusWishbone_ADR[{i}]',False).value = (address_temp >> i) & 1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = data
else:
for i in range(32):
self.cpu_hdl._id(f'dBusWishbone_DAT_MOSI[{i}]',False).value = (data >> i) & 1
if not Macros['GL']:
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
else:
# await RisingEdge(self.cpu_hdl._id("_07019_",False) & (self.cpu_hdl._id("grant[0]",False)))
await RisingEdge(self.cpu_hdl._id("_07019_",False) )
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = dBusWishbone_CYC
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = dBusWishbone_ADR
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = dBusWishbone_DAT_MOSI
self.cpu_hdl.iBusWishbone_CYC.value = iBusWishbone_CYC
self.cpu_hdl.dBusWishbone_STB.value = dBusWishbone_STB
self.cpu_hdl.dBusWishbone_WE.value = dBusWishbone_WE
self.cpu_hdl.dBusWishbone_SEL.value = dBusWishbone_SEL
await ClockCycles(self.clk, 1)
cocotb.log.info(f"[RiskV][drive_data2address] finish driving address {hex(address)} with {hex(data)}")
""" """
async def read_address(self,address,SEL=0xF):
cocotb.log.info(f"[RiskV][read_address] start reading address {hex(address)}")
# print(dir(self.cpu_hdl))
dBusWishbone_CYC = self.cpu_hdl.dBusWishbone_CYC.value
if not Macros['GL']:
iBusWishbone_CYC = self.cpu_hdl.iBusWishbone_CYC.value
dBusWishbone_STB = self.cpu_hdl.dBusWishbone_STB.value
dBusWishbone_WE = self.cpu_hdl.dBusWishbone_WE.value
if not Macros['GL']:
dBusWishbone_SEL = self.cpu_hdl.dBusWishbone_SEL.value
else:
dBusWishbone_SEL0 = self.cpu_hdl.net2121.value
dBusWishbone_SEL1 = self.cpu_hdl.net1979.value
dBusWishbone_SEL2 = self.cpu_hdl.net848.value
dBusWishbone_SEL3 = self.cpu_hdl.net1956.value
if not Macros['GL']:
dBusWishbone_ADR = self.cpu_hdl.dBusWishbone_ADR.value
dBusWishbone_DAT_MOSI = self.cpu_hdl.dBusWishbone_DAT_MOSI.value
self.cpu_hdl.dBusWishbone_CYC.value = 1
if not Macros['GL']:
self.cpu_hdl.iBusWishbone_CYC.value = 0
self.cpu_hdl.dBusWishbone_STB.value = 1
self.cpu_hdl.dBusWishbone_WE.value = 0
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_SEL.value = SEL
else:
self.cpu_hdl.net2121.value = (SEL >>0 ) &1
self.cpu_hdl.net1979.value = (SEL >>1 ) &1
self.cpu_hdl.net848.value = (SEL >>2 ) &1
self.cpu_hdl.net1956.value = (SEL >>3 ) &1
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = address >> 2
else:
address_temp = address >> 2
for i in range(30):
self.cpu_hdl._id(f'dBusWishbone_ADR[{i}]',False).value = (address_temp >> i) & 1
if not Macros['GL']:
await RisingEdge(self.cpu_hdl.dBusWishbone_ACK)
else:
# await RisingEdge(self.cpu_hdl._id("_07019_",False) & (self.cpu_hdl._id("grant[0]",False)))
await RisingEdge(self.cpu_hdl._id("_07019_",False) )
await ClockCycles(self.clk, 1)
self.cpu_hdl.dBusWishbone_CYC.value = dBusWishbone_CYC
if not Macros['GL']:
self.cpu_hdl.dBusWishbone_ADR.value = dBusWishbone_ADR
self.cpu_hdl.dBusWishbone_DAT_MOSI.value = dBusWishbone_DAT_MOSI
self.cpu_hdl.iBusWishbone_CYC.value = iBusWishbone_CYC
self.cpu_hdl.dBusWishbone_STB.value = dBusWishbone_STB
self.cpu_hdl.dBusWishbone_WE.value = dBusWishbone_WE
self.cpu_hdl.dBusWishbone_SEL.value = dBusWishbone_SEL
data = self.cpu_hdl.dBusWishbone_DAT_MISO.value
await ClockCycles(self.clk, 1)
cocotb.log.info(f"[RiskV][read_address] finish reading address {hex(address)} data = {data}")
# return data
return int(str(bin(data.integer)[2:]).zfill(32),2)
# return int(str(bin(data.integer)[2:]).zfill(32)[::-1],2)
def read_debug_reg1(self):
return self.debug_hdl.debug_reg_1.value.integer
def read_debug_reg2(self):
return self.debug_hdl.debug_reg_2.value.integer
def read_debug_reg1_str(self):
return self.debug_hdl.debug_reg_1.value.binstr
def read_debug_reg2_str(self):
return self.debug_hdl.debug_reg_2.value.binstr
# writing debug registers using backdoor because in GL cpu can't be disabled for now because of different netlist names
def write_debug_reg1_backdoor(self,data):
self.debug_hdl.debug_reg_1.value = data
def write_debug_reg2_backdoor(self,data):
self.debug_hdl.debug_reg_2.value = data
async def force_reset_fun(self):
first_time_force = True
first_time_release = True
while True:
if self.force_reset:
if first_time_force:
cocotb.log.info(f"[RiskV][force_reset_fun] Force CPU reset")
first_time_force = False
first_time_release = True
self.cpu_hdl.reset.value =1
if not Macros['GL']:
common.drive_hdl(self.cpu_hdl.reset,(0,0),1)
else:
common.drive_hdl(self.cpu_hdl.mgmtsoc_vexriscv_debug_reset,(0,0),1)
else:
if first_time_release:
first_time_force = True
first_time_release = False
if not Macros['GL']:
common.drive_hdl(self.cpu_hdl.reset,(0,0),0)
else:
common.drive_hdl(self.cpu_hdl.mgmtsoc_vexriscv_debug_reset,(0,0),0)
cocotb.log.info(f"[RiskV][force_reset_fun] release CPU reset")
await ClockCycles(self.clk, 1)
def cpu_force_reset(self):
self.force_reset = True
def cpu_release_reset(self):
self.force_reset = False

View File

@ -1,87 +0,0 @@
import re
import sys
from tokenize import group
from unittest.util import _MIN_COMMON_LEN
import string
import cocotb
import os
class Regs:
def __init__(self):
pass
def get_addr(self,reg):
search1 = self.get_add_defs(reg)
# if all(c in string.hexdigits for c in search1[2:]):
return int(search1,16)
# return hex(self.get_hexa(search1))
"""get address from defs.h"""
def get_add_defs(self,reg):
pattern = re.compile(rf'#define {reg}\s*\(\*\(volatile uint32_t\*\)\s*(.*)\s*\)')
with open(f'{os.getenv("FIRMWARE_PATH")}/defs.h') as f:
for line in f:
m= re.search(pattern,line)
if m:
break
if m:
if not all(c in string.hexdigits for c in m.group(1)):
return hex(self.get_hexa(m.group(1)))
else:
return m.group(1)
else:
cocotb.log.info(f" [defsParser] can't find {reg} inside defs")
sys.exit()
"""get address from defs.h"""
def get_add_csr(self,reg):
pattern1 = re.compile(rf'#define {reg}\s*\(\*\(volatile uint32_t\*\)\s*(.*)\s*\)')
pattern2 = re.compile(rf'#define {reg}\s*(.*)')
m = False
with open(f'{os.getenv("FIRMWARE_PATH")}/../generated/csr.h') as f:
for line in f:
m1= re.search(pattern1,line)
m2= re.search(pattern2,line)
if m1:
m = m1
break
if m2:
m=m2
break
if m:
matched_str= m.group(1)
if matched_str[-1] == "L" and matched_str[-2].isnumeric:
matched_str = matched_str[:-1]
if not all(c in string.hexdigits for c in matched_str[2:]):
matched_str= hex(self.get_hexa(matched_str))
return matched_str
else:
cocotb.log.info(f" [defsParser] can't find {reg} inside csr")
sys.exit()
def get_hexa(self,s:string):
pattern2 = re.compile(r'\((.*)\s*\+\s*(.*)\)')
search_match = re.search(pattern2,s)
if search_match :
matches = [search_match.group(1),search_match.group(2)]
else:
matches = [s]
nothex = 1
while nothex:
nothex = 0
for i,match in enumerate(matches):
if not all(c in string.hexdigits for c in match[2:-1]):
matches[i]=self.get_add_csr(match)
nothex = 0
else:
if match[-1] == "L" and match[-2].isnumeric:
matches[i]=matches[i][:-1]
if len(matches) ==2:
return int(matches[0],16) + int(matches[1],16)
else:
return int(matches[0],16)

View File

@ -1,84 +0,0 @@
import random
import cocotb
from cocotb.clock import Clock
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
import cocotb.simulator
from cocotb.handle import SimHandleBase
from cocotb.handle import Force
from cocotb_coverage.coverage import *
from cocotb.binary import BinaryValue
import enum
from cocotb.handle import (
ConstantObject,
HierarchyArrayObject,
HierarchyObject,
ModifiableObject,
NonHierarchyIndexableObject,
SimHandle,
)
from itertools import groupby, product
import interfaces.common as common
from interfaces.common import GPIO_MODE
from interfaces.common import MASK_GPIO_CTRL
from interfaces.common import Macros
class LA:
def __init__(self,dut:SimHandleBase):
self.dut = dut
self.clk = dut.clock_tb
self.core_hdl = dut.uut.soc.core
""" Configure the value of LA probes [0:127]
writing 1 to any bit means bit acts as outputs from the cpu
writing 0 to any bit means bit acts as inputs to the cpu """
async def configure_la_en(self, bits,data):
self.__drive_la_iena(bits,data)
self.__drive_la_oenb(bits,data)
await ClockCycles(self.clk, 1)
def __drive_la_iena(self, bits,data):
iena , n_bits = common.signal_value_size(self.core_hdl.la_ien_storage)
cocotb.log.debug(f' [LA] before change iena with {iena} and data = {data} bit [{n_bits-1-bits[0]}]:[{n_bits-1-bits[1]}]')
iena[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
self.core_hdl.la_ien_storage.value = iena
cocotb.log.info(f' [LA] drive reg_la_iena with {hex(iena)}')
def __drive_la_oenb(self, bits,data):
oenb , n_bits = common.signal_value_size(self.core_hdl.la_oe_storage)
cocotb.log.debug(f' [LA] before change oenb with {oenb} and data = {data} bit [{n_bits-1-bits[0]}]:[{n_bits-1-bits[1]}]')
oenb[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
self.core_hdl.la_oe_storage.value = oenb
cocotb.log.info(f' [LA] drive reg_la_oenb with {hex(oenb)}')
""" update the value of LA data input from cpu to user project """
def drive_la_data_to_user(self,bits,data):
la , n_bits = common.signal_value_size(self.core_hdl.la_out_storage)
cocotb.log.debug(f' [LA] before la data update with LA ={la} and data = {data} bit [{n_bits-1-bits[0]}]:[{n_bits-1-bits[1]}]')
la[n_bits-1-bits[0]:n_bits-1-bits[1]] = data
self.core_hdl.la_out_storage.value = la
cocotb.log.info(f' [LA] drive_la_data_to_user: drive data {hex(la)} to user project')
"""return the value of LA data output from user project tp cpu"""
def check_la_user_out(self):
LA_out = self.core_hdl.la_input.value
if(LA_out.is_resolvable):
cocotb.log.info(f' [LA] Monitor : reg_la_data_out from user = {hex(LA_out)}')
else:
cocotb.log.info(f' [LA] Monitor : reg_la_data_out from user = {LA_out}')
return LA_out
"""return the value of LA data output from user project tp cpu"""
def check_la_ctrl_reg(self):
LA_out = self.dut.uut.la_oenb_mprj.value
if(LA_out.is_resolvable):
cocotb.log.info(f' [LA] Monitor : reg_la_data_out from user = {hex(LA_out)}')
else:
cocotb.log.info(f' [LA] Monitor : reg_la_data_out from user = {LA_out}')
return LA_out

View File

@ -1 +0,0 @@
acc+=rw,wn:*

View File

@ -1,7 +0,0 @@
initial begin
`ifndef CARAVAN
$sdf_annotate({`MAIN_PATH,"/../../../signoff/caravel/primetime-signoff/sdf/",`CORNER,"/caravel.", `SDF_POSTFIX,".sdf"}, uut,,{`MAIN_PATH,"/sim/",`TAG,"/",`FTESTNAME,"/caravel_sdf.log"},"MINIMUM");
`else
$sdf_annotate({`MAIN_PATH,"/../../../signoff/caravan/primetime-signoff/sdf/",`CORNER,"/caravan.", `SDF_POSTFIX,".sdf"}, uut,,{`MAIN_PATH,"/sim/",`TAG,"/",`FTESTNAME,"/caravan_sdf.log"},"MINIMUM");
`endif
end

View File

@ -1,355 +0,0 @@
{
"Tests": {
"_comment0" :"level is priorty of the test low is better, SW spcify if the test uses SW, RTL regressions run this test in RTL ",
"_comment1" :"GL regressions run this test in gatelevel, GL_SDF regression run this test with SDF included"
,"gpio_all_i" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as mgmt input using automatic approach firmware and check them"}
,"gpio_all_i_caravan" :{"level":0,
"SW":true,
"RTL":["r_caravan_rtl"],
"GL":["r_caravan_gl"],
"GL_SDF":["r_caravan_sdf"],
"description":"configure all gpios as mgmt input using automatic approach firmware and check them for caravan"}
,"hk_disable" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"check Housekeeping SPI disable register is working"}
,"uart_rx" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"test uart reception"}
,"hk_regs_rst_spi" :{"level":0,
"SW":false,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"check reset value of house keeping registers by reading them trough the spi housekeeping"}
,"gpio_all_i_user" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as user input using automatic approach firmware and check them"}
,"gpio_all_i_pu" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as mgmt input pull up using automatic approach firmware and check them"}
,"gpio_all_i_pu_caravan" :{"level":0,
"SW":true,
"RTL":["r_caravan_rtl"],
"GL":["r_caravan_gl"],
"GL_SDF":["r_caravan_sdf"],
"description":"configure all gpios as mgmt input pull up using automatic approach firmware and check them for caravan"}
,"gpio_all_i_pu_user" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as user input pull up using automatic approach firmware and check them"}
,"gpio_all_i_pd" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as mgmt input pull down using automatic approach firmware and check them"}
,"gpio_all_i_pd_caravan" :{"level":0,
"SW":true,
"RTL":["r_caravan_rtl"],
"GL":["r_caravan_gl"],
"GL_SDF":["r_caravan_sdf"],
"description":"configure all gpios as mgmt input pull down using automatic approach firmware and check them for caravan"}
,"gpio_all_i_pd_user" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as user input pull down using automatic approach firmware and check them"}
,"gpio_all_bidir_user" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as user bidir using automatic approach firmware and check them"}
,"gpio_all_o" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as mgmt output using automatic approach firmware and check them"}
,"gpio_all_o_caravan" :{"level":0,
"SW":true,
"RTL":["r_caravan_rtl"],
"GL":["r_caravan_gl"],
"GL_SDF":["r_caravan_sdf"],
"description":"configure all gpios as mgmt output using automatic approach firmware and check them for caravan"}
,"gpio_all_o_user" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as user output using automatic approach firmware and check them"}
,"hk_regs_wr_wb_cpu" :{"level":0,
"SW":false,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"bit bash test for housekeeping registers"}
,"IRQ_timer" :{"level":2,
"SW":true,
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"test timer0 interrupt"}
,"bitbang_cpu_all_i" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":" configure gpio[0:37] as mgmt input using bitbang and check them"}
,"bitbang_spi_o" :{"level":0,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"SW":true,
"description":"Same as bitbang_cpu_all but configure the gpio using the SPI not the firmware"}
,"mgmt_gpio_out" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"tests blinking of mgmt gpio bit as an output"}
,"bitbang_spi_i" :{"level":0,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"SW":true,
"description":"Same as bitbang_cpu_all_i but configure the gpio using the SPI not the firmware"}
,"hk_regs_wr_spi" :{"level":0,
"SW":false,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"write then read(the written value) from random housekeeping registers through the SPI housekeeping"}
,"IRQ_external" :{"level":2,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"test external interrupt by mprj 7"}
,"IRQ_uart" :{"level":2,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"test timer0 interrupt"}
,"mgmt_gpio_in" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"tests blinking of mgmt gpio bit as an output"}
,"timer0_oneshot" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"check timer0 oneshot mode"}
,"uart_loopback" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"test uart in loopback mode input and output is shorted"}
,"timer0_periodic" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"check timer0 periodic mode"}
,"uart_tx" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"test uart transmit"}
,"debug" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"use caravel in debug mode and check reading and writing from dff2 RAM"}
,"spi_master_rd" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"using SPI master for reading from external memory"}
,"user_pass_thru_rd" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"use the housekeeping spi in user pass thru mode to read from external mem"}
,"clock_redirect" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"check clock redirect is working as expected"}
,"mgmt_gpio_bidir" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"send random number of blinks through mgmt_gpio and expect to recieve the same number back "}
,"la" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"check logic analyzer input and output enable"}
,"pll" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"Check pll diffrent configuration"}
,"spi_master_temp" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"To be deleted"}
,"bitbang_cpu_all_o" :{"level":0,
"SW":true,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","push_gl","gpio_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"configure all gpios as mgmt output using bitbang and check them"}
,"mem_dff" :{"level":2,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"Memory stress for all space of dff"}
,"bitbang_cpu_all_01" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"shift all the register with 01"}
,"mem_dff2" :{"level":2,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"Memory stress for all space of dff2"}
,"bitbang_cpu_all_10" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"shift all the register with 10"}
,"bitbang_cpu_all_1100" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"shift all the register with 1100"}
,"bitbang_cpu_all_0011" :{"level":0,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","push_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"shift all the register with 0011"}
,"cpu_stress" :{"level":2,
"SW":true,
"RTL":["r_rtl","r_caravan_rtl","nightly","weekly","tape_out"],
"GL":["r_gl","r_caravan_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","r_caravan_sdf","weekly","tape_out"],
"description":"stress the cpu with heavy processing"}
,"bitbang_no_cpu_all_o" :{"level":0,
"SW":false,
"RTL":["r_rtl","setup","gpio_rtl","push","push_gl","nightly","weekly","tape_out"],
"GL":[],
"GL_SDF":[],
"description":"test disable CPU and control the wishbone to configure gpio[4:37] as mgmt output using bitbang and check them"}
,"bitbang_no_cpu_all_i" :{"level":0,
"SW":false,
"RTL":["r_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":[],
"GL_SDF":[],
"description":"test disable CPU and control the wishbone to configure gpio[0:31] as mgmt input using bitbang and check them"}
,"hk_regs_wr_wb" :{"level":0,
"SW":false,
"RTL":["r_rtl","setup","push","push_gl","nightly","weekly","tape_out"],
"GL":[],
"GL_SDF":[],
"description":"write then read (the written value) from random housekeeping registers through the firmware but without using CPU, the SPI and system regs can't be read using firmware so the test only GPIO regs inside housekeeping "}
,"helloWorld" :{"level":3,
"SW":false,
"RTL":[],
"GL":[],
"GL_SDF":[],
"description":"hello world test"}
,"spi_rd_wr_nbyte" :{"level":3,
"SW":false,
"RTL":[],
"GL":[],
"GL_SDF":[],
"description":"try housekeeping spi Write and Read in n-byte mode "}
,"cpu_reset" :{"level":3,
"SW":true,
"RTL":["r_rtl","nightly","weekly","tape_out"],
"GL":["r_gl","nightly","weekly","tape_out"],
"GL_SDF":["r_sdf","weekly","tape_out"],
"description":"test cpu reset register inside the housekeeping "}
}
}

View File

@ -1,62 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = 0x1803 ;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
// bitbang
for(int i =0;i<62;i++){
clock00();
clock00();
clock11();
clock11();
}
reg_debug_1 = 0xFF; // finish configuration
}

View File

@ -1,60 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = 0x1803 ;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
// bitbang
for(int i =0;i<124;i++){
clock00();
clock11();
}
reg_debug_1 = 0xFF; // finish configuration
}

View File

@ -1,60 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = 0x1803 ;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
// bitbang
for(int i =0;i<124;i++){
clock11();
clock00();
}
reg_debug_1 = 0xFF; // finish configuration
}

View File

@ -1,62 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = 0x1803 ;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
// bitbang
for(int i =0;i<62;i++){
clock11();
clock11();
clock00();
clock00();
}
reg_debug_1 = 0xFF; // finish configuration
}

View File

@ -1,91 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = 0x1803;
reg_mprj_io_36 = 0x1803;
reg_mprj_io_35 = 0x1803;
reg_mprj_io_34 = 0x1803;
reg_mprj_io_33 = 0x1803;
reg_mprj_io_32 = 0x1803;
reg_mprj_io_31 = 0x1803;
reg_mprj_io_30 = 0x1803;
reg_mprj_io_29 = 0x1803;
reg_mprj_io_28 = 0x1803;
reg_mprj_io_27 = 0x1803;
reg_mprj_io_26 = 0x1803;
reg_mprj_io_25 = 0x1803;
reg_mprj_io_24 = 0x1803;
reg_mprj_io_23 = 0x1803;
reg_mprj_io_22 = 0x1803;
reg_mprj_io_21 = 0x1803;
reg_mprj_io_20 = 0x1803;
reg_mprj_io_19 = 0x1803;
reg_mprj_io_18 = 0x1803;
reg_mprj_io_17 = 0x1803;
reg_mprj_io_16 = 0x1803;
reg_mprj_io_15 = 0x1803;
reg_mprj_io_14 = 0x1803;
reg_mprj_io_13 = 0x1803;
reg_mprj_io_12 = 0x1803;
reg_mprj_io_11 = 0x1803;
reg_mprj_io_10 = 0x1803;
reg_mprj_io_9 = 0x1803;
reg_mprj_io_8 = 0x1803;
reg_mprj_io_7 = 0x1803;
reg_mprj_io_6 = 0x1803;
reg_mprj_io_5 = 0x1803;
reg_mprj_io_4 = 0x1803;
reg_mprj_io_3 = 0x1803;
reg_mprj_io_2 = 0x1803;
reg_mprj_io_1 = 0x1803;
reg_mprj_io_0 = 0x1803;
reg_mprj_io_0 = 0x1803;
// bitbang
//Configure all as input except reg_mprj_io_3
clock_in_right_i_left_i_standard(0); // 18 and 19
clock_in_right_i_left_i_standard(0); // 17 and 20
clock_in_right_i_left_i_standard(0); // 16 and 21
clock_in_right_i_left_i_standard(0); // 15 and 22
clock_in_right_i_left_i_standard(0); // 14 and 23
clock_in_right_i_left_i_standard(0); // 13 and 24
clock_in_right_i_left_i_standard(0); // 12 and 25
clock_in_right_i_left_i_standard(0); // 11 and 26
clock_in_right_i_left_i_standard(0); // 10 and 27
clock_in_right_i_left_i_standard(0); // 9 and 28
clock_in_right_i_left_i_standard(0); // 8 and 29
clock_in_right_i_left_i_standard(0); // 7 and 30
clock_in_right_i_left_i_standard(0); // 6 and 31
clock_in_right_i_left_i_standard(0); // 5 and 32
clock_in_right_i_left_i_standard(0); // 4 and 33
clock_in_right_i_left_i_standard(0); // 3 and 34
clock_in_right_i_left_i_standard(0); // 2 and 35
clock_in_right_i_left_i_standard(0); // 1 and 36
clock_in_right_i_left_i_standard(0); // 0 and 37
load(); // load
reg_debug_1 = 0XAA; // configuration done wait environment to send 0x8F66FD7B to reg_mprj_datal
while (reg_mprj_datal != 0x8F66FD7B);
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_datal
while (reg_mprj_datal != 0xFFA88C5A);
reg_debug_1 = 0XCC; // configuration done wait environment to send 0xC9536346 to reg_mprj_datal
while (reg_mprj_datal != 0xC9536346);
reg_debug_1 = 0XD1;
while (reg_mprj_datah != 0x3F);
reg_debug_1 = 0XD2;
while (reg_mprj_datah != 0x0);
reg_debug_1 = 0XD3;
while (reg_mprj_datah != 0x15);
reg_debug_1 = 0XD4;
while (reg_mprj_datah != 0x2A);
reg_debug_2 = 0xFF;
}

View File

@ -1,99 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_OUTPUT ;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
// bitbang
// Configure all as output except reg_mprj_io_3
clock_in_right_o_left_o_standard(0); // 18 and 19
clock_in_right_o_left_o_standard(0); // 17 and 20
clock_in_right_o_left_o_standard(0); // 16 and 21
clock_in_right_o_left_o_standard(0); // 15 and 22
clock_in_right_o_left_o_standard(0); // 14 and 23
clock_in_right_o_left_o_standard(0); // 13 and 24
clock_in_right_o_left_o_standard(0); // 12 and 25
clock_in_right_o_left_o_standard(0); // 11 and 26
clock_in_right_o_left_o_standard(0); // 10 and 27
clock_in_right_o_left_o_standard(0); // 9 and 28
clock_in_right_o_left_o_standard(0); // 8 and 29
clock_in_right_o_left_o_standard(0); // 7 and 30
clock_in_right_o_left_o_standard(0); // 6 and 31
clock_in_right_o_left_o_standard(0); // 5 and 32
clock_in_right_o_left_o_standard(0); // 4 and 33
clock_in_right_o_left_o_standard(0); // 3 and 34
clock_in_right_o_left_o_standard(0); // 2 and 35
clock_in_right_o_left_o_standard(0); // 1 and 36
clock_in_right_o_left_o_standard(0); // 0 and 37
load();
reg_debug_1 = 0xFF; // finish configuration
reg_mprj_datal = 0x0;
reg_mprj_datah = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_datah = i;
reg_debug_2 = 37-j;
reg_mprj_datah = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_datah = 0x3f;
reg_mprj_datal = i;
reg_debug_2 = 32-j;
reg_mprj_datah = 0x00;
reg_mprj_datal = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
}

View File

@ -1,325 +0,0 @@
void clock11()
{
reg_mprj_xfer = 0x66; reg_mprj_xfer = 0x76;
}
void clock00()
{
reg_mprj_xfer = 0x06; reg_mprj_xfer = 0x16;
}
// --------------------------------------------------------
void clock10()
{
reg_mprj_xfer = 0x46; reg_mprj_xfer = 0x56;
}
void clock01()
{
reg_mprj_xfer = 0x26; reg_mprj_xfer = 0x36;
}
// --------------------------------------------------------
// Load registers
// --------------------------------------------------------
void load()
{
reg_mprj_xfer = 0x06;
reg_mprj_xfer = 0x0e; reg_mprj_xfer = 0x06; // Apply load
}
// --------------------------------------------------------
// Enable bit-bang mode and clear registers
// --------------------------------------------------------
void clear_registers()
{
reg_mprj_xfer = 0x06; // Enable bit-bang mode
reg_mprj_xfer = 0x04; reg_mprj_xfer = 0x06; // Pulse reset
}
// --------------------------------------------------------
// Clock in an input + output configuration. The value
// passed in "ddhold" is the number of data-dependent hold
// violations up to this point.
// --------------------------------------------------------
/* Clock in data on the left side. Assume standard hold
* violation, so clock in12 times and assume that the
* next data to be clocked will start with "1", enforced
* by the code.
*
* Left side = GPIOs 37 to19
*/
void clock_in_left_short(uint32_t ddhold)
{
uint32_t count;
uint32_t holds = ddhold;
clock10();
clock10();
for (count = 0; count < 9; count++) {
if (holds != 0) {
clock10();
holds--;
}
else
clock00();
}
clock00();
}
/* Clock in data on the right side. Assume standard hold
* violation, so clock in12 times and assume that the
* next data to be clocked will start with "1", enforced
* by the code.
*
* Right side = GPIOs 0 to18
*/
void clock_in_right_short(uint32_t ddhold)
{
uint32_t count;
uint32_t holds = ddhold;
clock01();
clock01();
for (count = 0; count < 9; count++) {
if (holds != 0) {
clock01();
holds--;
}
else
clock00();
}
clock00();
}
/* Clock in data on the left side. Clock the normal13 times,
* which is correct for no hold violation or for a data-
* dependent hold violation (for the latter, ddhold must be
* incremented before calling the subroutine).
*
* Left side = GPIOs 37 to19
*/
void clock_in_left_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock10();
clock10();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock10();
holds--;
}
else
clock00();
}
clock10();
clock00();
clock00();
clock10();
}
void clock_in_right_o_left_o_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock11();
holds--;
}
else
clock00();
}
clock11();
clock00();
clock00();
clock11();
}
void clock_in_right_o_left_i_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock11();
holds--;
}
else
clock00();
}
clock10();
clock00();
clock01();
clock11();
}
void clock_in_right_i_left_o_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock11();
holds--;
}
else
clock00();
}
clock01();
clock00();
clock10();
clock11();
}
void clock_in_right_i_left_i_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock11();
holds--;
}
else
clock00();
}
clock00();
clock00();
clock11();
clock11();
}
/* Clock in data on the right side. Clock the normal13 times,
* which is correct for no hold violation or for a data-
* dependent hold violation (for the latter, ddhold must be
* incremented before calling the subroutine).
*
* Right side = GPIOs 0 to18
*/
void clock_in_right_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock01();
holds--;
}
else
clock00();
}
clock10();
clock00();
clock01();
clock11();
}
void clock_in_right_i_left_io_standard(uint32_t ddhold){
uint32_t count;
uint32_t holds = ddhold;
clock11();
clock11();
for (count = 0; count < 7; count++) {
if (holds != 0) {
clock11();
holds--;
}
else
clock00();
}
clock01();
clock00();
clock11();
clock11();
}
// --------------------------------------------------------
// Clock in data for GPIO 0 and 37 (fixed) and apply load.
// --------------------------------------------------------
void clock_in_end(){
// Right side: GPIO 0 configured disabled
// Left side: GPIO 37 configured as input
clock11();
clock10();
clock00();
clock00();
clock00();
clock00();
clock00();
clock00();
clock00();
clock01();
clock00();
clock11();
clock11();
load();
}
// --------------------------------------------------------
// Same as above, except that GPIO is configured as an
// output for a quick sanity check.
// --------------------------------------------------------
void clock_in_end_output()
{
// Right side: GPIO 0 configured disabled
// Left side: GPIO 37 configured as output
clock11();
clock10();
clock00();
clock00();
clock00();
clock00();
clock00();
clock00();
clock00();
clock01();
clock00();
clock01();
clock11();
load();
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
}

View File

@ -1,355 +0,0 @@
from interfaces.defsParser import Regs
reg = Regs()
"""
reg_mprj_xfer contain
bit 0 : busy
bit 1 : bitbang enable
bit 2 : bitbang reset active low
bit 3 : bitbang load registers
bit 4 : bitbang clock
bit 5 : serial data 1
bit 6 : serial data 2
"""
"""shift the 2 registers with 2 ones"""
async def clock11(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x66) # 0110_0110
await cpu.drive_data2address(reg_mprj_xfer_addr,0x76) # 0111_0110
"""shift the 2 registers with 2 zeros"""
async def clock00(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x06) # 0000_0110
await cpu.drive_data2address(reg_mprj_xfer_addr,0x16) # 0001_0110
"""shift the 2 registers with 1 in the left side and zero in right side"""
async def clock01(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x26) # 0010_0110
await cpu.drive_data2address(reg_mprj_xfer_addr,0x36) # 0011_0110
"""shift the 2 registers with 1 in the left side and zero in right side"""
async def clock10(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x46) # 0100_0110
await cpu.drive_data2address(reg_mprj_xfer_addr,0x56) # 0101_0110
"""enable the serial loader bit to load registers"""
async def load(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x06) # enable bit bang
await cpu.drive_data2address(reg_mprj_xfer_addr,0x0e) # enable loader
await cpu.drive_data2address(reg_mprj_xfer_addr,0x06) # enable bit bang
"""Enable bit-bang mode and clear registers"""
async def clear_registers(cpu):
reg_mprj_xfer_addr = reg.get_addr('reg_mprj_xfer')
await cpu.drive_data2address(reg_mprj_xfer_addr,0x06) # enable bit bang
await cpu.drive_data2address(reg_mprj_xfer_addr,0x04) # reset
await cpu.drive_data2address(reg_mprj_xfer_addr,0x06) # enable bit bang
"""
--------------------------------------------------------
Clock in an input + output configuration. The value
passed in "ddhold" is the number of data-dependent hold
violations up to this point.
--------------------------------------------------------
* Clock in data on the left side. Assume standard hold
* violation, so clock in 12 times and assume that the
* next data to be clocked will start with "1", enforced
* by the code.
*
* Left side = GPIOs 37 to 19
"""
async def clock_in_left_short(cpu,ddhold):
await clock10(cpu)
await clock10(cpu)
for i in range(9):
if ddhold != 0:
await clock10(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock00(cpu)
async def clock_in_right_short(cpu,ddhold):
await clock01(cpu)
await clock01(cpu)
for i in range(9):
if ddhold != 0:
await clock01(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock00(cpu)
async def clock_in_left_standard(cpu,ddhold):
await clock10(cpu)
await clock10(cpu)
for i in range(7):
if ddhold != 0:
await clock10(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock10(cpu)
await clock00(cpu)
await clock00(cpu)
await clock10(cpu)
"""right output left input"""
async def clock_in_right_o_left_i_standard(cpu,ddhold):
await clock11(cpu)
await clock11(cpu)
for i in range(7):
if ddhold != 0:
await clock01(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock10(cpu)
await clock00(cpu)
await clock01(cpu)
await clock11(cpu)
"""right input left output"""
async def clock_in_right_i_left_o_standard(cpu,ddhold):
await clock11(cpu)
await clock11(cpu)
for i in range(7):
if ddhold != 0:
await clock10(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock01(cpu)
await clock00(cpu)
await clock10(cpu)
await clock11(cpu)
"""right input left output"""
async def clock_in_right_i_left_i_standard(cpu,ddhold):
await clock11(cpu)
await clock11(cpu)
for i in range(7):
if ddhold != 0:
await clock01(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock11(cpu)
await clock11(cpu)
"""right output left output"""
async def clock_in_right_o_left_o_standard(cpu,ddhold):
await clock11(cpu)
await clock11(cpu)
for i in range(7):
if ddhold != 0:
await clock01(cpu)
ddhold -=1
else:
await clock00(cpu)
await clock11(cpu)
await clock00(cpu)
await clock00(cpu)
await clock11(cpu)
async def clock_in_end_output(cpu):
# Right side: GPIO 0 configured disabled
# /Left side: GPIO 37 configured as output
await clock11(cpu)
await clock11(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock00(cpu)
await clock01(cpu)
await clock11(cpu)
await load(cpu)
reg_mprj_io_37_addr = reg.get_addr('reg_mprj_io_37')
await cpu.drive_data2address(reg_mprj_io_37_addr,0x1809)
async def clock11_spi(caravelEnv):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x66) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x76) # 11
await caravelEnv.disable_csb()
async def clock00_spi(caravelEnv):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x06) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x16) # 00
await caravelEnv.disable_csb()
async def clock01_spi(caravelEnv):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x26) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x36) # 01
await caravelEnv.disable_csb()
async def clock10_spi(caravelEnv):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x46) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x56) # 10
await caravelEnv.disable_csb()
async def load_spi(caravelEnv):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x0e) # load enable
await caravelEnv.disable_csb()
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(0x13) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(0x16) # 00
await caravelEnv.disable_csb()
"""right output left input"""
async def clock_in_right_o_left_i_standard_spi(caravelEnv,ddhold):
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
for i in range(7):
if ddhold != 0:
await clock01_spi(caravelEnv)
ddhold -=1
else:
await clock00_spi(caravelEnv)
await clock10_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock01_spi(caravelEnv)
await clock11_spi(caravelEnv)
"""right input left output"""
async def clock_in_right_i_left_o_standard_spi(caravelEnv,ddhold):
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
for i in range(7):
if ddhold != 0:
await clock10_spi(caravelEnv)
ddhold -=1
else:
await clock00_spi(caravelEnv)
await clock01_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock10_spi(caravelEnv)
await clock11_spi(caravelEnv)
"""right input left output"""
async def clock_in_right_i_left_i_standard_spi(caravelEnv,ddhold):
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
for i in range(7):
if ddhold != 0:
await clock01_spi(caravelEnv)
ddhold -=1
else:
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
"""right output left output"""
async def clock_in_right_o_left_o_standard_spi(caravelEnv,ddhold):
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
for i in range(7):
if ddhold != 0:
await clock01_spi(caravelEnv)
ddhold -=1
else:
await clock00_spi(caravelEnv)
await clock11_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock11_spi(caravelEnv)
async def clock_in_end_output_spi(caravelEnv):
# Right side: GPIO 0 configured disabled
# /Left side: GPIO 37 configured as output
await clock11_spi(caravelEnv)
await clock11_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock00_spi(caravelEnv)
await clock01_spi(caravelEnv)
await clock11_spi(caravelEnv)
await load_spi(caravelEnv)

View File

@ -1,10 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
return;
}

View File

@ -1,10 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
return;
}

View File

@ -1,9 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
return;
}

View File

@ -1,72 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
int i,j;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_debug_1 = 0xFF; // finish configuration
while (reg_debug_2 != 0xDD);
reg_debug_1 = 0XAA; // configuration done wait environment to send 0x8F66FD7B to reg_mprj_datal
while (reg_mprj_datal != 0x8F66FD7B);
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_datal
while (reg_mprj_datal != 0xFFA88C5A);
reg_debug_1 = 0XCC; // configuration done wait environment to send 0xC9536346 to reg_mprj_datal
while (reg_mprj_datal != 0xC9536346);
reg_debug_1 = 0XD1;
while (reg_mprj_datah != 0x3F);
reg_debug_1 = 0XD2;
while (reg_mprj_datah != 0x0);
reg_debug_1 = 0XD3;
while (reg_mprj_datah != 0x15);
reg_debug_1 = 0XD4;
while (reg_mprj_datah != 0x2A);
reg_debug_2 = 0xFF;
}

View File

@ -1,79 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
int i,j;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 0;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
// reg_mprj_io_4 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
// reg_mprj_io_3 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
// reg_mprj_io_2 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
// reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
// reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_debug_1 = 0xFF; // finish configuration
while (reg_debug_2 != 0xFF); // finish bit bang
reg_hkspi_disable = 1;
reg_mprj_datal = 0x0;
reg_mprj_datah = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_datah = i;
reg_debug_2 = 37-j;
reg_mprj_datah = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_datah = 0x3f;
reg_mprj_datal = i;
reg_debug_2 = 32-j;
reg_mprj_datah = 0x00;
reg_mprj_datal = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
}

View File

@ -1,259 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
reg = Regs()
@cocotb.test()
@repot_test
async def bitbang_no_cpu_all_o(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=9373)
cpu = RiskV(dut)
cpu.cpu_force_reset()
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_37'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_36'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_35'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_34'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_33'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_32'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_31'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_30'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_29'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_28'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_27'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_26'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_25'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_24'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_23'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_22'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_21'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_20'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_19'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_18'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_17'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_16'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_15'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_14'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_13'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_12'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_11'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_10'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_9'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_8'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_7'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_6'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_5'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_4'),GPIO_MODE.GPIO_MODE_MGMT_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_3'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_2'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_1'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_0'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_0'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
#Configure all as output except reg_mprj_io_3
await clear_registers(cpu)
await clock_in_right_o_left_o_standard(cpu,0) # 18 and 19
await clock_in_right_o_left_o_standard(cpu,0) # 17 and 20
await clock_in_right_o_left_o_standard(cpu,0) # 16 and 21
await clock_in_right_o_left_o_standard(cpu,0) # 15 and 22
await clock_in_right_o_left_o_standard(cpu,0) # 14 and 23
await clock_in_right_o_left_o_standard(cpu,0) # 13 and 24
await clock_in_right_o_left_o_standard(cpu,0) # 12 and 25
await clock_in_right_o_left_o_standard(cpu,0) # 11 and 26
await clock_in_right_o_left_o_standard(cpu,0) # 10 and 27
await clock_in_right_o_left_o_standard(cpu,0) # 9 and 28
await clock_in_right_o_left_o_standard(cpu,0) # 8 and 29
await clock_in_right_o_left_o_standard(cpu,0) # 7 and 30
await clock_in_right_o_left_o_standard(cpu,0) # 6 and 31
await clock_in_right_o_left_o_standard(cpu,0) # 5 and 32
await clock_in_right_o_left_o_standard(cpu,0) # 4 and 33
await clock_in_right_o_left_i_standard(cpu,0) # 3 and 34
await clock_in_right_o_left_i_standard(cpu,0) # 2 and 35
await clock_in_right_o_left_i_standard(cpu,0) # 1 and 36
await clock_in_end_output(cpu) # 0 and 37 and load
await caravelEnv.release_csb()
await cpu.drive_data2address(reg.get_addr('reg_mprj_datal'),0x0)
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x0)
i= 0x20
for j in range(5):
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),i)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,4))} int {caravelEnv.monitor_gpio((37,4)).integer} i = {i}')
if caravelEnv.monitor_gpio((37,4)).integer != i << 28:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,4))} instead of {bin(i << 28)}')
# for k in range(250):
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0)
if caravelEnv.monitor_gpio((37,4)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,4))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
await ClockCycles(caravelEnv.clk, 1)
i= 0x80000000
for j in range(32):
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x3f)
await cpu.drive_data2address(reg.get_addr('reg_mprj_datal'),i)
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)}')
if caravelEnv.monitor_gpio((31,4)).integer != i>>4 :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,4))} instead of {i>>4}')
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,4))} type {int(caravelEnv.monitor_gpio((37,4)))} i = {i}')
await ClockCycles(caravelEnv.clk, 1)
# await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x0)
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x0)
await cpu.drive_data2address(reg.get_addr('reg_mprj_datal'),0x0)
await ClockCycles(caravelEnv.clk, 1)
if caravelEnv.monitor_gpio((37,4)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,4))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await ClockCycles(caravelEnv.clk, 1000)
@cocotb.test()
@repot_test
async def bitbang_no_cpu_all_i(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=7351)
cpu = RiskV(dut)
cpu.cpu_force_reset()
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_37'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_36'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_35'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_34'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_33'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_32'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_31'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_30'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_29'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_28'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_27'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_26'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_25'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_24'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_23'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_22'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_21'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_20'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_19'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_18'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_17'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_16'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_15'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_14'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_13'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_12'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_11'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_10'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_9'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_8'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_7'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_6'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_5'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_4'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_3'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_2'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_1'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_0'),GPIO_MODE.GPIO_MODE_MGMT_STD_INPUT.value)
#Configure all as input except reg_mprj_io_3
await clear_registers(cpu)
await clock_in_right_i_left_i_standard(cpu,0) # 18 and 19
await clock_in_right_i_left_i_standard(cpu,0) # 17 and 20
await clock_in_right_i_left_i_standard(cpu,0) # 16 and 21
await clock_in_right_i_left_i_standard(cpu,0) # 15 and 22
await clock_in_right_i_left_i_standard(cpu,0) # 14 and 23
await clock_in_right_i_left_i_standard(cpu,0) # 13 and 24
await clock_in_right_i_left_i_standard(cpu,0) # 12 and 25
await clock_in_right_i_left_i_standard(cpu,0) # 11 and 26
await clock_in_right_i_left_i_standard(cpu,0) # 10 and 27
await clock_in_right_i_left_i_standard(cpu,0) # 9 and 28
await clock_in_right_i_left_i_standard(cpu,0) # 8 and 29
await clock_in_right_i_left_i_standard(cpu,0) # 7 and 30
await clock_in_right_i_left_i_standard(cpu,0) # 6 and 31
await clock_in_right_i_left_i_standard(cpu,0) # 5 and 32
await clock_in_right_i_left_i_standard(cpu,0) # 4 and 33
await clock_in_right_i_left_i_standard(cpu,0) # 3 and 34
await clock_in_right_i_left_i_standard(cpu,0) # 2 and 35
await clock_in_right_i_left_i_standard(cpu,0) # 1 and 36
await clock_in_right_i_left_i_standard(cpu,0) # 0 and 37
await load(cpu) # load
caravelEnv.drive_gpio_in((31,0),0x8F66FD7B)
await ClockCycles(caravelEnv.clk, 100)
reg_mprj_datal = await cpu.read_address(reg.get_addr('reg_mprj_datal'))
# value_masked = reg_mprj_datal & mask_input
if reg_mprj_datal == 0x8F66FD7B:
cocotb.log.info(f'[TEST] Passed with value 0x8F66FD7B')
else:
cocotb.log.error(f'[TEST] fail with value mprj = {bin(reg_mprj_datal)} instead of {bin(0x8F66FD7B)}')
await ClockCycles(caravelEnv.clk, 100)
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x1B)
x = caravelEnv.monitor_gpio((37,32))
print(f"xxxxxxxx {x}")
await ClockCycles(caravelEnv.clk, 100)
caravelEnv.drive_gpio_in((31,0),0xFFA88C5A)
await ClockCycles(caravelEnv.clk, 100)
reg_mprj_datal = await cpu.read_address(reg.get_addr('reg_mprj_datal'))
# value_masked = reg_mprj_datal & mask_input
if reg_mprj_datal == 0xFFA88C5A:
cocotb.log.info(f'[TEST] Passed with value 0xFFA88C5A')
else:
cocotb.log.error(f'[TEST] fail with value mprj = {bin(reg_mprj_datal)} instead of {bin(0xFFA88C5A)}')
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x2B)
await ClockCycles(caravelEnv.clk, 100)
caravelEnv.drive_gpio_in((31,0),0xC9536346)
await ClockCycles(caravelEnv.clk, 100)
reg_mprj_datal = await cpu.read_address(reg.get_addr('reg_mprj_datal'))
# value_masked = reg_mprj_datal & mask_input
if reg_mprj_datal == 0xC9536346:
cocotb.log.info(f'[TEST] Passed with value 0xC9536346')
else:
cocotb.log.error(f'[TEST] fail with value mprj = {bin(reg_mprj_datal)} instead of {bin(0xC9536346)}')
await cpu.drive_data2address(reg.get_addr('reg_mprj_datah'),0x3B)
await ClockCycles(caravelEnv.clk, 100)
"""Testbench of GPIO configuration through bit-bang method using the housekeeping SPI."""
@cocotb.test()
@repot_test
async def io_ports(dut):
caravelEnv,clock = await test_configure(dut)
cpu = RiskV(dut)
cpu.cpu_force_reset()
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_0'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_1'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_2'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_3'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_4'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_5'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_6'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
await cpu.drive_data2address(reg.get_addr('reg_mprj_io_7'),GPIO_MODE.GPIO_MODE_USER_STD_OUTPUT.value)
# Apply configuration
await cpu.drive_data2address(reg.get_addr('reg_mprj_xfer'),1)
while True:
if await cpu.read_address(reg.get_addr('reg_mprj_xfer')) != 1 :
break

View File

@ -1,415 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from interfaces.common import Macros
reg = Regs()
@cocotb.test()
@repot_test
async def bitbang_cpu_all_o(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1842534)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xFF)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring using bitbang")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i<<32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i<<32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await ClockCycles(caravelEnv.clk, 10)
@cocotb.test()
@repot_test
async def bitbang_cpu_all_10(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1452270)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xFF)
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]","gpio_control_in_1[6]","gpio_control_in_1[7]","gpio_control_in_1[8]","gpio_control_in_1[9]","gpio_control_in_1[10]")
if Macros['CARAVAN']:
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]")
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_in_2[10]","gpio_control_in_2[11]","gpio_control_in_2[12]","gpio_control_in_2[13]","gpio_control_in_2[14]","gpio_control_in_2[15]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
if Macros['CARAVAN']:
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
type = True # type of shifting 01 or 10
for gpio in gpios_l:
if not Macros['GL']:
shift(uut._id(gpio,False),type)
else:
shift(uut._id(f'\\{gpio} ',False),type)
type = not type
type = True # type of shifting 01 or 10
for gpio in reversed(gpios_h):
if not Macros['GL']:
shift(uut._id(gpio,False),type)
else:
shift(uut._id(f'\\{gpio} ',False),type)
type = not type
def shift(gpio,shift_type):
if shift_type:
bits = "0101010101010"
else:
bits = "1010101010101"
fail = False
if not Macros['GL']:
cocotb.log.info(f"[TEST] gpio {gpio} shift {gpio._id(f'shift_register',False).value} expected {bits}")
for i in range(13):
if not Macros['GL']:
shift_register = gpio._id(f"shift_register",False).value.binstr[i]
else:
shift_register = gpio._id(f"\\shift_register[{i}] ",False).value.binstr
if shift_register != bits[i]:
fail = True
cocotb.log.error(f"[TEST] wrong shift register {i} in {gpio}")
if not fail:
cocotb.log.info(f"[TEST] gpio {gpio} passed")
@cocotb.test()
@repot_test
async def bitbang_cpu_all_01(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1452269)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xFF)
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]","gpio_control_in_1[6]","gpio_control_in_1[7]","gpio_control_in_1[8]","gpio_control_in_1[9]","gpio_control_in_1[10]")
if Macros['CARAVAN']:
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]")
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_in_2[10]","gpio_control_in_2[11]","gpio_control_in_2[12]","gpio_control_in_2[13]","gpio_control_in_2[14]","gpio_control_in_2[15]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
if Macros['CARAVAN']:
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
type = False # type of shifting 01 or 10
for gpio in gpios_l:
if not Macros['GL']:
shift(uut._id(gpio,False),type)
else:
shift(uut._id(f'\\{gpio} ',False),type)
type = not type
type = False # type of shifting 01 or 10
for gpio in reversed(gpios_h):
if not Macros['GL']:
shift(uut._id(gpio,False),type)
else:
shift(uut._id(f'\\{gpio} ',False),type)
type = not type
@cocotb.test()
@repot_test
async def bitbang_cpu_all_0011(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1402860)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xFF)
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]","gpio_control_in_1[6]","gpio_control_in_1[7]","gpio_control_in_1[8]","gpio_control_in_1[9]","gpio_control_in_1[10]")
if Macros['CARAVAN']:
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]")
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_in_2[10]","gpio_control_in_2[11]","gpio_control_in_2[12]","gpio_control_in_2[13]","gpio_control_in_2[14]","gpio_control_in_2[15]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
if Macros['CARAVAN']:
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
type = 2 # type of shifting 01 or 10
for gpio in gpios_l:
if not Macros['GL']:
shift_2(uut._id(gpio,False),type)
else:
shift_2(uut._id(f'\\{gpio} ',False),type)
type = (type + 1) %4
type = 2 # type of shifting 01 or 10
for gpio in reversed(gpios_h):
if not Macros['GL']:
shift_2(uut._id(gpio,False),type)
else:
shift_2(uut._id(f'\\{gpio} ',False),type)
type = (type + 1) %4
@cocotb.test()
@repot_test
async def bitbang_cpu_all_1100(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1402426)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xFF)
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]","gpio_control_in_1[6]","gpio_control_in_1[7]","gpio_control_in_1[8]","gpio_control_in_1[9]","gpio_control_in_1[10]")
if Macros['CARAVAN']:
gpios_l = ("gpio_control_bidir_1[0]","gpio_control_bidir_1[1]","gpio_control_in_1a[0]","gpio_control_in_1a[1]","gpio_control_in_1a[2]","gpio_control_in_1a[3]","gpio_control_in_1a[4]","gpio_control_in_1a[5]","gpio_control_in_1[0]","gpio_control_in_1[1]","gpio_control_in_1[2]","gpio_control_in_1[3]","gpio_control_in_1[4]","gpio_control_in_1[5]")
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_in_2[10]","gpio_control_in_2[11]","gpio_control_in_2[12]","gpio_control_in_2[13]","gpio_control_in_2[14]","gpio_control_in_2[15]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
if Macros['CARAVAN']:
gpios_h= ("gpio_control_in_2[0]","gpio_control_in_2[1]","gpio_control_in_2[2]","gpio_control_in_2[3]","gpio_control_in_2[4]","gpio_control_in_2[5]","gpio_control_in_2[6]","gpio_control_in_2[7]","gpio_control_in_2[8]","gpio_control_in_2[9]","gpio_control_bidir_2[0]","gpio_control_bidir_2[1]","gpio_control_bidir_2[2]")
type = 0 # type of shifting 01 or 10
for gpio in gpios_l:
if not Macros['GL']:
shift_2(uut._id(gpio,False),type)
else:
shift_2(uut._id(f'\\{gpio} ',False),type)
type = (type + 1) %4
type = 0 # type of shifting 01 or 10
for gpio in reversed(gpios_h):
if not Macros['GL']:
shift_2(uut._id(gpio,False),type)
else:
shift_2(uut._id(f'\\{gpio} ',False),type)
type = (type + 1) %4
def shift_2(gpio,shift_type):
if shift_type == 0:
bits = "0011001100110"
elif shift_type == 1:
bits = "0110011001100"
elif shift_type == 2:
bits = "1100110011001"
elif shift_type == 3:
bits = "1001100110011"
fail = False
if not Macros['GL']:
cocotb.log.info(f"[TEST] gpio {gpio} shift {gpio._id(f'shift_register',False).value.binstr[::-1]} expected {bits}")
else :
shift_reg =''
for i in range(13):
shift_reg += gpio._id(f"\\shift_register[{i}] ",False).value.binstr
cocotb.log.info(f"[TEST] gpio {gpio} shift {shift_reg} expected {bits}")
for i in range(13):
if not Macros['GL']:
shift_register = gpio._id(f"shift_register",False).value.binstr[12-i]
else:
shift_register = gpio._id(f"\\shift_register[{i}] ",False).value.binstr
if shift_register != bits[i]:
fail = True
cocotb.log.error(f"[TEST] wrong shift register {i} in {gpio}")
if not fail:
cocotb.log.info(f"[TEST] gpio {gpio} passed")
@cocotb.test()
@repot_test
async def bitbang_cpu_all_i(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1641382)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0xFFA88C5A
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0xC9536346
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0x3F
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x0
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x15
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x2A
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg2(cpu,caravelEnv,0xFF)
cocotb.log.info(f"[TEST] finish")
"""Testbench of GPIO configuration through bit-bang method using the housekeeping SPI configure all gpio as output."""
@cocotb.test()
@repot_test
async def bitbang_spi_o(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=294252)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xFF) # wait for housekeeping registers configured
#Configure all as output except reg_mprj_io_3
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 18 and 19
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 17 and 20
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 16 and 21
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 15 and 22
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 14 and 23
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 13 and 24
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 12 and 25
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 11 and 26
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 10 and 27
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 9 and 28
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 8 and 29
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 7 and 30
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 6 and 31
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 5 and 32
await clock_in_right_o_left_i_standard_spi(caravelEnv,0) # 4 and 33
await clock_in_right_o_left_i_standard_spi(caravelEnv,0) # 3 and 34
await clock_in_right_o_left_i_standard_spi(caravelEnv,0) # 2 and 35
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 1 and 36
await clock_in_right_o_left_o_standard_spi(caravelEnv,0) # 0 and 37
await load_spi(caravelEnv) # load
cpu.write_debug_reg2_backdoor(0xFF)
cocotb.log.info("[TEST] finish configuring using bitbang")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,5))} j = {j}')
if caravelEnv.monitor_gpio((37,5)).integer != i << 27:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,5))} instead of {bin(i << 28)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,5)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,5))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,5))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,5)).integer != i>>5 :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,4))} instead of {bin(i>>4)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,5)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,5))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await ClockCycles(caravelEnv.clk, 10)
"""Testbench of GPIO configuration through bit-bang method using the housekeeping SPI configure all gpio as input."""
@cocotb.test()
@repot_test
async def bitbang_spi_i(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=55417)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xFF) # wait for housekeeping registers configured
#Configure all as output except reg_mprj_io_3
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 18 and 19
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 17 and 20
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 16 and 21
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 15 and 22
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 14 and 23
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 13 and 24
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 12 and 25
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 11 and 26
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 10 and 27
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 9 and 28
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 8 and 29
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 7 and 30
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 6 and 31
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 5 and 32
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 4 and 33
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 3 and 34
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 2 and 35
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 1 and 36
await clock_in_right_i_left_i_standard_spi(caravelEnv,0) # 0 and 37
await load_spi(caravelEnv) # load
cpu.write_debug_reg2_backdoor(0xDD)
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0xFFA88C5A
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0xC9536346
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[31:0]")
data_in = 0x3F
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x0
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x15
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully to gpio[37:32]")
data_in = 0x2A
cocotb.log.info(f"[TEST] send {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg2(cpu,caravelEnv,0xFF)
cocotb.log.info(f"[TEST] finish")

View File

@ -1,32 +0,0 @@
# from turtle import st
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from cocotb.result import SimTimeoutError
import cocotb
import time
"""class to handle timeout inside the tests. after the provided number of cycles (cycle_num) are exceeded test would fail
precision would determine when to log timeout warning for example if cycle_num=1000 and percision = 10% so after each 1000*10% = 100 cycle log would be printed
"""
class Timeout:
def __init__(self,clk,cycle_num,precision=0.20):
self.clk = clk
self.cycle_num = cycle_num
self.cycle_precision = precision * cycle_num
cocotb.scheduler.add(self._timeout_check())
async def _timeout_check(self):
number_of_cycles = 0
for i in range(0,self.cycle_num):
await ClockCycles(self.clk,1)
number_of_cycles +=1
if number_of_cycles %self.cycle_precision ==0:
cocotb.log.warning(f"simulation are only {self.cycle_num-number_of_cycles} cycles away from TIMEOUT ")
raise SimTimeoutError(f"simulation exceeds the max number of cycles {self.cycle_num}")
pass

View File

@ -1,95 +0,0 @@
import random
import cocotb
from cocotb.clock import Clock
import cocotb.log
import interfaces.caravel as caravel
from interfaces.logic_analyzer import LA
from wb_models.housekeepingWB.housekeepingWB import HK_whiteBox
import interfaces.common as common
import logging
from interfaces.cpu import RiskV
from cocotb.log import SimTimeContextFilter
from cocotb.log import SimLogFormatter
from tests.common_functions.Timeout import Timeout
import os
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
"""configure the test log file location and log verbosity
configure the test clock
configure the test timeout
configure whitbox models
start up the test connecting power vdd to the design then reset and disable the CSB bit
return the caravel environmnet with clock and start up
"""
async def test_configure(dut,timeout_cycles=1000000,clk=25,timeout_precision=0.2,num_error=3):
caravelEnv = caravel.Caravel_env(dut)
Timeout(caravelEnv.clk,timeout_cycles,timeout_precision)
if os.getenv('ERRORMAX') != 'None':
num_error = int(os.getenv('ERRORMAX'))
cocotb.scheduler.add(max_num_error(num_error,caravelEnv.clk))
clock = Clock(caravelEnv.clk, clk, units="ns") # Create a 10ns period clock on port clk
cocotb.start_soon(clock.start()) # Start the clock
await caravelEnv.start_up()
await ClockCycles(caravelEnv.clk, 10)
# HK_whiteBox(dut)
return caravelEnv,clock
class CallCounted:
"""Decorator to determine number of calls for a method"""
def __init__(self,method):
self.method=method
self.counter=0
def __call__(self,*args,**kwargs):
self.counter+=1
return self.method(*args,**kwargs)
def repot_test(func):
async def wrapper_func(*args, **kwargs):
## configure logging
COCOTB_ANSI_OUTPUT=0
TestName = func.__name__
cocotb.log.setLevel(logging.INFO)
cocotb.log.error = CallCounted(cocotb.log.error)
cocotb.log.critical = CallCounted(cocotb.log.critical)
cocotb.log.warning = CallCounted(cocotb.log.warning)
handler = logging.FileHandler(f"sim/{os.getenv('RUNTAG')}/{os.getenv('TESTFULLNAME')}/{TestName}.log",mode='w')
handler.addFilter(SimTimeContextFilter())
handler.setFormatter(SimLogFormatter())
cocotb.log.addHandler(handler)
## call test
await func(*args, **kwargs)
## report after finish simulation
msg = f'with ({cocotb.log.critical.counter})criticals ({cocotb.log.error.counter})errors ({cocotb.log.warning.counter})warnings '
if cocotb.log.error.counter > 0 or cocotb.log.critical.counter >0:
raise cocotb.result.TestComplete(f'Test failed {msg}')
else:
raise cocotb.result.TestComplete(f'Test passed {msg}')
return retval
return wrapper_func
async def max_num_error(num_error,clk):
while True:
await ClockCycles(clk,1)
if cocotb.log.error.counter + cocotb.log.critical.counter > num_error:
msg = f'Test failed with max number of errors {num_error} ({cocotb.log.critical.counter})criticals ({cocotb.log.error.counter})errors ({cocotb.log.warning.counter})warnings '
raise cocotb.result.TestFailure(msg)
async def wait_reg1(cpu,caravelEnv,data):
while (True):
if cpu.read_debug_reg1() == data:
return
await ClockCycles(caravelEnv.clk,10)
async def wait_reg2(cpu,caravelEnv,data):
while (True):
if cpu.read_debug_reg2() == data:
return
await ClockCycles(caravelEnv.clk,10)

View File

@ -1,18 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_1 = 0x1;
reg_debug_1 = 0x2;
reg_debug_1 = 0x3;
reg_debug_1 = 0x4;
reg_debug_1 = 0x5;
while(reg_debug_2 == 0x0);
reg_hkspi_reset = 1;
}

View File

@ -1,67 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
reg = Regs()
@cocotb.test()
@repot_test
async def cpu_reset(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=34823)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start cpu_reset test")
# wait for CPU to write 5 at debug_reg1
while True:
if cpu.read_debug_reg1() == 5:
cocotb.log.info("[TEST] debug reg 1 = 5" )
break
await ClockCycles(caravelEnv.clk,1)
# put the cpu under reset using spi
cocotb.log.info("[TEST] asserting cpu reset register using SPI")
await write_reg_spi(caravelEnv,0xb,1)
await ClockCycles(caravelEnv.clk,1000)
if cpu.read_debug_reg1() == 0:
cocotb.log.info("[TEST] asserting cpu reset register using SPI successfully rest the cpu")
else:
cocotb.log.error("[TEST] asserting cpu reset register using SPI successfully doesn't rest the cpu")
cocotb.log.info("[TEST] deasserting cpu reset register using SPI")
await write_reg_spi(caravelEnv,0xb,0)
watchdog = 12000
while True:
if cpu.read_debug_reg1() == 5:
cocotb.log.info("[TEST] deasserting cpu reset register using SPI wakes the cpu up" )
break
watchdog -=1
if watchdog <0:
cocotb.log.error("[TEST] deasserting cpu reset register using SPI doesn't wake the cpu up" )
break
await ClockCycles(caravelEnv.clk,1)
cocotb.log.info("[TEST] asserting cpu reset register using firmware")
cpu.write_debug_reg2_backdoor(0xAA)
await ClockCycles(caravelEnv.clk,10000)
watchdog = 8000
while True:
if cpu.read_debug_reg1() == 0:
cocotb.log.info("[TEST] asserting cpu reset register using firmware successfully rest the cpu" )
break
watchdog -=1
if watchdog <0:
cocotb.log.error("[TEST] asserting cpu reset register using firmware successfully doesn't rest the cpu" )
break
await ClockCycles(caravelEnv.clk,100)

View File

@ -1,156 +0,0 @@
#include <defs.h>
int A[]={1, 40, 2, 5, 22, 11, 90, 200, 10, 20, 25};
// int factorial(int n) {
// int fac=1;
// for(int i=1; i<=n;++i){
// fac = fac * i;
// }
// return fac;
// }
int fibbonacci(int n) {
if(n == 0){
return 0;
} else if(n == 1) {
return 1;
} else {
return (fibbonacci(n-1) + fibbonacci(n-2));
}
}
void recursiveInsertionSort(int arr[], int n){
if (n <= 1)
return;
recursiveInsertionSort( arr, n-1 );
int nth = arr[n-1];
int j = n-2;
while (j >= 0 && arr[j] > nth){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = nth;
}
void quick_sort(int number[],int first,int last){
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(number[i]<=number[pivot]&&i<last)
i++;
while(number[j]>number[pivot])
j--;
if(i<j){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quick_sort(number,first,j-1);
quick_sort(number,j+1,last);
}
}
int f4(int a, int b, int c, int d){
return a + b + c + d;
}
int f5(int a, int b, int c, int d, int e){
return e + f4(a, b, c, d);
}
int f6(int a, int b, int c, int d, int e, int f){
return f + f5(a, b, c, d, e);
}
int f7(int a, int b, int c, int d, int e, int f, int g){
return g + f6(a, b, c, d, e, f);
}
int f8(int a, int b, int c, int d, int e, int f, int g, int h){
return h + f7(a, b, c, d, e, f, g);
}
/*
Stress the cpu with heavy processing
*/
void main()
{
int n;
int B[10];
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// start test
// reg_mprj_datal = 0xAAAA0000;
// n =factorial(12);
// if(n != 479001600)
// reg_mprj_datal = 0xFFFF0000; //fail
// reg_mprj_datal = 0x11110000; //phase 1 pass
n = fibbonacci(10);
if(n != 55)
reg_debug_1 = 0x1E; // fail pahse 1
else
reg_debug_1 = 0x1B; // pass pahse 1
int sumA = 0;
for(int i=0; i<10; i++){
B[i] = A[i];
sumA += A[i];
}
if(sumA != 401)
reg_debug_1 = 0x2E; // fail pahse 2
else
reg_debug_1 = 0x2B; // pass pahse 2
recursiveInsertionSort(B, 10);
int sumB = 0;
for(int i=0; i<10; i++){
sumB += B[i];
}
if(sumA != sumB)
reg_debug_1 = 0x3E;// fail pahse 3
else
reg_debug_1 = 0x3B; // pass pahse 3
for(int i=0; i<10; i++){
B[i] = A[i];
sumA += A[i];
}
quick_sort(B, 0, 9);
for(int i=0; i<10; i++){
sumB += B[i];
}
if(sumA != sumB)
reg_debug_1 = 0x4E;// fail pahse 4
else
reg_debug_1 = 0x4B; // pass pahse 4
int sum = f8(10, 20, 30, 40, 50, 60, 70, 80);
if(sum != (10+20+30+40+50+60+70+80))
reg_debug_1 = 0x5E; // fail pahse 5
else
reg_debug_1 = 0x5B; // pass pahse 5
// test finish
reg_debug_2 = 0xFF;
}

View File

@ -1,43 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
reg = Regs()
"""stress the cpu with heavy processing"""
@cocotb.test()
@repot_test
async def cpu_stress(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1377432)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start CPU stress test")
pass_list = (0x1B,0x2B,0x3B,0x4B,0x5B)
fail_list = (0x1E,0x2E,0x3E,0x4E,0x5E)
phases_fails = 5
phases_passes = 0
reg1 =0 # buffer
while True:
if cpu.read_debug_reg2() == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
phases_passes +=1
phases_fails -=1
cocotb.log.info(f"[TEST] pass phase {hex(reg1)[2]}")
elif reg1 in fail_list: # pass phase
cocotb.log.error(f"[TEST] failed phase {hex(reg1)[2]}")
await ClockCycles(caravelEnv.clk,1)
if phases_fails > 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")

View File

@ -1,50 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <stub.c>
// --------------------------------------------------------
void main()
{
int j;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
// Now, apply the configuration
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
(*(volatile uint32_t*) CSR_DEBUG_MODE_OUT_ADDR ) = 1; // enable debug mode
// start of the test
reg_debug_1 = 0xAA;
// very long wait
for (j = 0; j < 1600; j++);
for (j = 0; j < 1600; j++);
for (j = 0; j < 1600; j++);
}

View File

@ -1,110 +0,0 @@
from curses import baudrate
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer,Edge
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from interfaces.common import Macros
bit_time_ns = 0
reg = Regs()
@cocotb.test()
@repot_test
async def debug(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=31011)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
# calculate bit time
clk = clock.period/1000
global bit_time_ns
bit_time_ns = round(10**5 * clk / (1152))
cocotb.log.info(f"[TEST] bit time in nano second = {bit_time_ns}")
caravelEnv.drive_gpio_in((0,0),1) # IO[0] affects the uart selecting btw system and debug
caravelEnv.drive_gpio_in((5,5),1)
# wait for start of sending
await wait_reg1(cpu,caravelEnv,0XAA)
# caravelEnv.drive_gpio_in((0,0),1) # IO[0] affects the uart selecting btw system and debug
cocotb.log.info(f"[TEST] Start debug test")
# send random data to address 30'h00400024 and expect to recieve the same data back it back
dff_address = random.randint(0x00000400, 0x00000600) & 0xFFFFFFFC
data = random.getrandbits(32)
address = dff_address >>2 # address has to be shifted
# data = 0xFFFFFFF0
cocotb.log.info (f"[TEST] Executing DFF2 write address={hex(dff_address)} data = {hex(data)}")
await wb_write(caravelEnv,address,data)
receieved_data = await wb_read(caravelEnv,address)
if data != receieved_data:
cocotb.log.error(f"[TEST] DFF2 reading failed from address {hex(address)} expected data = {hex(data)} recieved data = {hex(receieved_data)}")
else:
cocotb.log.info(f"[TEST] PASS: DFF2 reading right value {hex(data)} from {hex(address)} ")
async def start_of_tx(caravelEnv):
while (True): # wait for the start of the transimission it 1 then 0
if (caravelEnv.monitor_gpio((6,6)).integer == 0):
break
await Timer(bit_time_ns, units='ns')
await Timer(bit_time_ns, units='ns')
async def uart_send_char(caravelEnv,char):
cocotb.log.info (f"[uart_send_char] start sending on uart {char}")
#send start bit
caravelEnv.drive_gpio_in((5,5),0)
await Timer(bit_time_ns, units='ns')
#send bits
for i in range(8):
caravelEnv.drive_gpio_in((5,5),char[i])
await Timer(bit_time_ns, units='ns')
# stop of frame
caravelEnv.drive_gpio_in((5,5),1)
await Timer(bit_time_ns, units='ns')
async def uart_get_char(caravelEnv):
await start_of_tx(caravelEnv)
char = ''
for i in range (8):
char = caravelEnv.monitor_gpio((6,6)).binstr + char
await Timer(bit_time_ns, units='ns')
cocotb.log.info (f"[uart_get_char] recieving {char} from uart")
return char
async def wb_write(caravelEnv,addr,data):
addr_bits = bin(addr)[2:].zfill(32)[::-1]
data_bits = bin(data)[2:].zfill(32)[::-1]
cocotb.log.debug(f"[TEST] address bits = {addr_bits} {type(addr_bits)}")
await uart_send_char(caravelEnv, '10000000') # write cmd
await uart_send_char(caravelEnv, '10000000') # size
await uart_send_char(caravelEnv, addr_bits[24:32])
await uart_send_char(caravelEnv, addr_bits[16:24])
await uart_send_char(caravelEnv, addr_bits[8:16])
await uart_send_char(caravelEnv, addr_bits[0:8])
await uart_send_char(caravelEnv, data_bits[24:32])
await uart_send_char(caravelEnv, data_bits[16:24])
await uart_send_char(caravelEnv, data_bits[8:16])
await uart_send_char(caravelEnv, data_bits[0:8])
async def wb_read(caravelEnv,addr):
addr_bits = bin(addr)[2:].zfill(32)[::-1]
await uart_send_char(caravelEnv, '01000000') # read cmd
await uart_send_char(caravelEnv, '10000000') # size
await uart_send_char(caravelEnv, addr_bits[24:32])
await uart_send_char(caravelEnv, addr_bits[16:24])
await uart_send_char(caravelEnv, addr_bits[8:16])
await uart_send_char(caravelEnv, addr_bits[0:8])
data_bits = await uart_get_char(caravelEnv)
data_bits += await uart_get_char(caravelEnv)
data_bits += await uart_get_char(caravelEnv)
data_bits += await uart_get_char(caravelEnv)
return int(data_bits,2)

View File

@ -1,458 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
reg = Regs()
@cocotb.test()
@repot_test
async def gpio_all_o(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=538624)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i<<32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i<<32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0XBB)
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] try drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
reg2 =0
await wait_reg1(cpu,caravelEnv,0XFF)
try:
reg2 =cpu.read_debug_reg2()
if reg2 == data_in:
cocotb.log.error(f"[TEST] Error: data {hex(data_in)} driven on gpio[31:0] is seen by firmware while gpios are configured as output")
else:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output it can see {reg2}")
except Exception as e:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output")
return
await ClockCycles(caravelEnv.clk, 10)
@cocotb.test()
@repot_test
async def gpio_all_i(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=56837)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
caravelEnv.release_gpio((37,0))
await wait_reg2(cpu,caravelEnv,0XFF)
if caravelEnv.monitor_gpio((37,0)).binstr != "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
cocotb.log.error(f"[TEST] ERROR: firmware can write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
else:
cocotb.log.info(f"[TEST] [TEST] PASS: firmware cannot write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
cocotb.log.info(f"[TEST] finish")
@cocotb.test()
@repot_test
async def gpio_all_i_pu(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=54138,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 0")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with even half with 0")
else:
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with zeros then release all gpio
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_i_pd(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=54138,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==0: #even
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with ones then release all gpio
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_bidir(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1144980)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0x1A)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i << 32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i << 32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0x2A)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xFFA88C5A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg2(cpu,caravelEnv,0xFF)
cocotb.log.info(f"[TEST] finish")
await ClockCycles(caravelEnv.clk, 10)

View File

@ -1,98 +0,0 @@
#include <defs.h>
#include <stub.c>
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0x1A; // try the gpios as output
reg_mprj_datal = 0x0;
reg_mprj_datah = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_datah = i;
reg_debug_2 = 37-j;
reg_mprj_datah = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_datah = 0x3f;
reg_mprj_datal = i;
reg_debug_2 = 32-j;
reg_mprj_datah = 0x00;
reg_mprj_datal = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
// test input
reg_debug_1 = 0X2A; // configuration done wait environment to send 0x8F66FD7B to reg_mprj_datal
while (reg_mprj_datal != 0x8F66FD7B);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_datal
while (reg_mprj_datal != 0xFFA88C5A);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XCC; // configuration done wait environment to send 0xC9536346 to reg_mprj_datal
while (reg_mprj_datal != 0xC9536346);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD1;
while (reg_mprj_datah != 0x3F);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD2;
while (reg_mprj_datah != 0x0);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD3;
while (reg_mprj_datah != 0x15);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD4;
while (reg_mprj_datah != 0x2A);
reg_debug_2=0xFF;
}

View File

@ -1,115 +0,0 @@
#include <defs.h>
#include <stub.c>
#define reg_mprj_userl (*(volatile uint32_t*)0x300FFFF0)
#define reg_mprj_userh (*(volatile uint32_t*)0x300FFFF4)
#define reg_oeb_userl (*(volatile uint32_t*)0x300FFFEC)
#define reg_oeb_userh (*(volatile uint32_t*)0x300FFFE8)
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_36 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_35 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_34 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_33 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_32 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_31 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_30 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_29 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_28 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_27 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_26 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_25 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_24 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_23 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_22 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_21 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_20 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_19 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_18 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_17 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_16 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_15 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_14 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_13 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_12 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_11 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_10 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_9 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_8 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_7 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_6 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_5 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_4 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_3 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_2 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_1 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_io_0 = GPIO_MODE_USER_STD_BIDIRECTIONAL;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_oeb_userl = 0x0;
reg_oeb_userh = 0x0;
reg_debug_1 = 0x1A; // try the gpios as output
reg_mprj_userl = 0x0;
reg_mprj_userh = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_userh = i;
reg_debug_2 = 37-j;
reg_mprj_userh = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_userh = 0x3f;
reg_mprj_userl = i;
reg_debug_2 = 32-j;
reg_mprj_userh = 0x00;
reg_mprj_userl = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
reg_oeb_userl = 0xFFFFFFFF;
reg_oeb_userh = 0x3F;
reg_mprj_userl =0;
reg_mprj_userh =0;
// test input
reg_debug_1 = 0XAA; // configuration done wait environment to send 0xFFFFFFFF to reg_mprj_userl
while (reg_mprj_userl != 0xFFFFFFFF);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xAAAAAAAA to reg_mprj_userl
while (reg_mprj_userl != 0xAAAAAAAA);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XCC; // configuration done wait environment to send 0x55555555 to reg_mprj_userl
while (reg_mprj_userl != 0x55555555);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XDD; // configuration done wait environment to send 0x0 to reg_mprj_userl
while (reg_mprj_userl != 0x0);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XD1;
while (reg_mprj_userh != 0x3F);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD2;
while (reg_mprj_userh != 0x0);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD3;
while (reg_mprj_userh != 0x15);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD4;
while (reg_mprj_userh != 0x2A);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD5;
reg_debug_2=0xFF;
}

View File

@ -1,86 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done wait environment to send 0xFFFFFFFF to reg_mprj_datal
while (reg_mprj_datal != 0xFFFFFFFF);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xAAAAAAAA to reg_mprj_datal
while (reg_mprj_datal != 0xAAAAAAAA);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XCC; // configuration done wait environment to send 0x55555555 to reg_mprj_datal
while (reg_mprj_datal != 0x55555555);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XDD; // configuration done wait environment to send 0x0 to reg_mprj_datal
while (reg_mprj_datal != 0x0);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD1;
while (reg_mprj_datah != 0x3F);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD2;
while (reg_mprj_datah != 0x0);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD3;
while (reg_mprj_datah != 0x15);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD4;
while (reg_mprj_datah != 0x2A);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD5;
reg_debug_1 = 0XD5; // for delay insertion for release
// trying to inject error by sending data to gpio by firmware where gpios configured as input
reg_mprj_datal = 0x5AE1FFB8; // random number
reg_mprj_datah = 0x1E; // random number
reg_debug_2 = 0xFF;
}

View File

@ -1,58 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,58 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_36 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_35 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_34 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_33 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_32 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_31 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_30 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_29 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_28 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_27 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_26 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_25 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_24 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_23 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_22 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_21 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_20 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_19 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_18 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_17 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_16 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_15 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_14 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_13 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_12 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_11 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_10 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_9 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_8 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_7 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_6 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_5 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_4 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_3 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_2 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_1 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_PULLDOWN;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,57 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,64 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
#define reg_mprj_userl (*(volatile uint32_t*)0x300FFFF0)
#define reg_mprj_userh (*(volatile uint32_t*)0x300FFFF4)
#define reg_oeb_userl (*(volatile uint32_t*)0x300FFFEC)
#define reg_oeb_userh (*(volatile uint32_t*)0x300FFFE8)
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_36 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_35 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_34 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_33 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_32 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_31 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_30 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_29 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_28 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_27 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_26 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_25 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_24 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_23 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_22 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_21 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_20 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_19 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_18 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_17 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_16 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_15 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_14 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_13 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_12 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_11 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_10 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_9 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_8 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_7 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_6 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_5 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_4 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_3 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_2 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_1 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_PULLUP;
reg_mprj_userl = 0xFFFFFFFF;
reg_mprj_userh = 0x3F;
reg_oeb_userl = 0x0;
reg_oeb_userh = 0x0;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,88 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
#define reg_mprj_userl (*(volatile uint32_t*)0x300FFFF0)
#define reg_mprj_userh (*(volatile uint32_t*)0x300FFFF4)
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_36 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_35 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_34 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_33 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_32 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_31 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_30 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_29 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_28 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_27 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_26 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_25 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_24 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_23 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_22 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_21 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_20 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_19 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_18 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_17 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_16 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_15 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_14 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_13 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_12 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_11 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_10 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_9 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_8 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_7 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_6 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_5 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_4 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_3 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_2 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_1 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_USER_STD_INPUT_NOPULL;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done wait environment to send 0xFFFFFFFF to reg_mprj_userl
while (reg_mprj_userl != 0xFFFFFFFF);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xAAAAAAAA to reg_mprj_userl
while (reg_mprj_userl != 0xAAAAAAAA);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XCC; // configuration done wait environment to send 0x55555555 to reg_mprj_userl
while (reg_mprj_userl != 0x55555555);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XDD; // configuration done wait environment to send 0x0 to reg_mprj_userl
while (reg_mprj_userl != 0x0);
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XD1;
while (reg_mprj_userh != 0x3F);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD2;
while (reg_mprj_userh != 0x0);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD3;
while (reg_mprj_userh != 0x15);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD4;
while (reg_mprj_userh != 0x2A);
reg_debug_2 = reg_mprj_userh;
reg_debug_1 = 0XD5;
reg_debug_1 = 0XD5; // for delay insertion for release
// trying to inject error by sending data to gpio by firmware where gpios configured as input
reg_mprj_userl = 0x5AE1FFB8; // random number
reg_mprj_userh = 0x1E; // random number
reg_debug_2 = 0xFF;
}

View File

@ -1,90 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0xAA; // finish configuration
reg_mprj_datal = 0x0;
reg_mprj_datah = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_datah = i;
reg_debug_2 = 37-j;
reg_mprj_datah = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_datah = 0x3f;
reg_mprj_datal = i;
reg_debug_2 = 32-j;
reg_mprj_datah = 0x00;
reg_mprj_datal = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
// try to give input
reg_debug_1 = 0XBB; // configuration done wait environment to send 0x8F66FD7B to reg_mprj_datal
int timeout = 100;
while (reg_mprj_datal != 0x8F66FD7B){
timeout--;
if (timeout==0){
break;
}
}
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XFF; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_datal
}

View File

@ -1,95 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
// Debug reg DEBUG_ON
#define reg_mprj_userl (*(volatile uint32_t*)0x300FFFF0)
#define reg_mprj_userh (*(volatile uint32_t*)0x300FFFF4)
#define reg_oeb_userl (*(volatile uint32_t*)0x300FFFEC)
#define reg_oeb_userh (*(volatile uint32_t*)0x300FFFE8)
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_3 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_2 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_USER_STD_OUTPUT;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_oeb_userl = 0x0;
reg_oeb_userh = 0x0;
reg_debug_1 = 0xAA; // finish configuration
reg_mprj_userl = 0x0;
reg_mprj_userh = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_userh = i;
reg_debug_2 = 37-j;
reg_mprj_userh = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_userh = 0x3f;
reg_mprj_userl = i;
reg_debug_2 = 32-j;
reg_mprj_userh = 0x00;
reg_mprj_userl = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
// try to give input
reg_debug_1 = 0XBB; // configuration done wait environment to send 0x8F66FD7B to reg_mprj_userl
int timeout = 100;
while (reg_mprj_userl != 0x8F66FD7B){
timeout--;
if (timeout==0){
break;
}
}
reg_debug_2 = reg_mprj_userl;
reg_debug_1 = 0XFF; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_userl
}

View File

@ -1,468 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
reg = Regs()
@cocotb.test()
@repot_test
async def gpio_all_o_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=542674)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring as user output")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i<<32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i<<32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0XBB)
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] try send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
reg2 =0
await wait_reg1(cpu,caravelEnv,0XFF)
try:
reg2 =cpu.read_debug_reg2()
if reg2 == data_in:
cocotb.log.error(f"[TEST] Error: data {hex(data_in)} driven on gpio[31:0] is seen by firmware while gpios are configured as output")
else:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output it can see {reg2}")
except Exception as e:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output")
return
await ClockCycles(caravelEnv.clk, 10)
@cocotb.test()
@repot_test
async def gpio_all_i_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=498255)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
caravelEnv.release_gpio((37,0))
await wait_reg2(cpu,caravelEnv,0XFF)
if caravelEnv.monitor_gpio((37,0)).binstr != "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
cocotb.log.error(f"[TEST] ERROR: firmware can write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
else:
cocotb.log.info(f"[TEST] [TEST] PASS: firmware cannot write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
cocotb.log.info(f"[TEST] finish")
@cocotb.test()
@repot_test
async def gpio_all_i_pu_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=56875,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 0")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with even half with 0")
else:
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with zeros then release all gpio
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_i_pd_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=54138,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==0: #even
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with ones then release all gpio
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_bidir_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=266662)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0x1A)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i << 32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i << 32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk, 10)
caravelEnv.drive_gpio_in((31,0),0)
await ClockCycles(caravelEnv.clk, 10)
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
await wait_reg2(cpu,caravelEnv,0XFF)
cocotb.log.info(f"[TEST] finish")
await ClockCycles(caravelEnv.clk, 10)

View File

@ -1,87 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done wait environment to send 0xFFFFFFFF to reg_mprj_datal
while (reg_mprj_datal != 0xfe003fff); // gpios 14 to 25 has to be 0
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XBB; // configuration done wait environment to send 0xAAAAAAAA to reg_mprj_datal
while (reg_mprj_datal != 0xaa002aaa);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XCC; // configuration done wait environment to send 0x55555555 to reg_mprj_datal
while (reg_mprj_datal != 0x54001555);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XDD; // configuration done wait environment to send 0x0 to reg_mprj_datal
while (reg_mprj_datal != 0x0);
reg_debug_2 = reg_mprj_datal;
reg_debug_1 = 0XD1;
while (reg_mprj_datah != 0x3F);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD2;
while (reg_mprj_datah != 0x0);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD3;
while (reg_mprj_datah != 0x15);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD4;
while (reg_mprj_datah != 0x2A);
reg_debug_2 = reg_mprj_datah;
reg_debug_1 = 0XD5;
reg_debug_1 = 0XD5; // for delay insertion for release
// trying to inject error by sending data to gpio by firmware where gpios configured as input
reg_mprj_datal = 0x5AE1FFB8; // random number
reg_mprj_datah = 0x1E; // random number
reg_debug_2 = 0xFF;
}

View File

@ -1,58 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,57 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_INPUT_PULLUP;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0XAA; // configuration done
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
while (true);
}

View File

@ -1,81 +0,0 @@
#include <defs.h>
#include <stub.c>
#include "../bitbang/bitbang_functions.c"
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 = 0xAA; // finish configuration
reg_mprj_datal = 0x0;
reg_mprj_datah = 0x0;
i = 0x20;
for (j = 0; j < 5; j++) {
reg_mprj_datah = i;
reg_debug_2 = 37-j;
reg_mprj_datah = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x20;
}
i = 0x80000000;
for (j = 0; j < 32; j++) {
reg_mprj_datah = 0x3f;
reg_mprj_datal = i;
reg_debug_2 = 32-j;
reg_mprj_datah = 0x00;
reg_mprj_datal = 0x00000000;
reg_debug_2 = 0;
i >>=1;
i |= 0x80000000;
}
reg_debug_1 = 0XFF; // configuration done wait environment to send 0xFFA88C5A to reg_mprj_datal
}

View File

@ -1,500 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from interfaces.common import Macros
from cocotb.binary import BinaryValue
reg = Regs()
@cocotb.test()
@repot_test
async def gpio_all_o_caravan(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=586652)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
expected_data = bin(i<<32)[2:].zfill(38)[:13] +"zzzzzzzzzzz" + bin(i<<32)[2:].zfill(38)[24:]
if caravelEnv.monitor_gpio((37,0)).binstr != expected_data:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {expected_data}')
await wait_reg2(cpu,caravelEnv,0)
expected_data = bin(0)[2:].zfill(38)[:13] +"zzzzzzzzzzz" + bin(0)[2:].zfill(38)[24:]
if caravelEnv.monitor_gpio((37,0)).binstr != expected_data:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {expected_data}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
expected_data = bin(i)[2:].zfill(32)[:7] +"zzzzzzzzzzz" + bin(i)[2:].zfill(32)[18:]
if caravelEnv.monitor_gpio((31,0)).binstr != expected_data :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {expected_data}')
await wait_reg2(cpu,caravelEnv,0)
expected_data = bin(0)[2:].zfill(38)[:13] +"zzzzzzzzzzz" + bin(0)[2:].zfill(38)[24:]
if caravelEnv.monitor_gpio((37,0)).binstr != expected_data:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {expected_data}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0XFF)
await ClockCycles(caravelEnv.clk, 10)
@cocotb.test()
@repot_test
async def gpio_all_i_caravan(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=56837)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
mask = 0xfe003fff
data_expected = data_in & mask
if cpu.read_debug_reg2() == data_expected:
cocotb.log.info(f"[TEST] data {bin(data_in)} sent successfully through gpio[31:0] and seen as {bin(data_expected)}")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {bin(cpu.read_debug_reg2())} instead of {bin(data_expected)}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
data_expected = data_in & mask
if cpu.read_debug_reg2() == data_expected:
cocotb.log.info(f"[TEST] data {bin(data_in)} sent successfully through gpio[31:0] and seen as {bin(data_expected)}")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {bin(cpu.read_debug_reg2())} instead of {bin(data_expected)}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
data_expected = data_in & mask
if cpu.read_debug_reg2() == data_expected:
cocotb.log.info(f"[TEST] data {bin(data_in)} sent successfully through gpio[31:0] and seen as {bin(data_expected)}")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {bin(cpu.read_debug_reg2())} instead of {bin(data_expected)}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
data_expected = data_in & mask
if cpu.read_debug_reg2() == data_expected:
cocotb.log.info(f"[TEST] data {bin(data_in)} sent successfully through gpio[31:0] and seen as {bin(data_expected)}")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {bin(cpu.read_debug_reg2())} instead of {bin(data_expected)}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
caravelEnv.release_gpio((37,0))
await wait_reg2(cpu,caravelEnv,0XFF)
if caravelEnv.monitor_gpio((37,0)).binstr != "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
cocotb.log.error(f"[TEST] ERROR: firmware can write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
else:
cocotb.log.info(f"[TEST] [TEST] PASS: firmware cannot write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
cocotb.log.info(f"[TEST] finish")
@cocotb.test()
@repot_test
async def gpio_all_i_pu_caravan(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=58961,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and float and {i} gpio must be z in caravan")
continue
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i%2 ==0: #even
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and drived with odd half with 0 and {i} gpio must be z in caravan")
continue
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 0")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i%2 ==0: #odd
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with even half with 0")
else:
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and drived with even half with 0 and {i} gpio must be z in caravan")
continue
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1) and i%2==0:
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and drived with odd half with 1 and {i} gpio must be z in caravan")
continue
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1) and i%2==1:
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and drived with even half with 1 and {i} gpio must be z in caravan")
continue
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with zeros then release all gpio
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pullup and all released and {i} gpio must be z in caravan")
continue
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_i_pd_caravan(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=58961,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pulldown and float and {i} gpio must be z in caravan")
continue
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1) and i%2==0:
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pulldown and drived with odd half with 0 and {i} gpio must be z in caravan")
continue
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1) and i%2==1:
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pulldown and drived with even half with 0 and {i} gpio must be z in caravan")
continue
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pulldown and drived with odd half with 1 and {i} gpio must be z in caravan")
continue
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i%2 ==0: #even
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while configured as input pulldown and drived with odd half with 1 and {i} gpio must be z in caravan")
continue
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with ones then release all gpio
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.mprj_io.value.binstr[::-1]
for i in range(38):
if i in range(14,25,1):
if gpio[i] != "z":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of z while while configured as input pulldown and all released and {i} gpio must be z in caravan")
continue
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_bidir(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1144980)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0x1A)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i << 32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i << 32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0x2A)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xFFA88C5A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xC9536346
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg2(cpu,caravelEnv,0xFF)
cocotb.log.info(f"[TEST] finish")
await ClockCycles(caravelEnv.clk, 10)

View File

@ -1,468 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
reg = Regs()
@cocotb.test()
@repot_test
async def gpio_all_o_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=542674)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring as user output")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i<<32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i<<32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
await wait_reg1(cpu,caravelEnv,0XBB)
data_in = 0x8F66FD7B
cocotb.log.info(f"[TEST] try send {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
reg2 =0
await wait_reg1(cpu,caravelEnv,0XFF)
try:
reg2 =cpu.read_debug_reg2()
if reg2 == data_in:
cocotb.log.error(f"[TEST] Error: data {hex(data_in)} driven on gpio[31:0] is seen by firmware while gpios are configured as output")
else:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output it can see {reg2}")
except Exception as e:
cocotb.log.info(f"[TEST] driven data {hex(data_in)} sent can't be sent to gpio[31:0] when it configure as output")
return
await ClockCycles(caravelEnv.clk, 10)
@cocotb.test()
@repot_test
async def gpio_all_i_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=56694)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
caravelEnv.release_gpio((37,0))
await wait_reg2(cpu,caravelEnv,0XFF)
if caravelEnv.monitor_gpio((37,0)).binstr != "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
cocotb.log.error(f"[TEST] ERROR: firmware can write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
else:
cocotb.log.info(f"[TEST] [TEST] PASS: firmware cannot write to the gpios while they are configured as input_nopull gpio= {caravelEnv.monitor_gpio((37,0))}")
cocotb.log.info(f"[TEST] finish")
@cocotb.test()
@repot_test
async def gpio_all_i_pu_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=58961,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 0")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pullup and drived with even half with 0")
else:
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and drived with even half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with zeros then release all gpio
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pullup and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_i_pd_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=58961,num_error=2000)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0xAA)
await caravelEnv.release_csb()
# monitor the output of padframe module it suppose to be all ones when no input is applied
await ClockCycles(caravelEnv.clk,100)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and float")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with zero
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive gpios with ones
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with zeros and float other half
data_in = 0x0
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i]!="0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with even half with 0")
await ClockCycles(caravelEnv.clk,1000)
# drive odd half gpios with ones and float other half
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(0,38,2):
caravelEnv.release_gpio(i) # release even gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==0: #even
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive even half gpios with zeros and float other half
caravelEnv.drive_gpio_in((37,0),data_in)
for i in range(1,38,2):
caravelEnv.release_gpio(i) # release odd gpios
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if i%2 ==1: #odd
if gpio[i]!="1":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 1 while configured as input pulldown and drived with odd half with 1")
else:
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and drived with odd half with 1")
await ClockCycles(caravelEnv.clk,1000)
# drive with ones then release all gpio
data_in = 0x3FFFFFFFFF
caravelEnv.drive_gpio_in((37,0),data_in)
await ClockCycles(caravelEnv.clk,1000)
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk,1000)
gpio = dut.uut.padframe.mprj_io_in.value.binstr
for i in range(38):
if gpio[i] != "0":
cocotb.log.error(f"[TEST] gpio[{i}] is having wrong value {gpio[i]} instead of 0 while configured as input pulldown and all released")
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def gpio_all_bidir_user(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=290455)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
uut = dut.uut
await wait_reg1(cpu,caravelEnv,0x1A)
await caravelEnv.release_csb()
cocotb.log.info("[TEST] finish configuring ")
i= 0x20
for j in range(5):
await wait_reg2(cpu,caravelEnv,37-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,0)).integer != i << 32:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,0))} instead of {bin(i << 32)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'[TEST] Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x20
i= 0x80000000
for j in range(32):
await wait_reg2(cpu,caravelEnv,32-j)
cocotb.log.info(f'[Test] gpio out = {caravelEnv.monitor_gpio((37,0))} j = {j}')
if caravelEnv.monitor_gpio((37,32)).integer != 0x3f:
cocotb.log.error(f'[TEST] Wrong gpio high bits output {caravelEnv.monitor_gpio((37,32))} instead of {bin(0x3f)} ')
if caravelEnv.monitor_gpio((31,0)).integer != i :
cocotb.log.error(f'[TEST] Wrong gpio low bits output {caravelEnv.monitor_gpio((31,0))} instead of {bin(i)}')
await wait_reg2(cpu,caravelEnv,0)
if caravelEnv.monitor_gpio((37,0)).integer != 0:
cocotb.log.error(f'Wrong gpio output {caravelEnv.monitor_gpio((37,0))} instead of {bin(0x00000)}')
i = i >> 1
i |= 0x80000000
caravelEnv.release_gpio((37,0))
await ClockCycles(caravelEnv.clk, 10)
caravelEnv.drive_gpio_in((31,0),0)
await ClockCycles(caravelEnv.clk, 10)
await wait_reg1(cpu,caravelEnv,0xAA)
cocotb.log.info(f"[TEST] configuration finished")
data_in = 0xFFFFFFFF
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xBB)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0xAAAAAAAA
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xCC)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x55555555
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xDD)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[31:0]")
caravelEnv.drive_gpio_in((31,0),data_in)
await wait_reg1(cpu,caravelEnv,0xD1)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[31:0]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datal has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x3F
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD2)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x0
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD3)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x15
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0xD4)
if cpu.read_debug_reg2() == data_in:
cocotb.log.info(f"[TEST] data {hex(data_in)} sent successfully through gpio[37:32]")
else:
cocotb.log.error(f"[TEST] Error: reg_mprj_datah has recieved wrong data {cpu.read_debug_reg2()} instead of {data_in}")
data_in = 0x2A
cocotb.log.info(f"[TEST] drive {hex(data_in)} to gpio[37:32]")
caravelEnv.drive_gpio_in((37,32),data_in)
await wait_reg1(cpu,caravelEnv,0XD5)
await wait_reg2(cpu,caravelEnv,0XFF)
cocotb.log.info(f"[TEST] finish")
await ClockCycles(caravelEnv.clk, 10)

View File

@ -1,5 +0,0 @@
int main(){
// do nothing
return 0;
}

View File

@ -1,11 +0,0 @@
import cocotb
from tests.common_functions.test_functions import *
@cocotb.test()
@repot_test
async def helloWorld(dut):
caravelEnv,clock = await test_configure(dut)
cocotb.log.info("[Test] Hello world")
caravelEnv.print_gpios_ctrl_val()
caravelEnv.print_gpios_HW_val()

View File

@ -1,20 +0,0 @@
#include <defs.h>
#include <stub.c>
// --------------------------------------------------------
void main(){
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
/* Monitor pins must be set to output */
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
/* Apply configuration */
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_1 =0xAA;
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
return;
}

View File

@ -1,15 +0,0 @@
#include <defs.h>
#include <stub.c>
// --------------------------------------------------------
void main(){
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0xBB;
while (reg_debug_1 != 0xAA);
reg_hkspi_disable = 0;
reg_hkspi_pll_ena =0;
reg_debug_1 =0xBB;
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
}

View File

@ -1,152 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <stub.c>
// --------------------------------------------------------
/*
* PLL Test (self-switching)
* - Switches PLL bypass in housekeeping
* - Changes PLL divider in housekeeping
*
*/
void main()
{
int i;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
/* Monitor pins must be set to output */
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_OUTPUT;
/* Apply configuration */
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
// Start test
/*
*-------------------------------------------------------------
* Register 2610_000c reg_hkspi_pll_ena
* SPI address 0x08 = PLL enables
* bit 0 = PLL enable, bit 1 = DCO enable
*
* Register 2610_0010 reg_hkspi_pll_bypass
* SPI address 0x09 = PLL bypass
* bit 0 = PLL bypass
*
* Register 2610_0020 reg_hkspi_pll_source
* SPI address 0x11 = PLL source
* bits 0-2 = phase 0 divider, bits 3-5 = phase 90 divider
*
* Register 2610_0024 reg_hkspi_pll_divider
* SPI address 0x12 = PLL divider
* bits 0-4 = feedback divider
*
* Register 2620_0004 reg_clk_out_dest
* SPI address 0x1b = Output redirect
* bit 0 = trap to mprj_io[13]
* bit 1 = clk to mprj_io[14]
* bit 2 = clk2 to mprj_io[15]
*-------------------------------------------------------------
*/
// Monitor the core clock and user clock on mprj_io[14] and mprj_io[15]
// reg_clk_out_dest = 0x6 to turn on, 0x0 to turn off
// Write checkpoint for clock counting (PLL bypassed)
reg_debug_1 = 0xA1;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x0;
reg_debug_1 = 0xA2;
// Set PLL enable, no DCO mode
reg_hkspi_pll_ena = 0x1;
// Set PLL output divider to 0x03
reg_hkspi_pll_source = 0x3;
// Write checkpoint for clock counting (PLL bypassed)
reg_debug_1 = 0xA3;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x0;
reg_debug_1 = 0xA4;
// Disable PLL bypass
reg_hkspi_pll_bypass = 0x0;
// Write checkpoint for clock counting
reg_debug_1 = 0xA5;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x0;
reg_debug_1 = 0xA6;
// Write 0x03 to feedback divider (was 0x04)
reg_hkspi_pll_divider = 0x3;
// Write checkpoint
reg_debug_1 = 0xA7;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x0;
reg_debug_1 = 0xA8;
// Write 0x04 to PLL output divider
reg_hkspi_pll_source = 0x4;
// Write checkpoint
reg_debug_1 = 0xA9;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x6;
reg_clk_out_dest = 0x0;
reg_debug_1 = 0xAa;
// End test
reg_mprj_datal = 0xA0900000;
}

View File

@ -1,86 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
reg = Regs()
caravel_clock = 0
user_clock = 0
@cocotb.test()
@repot_test
async def pll(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=47279)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
error_margin = 0.1
await wait_reg1(cpu,caravelEnv,0xA1)
await cocotb.start(calculate_clk_period(dut.bin14_monitor,"caravel clock"))
await cocotb.start(calculate_clk_period(dut.bin15_monitor,"user clock"))
await wait_reg1(cpu,caravelEnv,0xA3)
if abs(caravel_clock - user_clock) > error_margin*caravel_clock:
cocotb.log.error(f"[TEST] Error: clocks should be equal in phase 1 but caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
else:
cocotb.log.info(f"[TEST] pass phase 1 caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
await cocotb.start(calculate_clk_period(dut.bin14_monitor,"caravel clock"))
await cocotb.start(calculate_clk_period(dut.bin15_monitor,"user clock"))
await wait_reg1(cpu,caravelEnv,0xA5)
if abs(caravel_clock - user_clock) > error_margin*caravel_clock:
cocotb.log.error(f"[TEST] Error: clocks should be equal in phase 2 but caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
else:
cocotb.log.info(f"[TEST] pass phase 2 caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
await cocotb.start(calculate_clk_period(dut.bin14_monitor,"caravel clock"))
await cocotb.start(calculate_clk_period(dut.bin15_monitor,"user clock"))
await wait_reg1(cpu,caravelEnv,0xA7)
if abs(caravel_clock - user_clock*3) > error_margin*caravel_clock:
cocotb.log.error(f"[TEST] Error: user clock shoud be 3 times caravel clock in phase 3 but caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
else:
cocotb.log.info(f"[TEST] pass phase 3 caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
await cocotb.start(calculate_clk_period(dut.bin14_monitor,"caravel clock"))
await cocotb.start(calculate_clk_period(dut.bin15_monitor,"user clock "))
await wait_reg1(cpu,caravelEnv,0xA9)
if abs(caravel_clock - user_clock*3) > error_margin*caravel_clock:
cocotb.log.error(f"[TEST] Error: user clock shoud be 3 times caravel clock in phase 4 but caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
else:
cocotb.log.info(f"[TEST] pass phase 4 caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
await cocotb.start(calculate_clk_period(dut.bin14_monitor,"caravel clock"))
await cocotb.start(calculate_clk_period(dut.bin15_monitor,"user clock"))
await wait_reg1(cpu,caravelEnv,0xAa)
if abs(caravel_clock - user_clock*4) > error_margin*caravel_clock:
cocotb.log.error(f"[TEST] Error: user clock shoud be 4 times caravel clock in phase 5 but caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
else:
cocotb.log.info(f"[TEST] pass phase 5 caravel clock = {round(1000000/caravel_clock,2)} MHz user clock = {round(1000000/user_clock,2)} MHz")
await ClockCycles(caravelEnv.clk,10000)
# for i in range(1000):
# await ClockCycles(caravelEnv.clk,10000)
# cocotb.log.info(f"time = {cocotb.simulator.get_sim_time()}")
async def calculate_clk_period(clk,name):
await RisingEdge(clk)
initial_time = cocotb.simulator.get_sim_time()
initial_time = (initial_time[0] <<32) | (initial_time[1])
for i in range(100):
await RisingEdge(clk)
end_time = cocotb.simulator.get_sim_time()
end_time = (end_time[0] <<32) | (end_time[1])
val = (end_time - initial_time) / 100
cocotb.log.debug(f"[TEST] clock of {name} is {val}")
if name == "caravel clock":
global caravel_clock
caravel_clock = val
elif name == "user clock":
global user_clock
user_clock = val
val = str(val)
return val

View File

@ -1,148 +0,0 @@
from faulthandler import disable
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
reg = Regs()
caravel_clock = 0
user_clock = 0
core_clock = 0
@cocotb.test()
@repot_test
async def clock_redirect(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=13052)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
error_margin = 0.1
# calculate core clock
await cocotb.start(calculate_clk_period(dut.uut.clock,"core clock"))
await ClockCycles(caravelEnv.clk,110)
cocotb.log.info(f"[TEST] core clock requency = {round(1000000/core_clock,2)} MHz period = {core_clock}ps")
await wait_reg1(cpu,caravelEnv,0xAa)
# check clk redirect working
#user clock
clock_name = "user clock"
await write_reg_spi(caravelEnv,0x1b,0x0) # disable user clock output redirect
await cocotb.start(calculate_clk_period(dut.bin14_monitor,clock_name))
await ClockCycles(caravelEnv.clk,110)
if user_clock != 0:
cocotb.log.error(f"[TEST] Error: {clock_name} is directed while clk2_output_dest is disabled")
else:
cocotb.log.info(f"[TEST] Pass: {clock_name} has not directed when reg clk2_output_dest is disabled")
await write_reg_spi(caravelEnv,0x1b,0x4) # enable user clock output redirect
await cocotb.start(calculate_clk_period(dut.bin14_monitor,clock_name))
await ClockCycles(caravelEnv.clk,110)
if abs(user_clock - core_clock) > (error_margin*core_clock):
cocotb.log.error(f"[TEST] Error: {clock_name} is directed with wrong value {clock_name} period = {user_clock} and core clock = {core_clock}")
else:
cocotb.log.info(f"[TEST] Pass: {clock_name} has directed successfully")
#caravel clock
clock_name = "caravel clock"
await write_reg_spi(caravelEnv,0x1b,0x0) # disable caravel clock output redirect
await cocotb.start(calculate_clk_period(dut.bin14_monitor,clock_name))
await ClockCycles(caravelEnv.clk,110)
if caravel_clock != 0:
cocotb.log.error(f"[TEST] Error: {clock_name} is directed while clk2_output_dest is disabled")
else:
cocotb.log.info(f"[TEST] Pass: {clock_name} has not directed when reg clk2_output_dest is disabled")
await write_reg_spi(caravelEnv,0x1b,0x4) # enable caravel clock output redirect
await cocotb.start(calculate_clk_period(dut.bin15_monitor,clock_name))
await ClockCycles(caravelEnv.clk,110)
if abs(caravel_clock - core_clock) > error_margin*core_clock:
cocotb.log.error(f"[TEST] Error: {clock_name} is directed with wrong value {clock_name} period = {caravel_clock} and core clock = {core_clock}")
else:
cocotb.log.info(f"[TEST] Pass: {clock_name} has directed successfully")
async def calculate_clk_period(clk,name):
await RisingEdge(clk)
initial_time = cocotb.simulator.get_sim_time()
initial_time = (initial_time[0] <<32) | (initial_time[1])
for i in range(100):
await RisingEdge(clk)
end_time = cocotb.simulator.get_sim_time()
end_time = (end_time[0] <<32) | (end_time[1])
val = (end_time - initial_time) / 100
cocotb.log.debug(f"[TEST] clock of {name} is {val}")
if name == "caravel clock":
global caravel_clock
caravel_clock = val
elif name == "user clock":
global user_clock
user_clock = val
elif name == "core clock":
global core_clock
core_clock = val
return val
@cocotb.test()
@repot_test
async def hk_disable(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=11393)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
# check spi working by writing to PLL enables
old_pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {old_pll_enable}")
await write_reg_spi(caravelEnv,0x8,1-old_pll_enable)
pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {pll_enable}")
if pll_enable == 1-old_pll_enable:
cocotb.log.info(f"[TEST] Pass: SPI swap pll_enable value from {old_pll_enable} to {pll_enable}")
else:
cocotb.log.error(f"[TEST] Error: SPI isn't working correctly it cant change pll from {old_pll_enable} to {1-old_pll_enable}")
old_pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {old_pll_enable}")
await write_reg_spi(caravelEnv,0x8,1-old_pll_enable)
pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {pll_enable}")
if pll_enable == 1-old_pll_enable:
cocotb.log.info(f"[TEST] Pass: SPI swap pll_enable value from {old_pll_enable} to {pll_enable}")
else:
cocotb.log.error(f"[TEST] Error: SPI isn't working correctly it cant change pll from {old_pll_enable} to {1-old_pll_enable}")
# disable Housekeeping SPIca
await write_reg_spi(caravelEnv,0x6f,0x1)
# try to change pll_en
old_pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {old_pll_enable}")
await write_reg_spi(caravelEnv,0x8,1-old_pll_enable)
pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {pll_enable}")
if pll_enable == 1-old_pll_enable:
cocotb.log.error(f"[TEST] Error: SPI swap pll_enable value from {old_pll_enable} to {pll_enable} while housekeeping spi is disabled")
else:
cocotb.log.info(f"[TEST] pass: SPI isn't working when SPI housekeeping is disabled")
# enable SPI housekeeping through firmware
await wait_reg2(cpu,caravelEnv,0xBB) # start waiting on reg1 AA
cpu.write_debug_reg1_backdoor(0xAA)
await wait_reg1(cpu,caravelEnv,0xBB) # enabled the housekeeping
old_pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {old_pll_enable}")
await write_reg_spi(caravelEnv,0x8,1-old_pll_enable)
pll_enable = dut.uut.housekeeping.pll_ena.value.integer
cocotb.log.debug(f"[TEST] pll_enable = {pll_enable}")
if pll_enable == 1-old_pll_enable:
cocotb.log.info(f"[TEST] Pass: Housekeeping SPI has been enabled correctly through firmware")
else:
cocotb.log.error(f"[TEST] Error: Housekeeping SPI failed to be enabled through firmware")

View File

@ -1,11 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
return;
}

View File

@ -1,11 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
return;
}

View File

@ -1,11 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
return;
}

View File

@ -1,333 +0,0 @@
#include <defs.h>
#include <stub.c>
// access all housekeeping registers that can be access through firmware and change it's value
void main(){
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// store RO value regs
int old_reg_hkspi_status = reg_hkspi_status;
int old_reg_hkspi_chip_id = reg_hkspi_chip_id;
int old_reg_hkspi_user_id = reg_hkspi_user_id;
int old_reg_hkspi_trap = reg_hkspi_trap;
int old_reg_hkspi_irq = reg_hkspi_irq;
// write 1 ones to all registers
reg_mprj_io_0 = 0xFFFFFFFF;
reg_mprj_io_1 = 0xFFFFFFFF;
reg_mprj_io_2 = 0xFFFFFFFF;
reg_mprj_io_3 = 0xFFFFFFFF;
reg_mprj_io_4 = 0xFFFFFFFF;
reg_mprj_io_5 = 0xFFFFFFFF;
reg_mprj_io_6 = 0xFFFFFFFF;
reg_mprj_io_7 = 0xFFFFFFFF;
reg_mprj_io_8 = 0xFFFFFFFF;
reg_mprj_io_9 = 0xFFFFFFFF;
reg_mprj_io_10 = 0xFFFFFFFF;
reg_mprj_io_11 = 0xFFFFFFFF;
reg_mprj_io_12 = 0xFFFFFFFF;
reg_mprj_io_13 = 0xFFFFFFFF;
reg_mprj_io_14 = 0xFFFFFFFF;
reg_mprj_io_15 = 0xFFFFFFFF;
reg_mprj_io_16 = 0xFFFFFFFF;
reg_mprj_io_17 = 0xFFFFFFFF;
reg_mprj_io_18 = 0xFFFFFFFF;
reg_mprj_io_19 = 0xFFFFFFFF;
reg_mprj_io_20 = 0xFFFFFFFF;
reg_mprj_io_21 = 0xFFFFFFFF;
reg_mprj_io_22 = 0xFFFFFFFF;
reg_mprj_io_23 = 0xFFFFFFFF;
reg_mprj_io_24 = 0xFFFFFFFF;
reg_mprj_io_25 = 0xFFFFFFFF;
reg_mprj_io_26 = 0xFFFFFFFF;
reg_mprj_io_27 = 0xFFFFFFFF;
reg_mprj_io_28 = 0xFFFFFFFF;
reg_mprj_io_29 = 0xFFFFFFFF;
reg_mprj_io_30 = 0xFFFFFFFF;
reg_mprj_io_31 = 0xFFFFFFFF;
reg_mprj_io_32 = 0xFFFFFFFF;
reg_mprj_io_33 = 0xFFFFFFFF;
reg_mprj_io_34 = 0xFFFFFFFF;
reg_mprj_io_35 = 0xFFFFFFFF;
reg_mprj_io_36 = 0xFFFFFFFF;
reg_mprj_io_37 = 0xFFFFFFFF;
// house keeping
reg_hkspi_status = 0xFFFFFFFF;
reg_hkspi_chip_id = 0xFFFFFFFF;
reg_hkspi_user_id = 0xFFFFFFFF;
reg_hkspi_pll_ena = 0xFFFFFFFF;
reg_hkspi_pll_bypass = 0xFFFFFFFF;
reg_hkspi_irq = 0xFFFFFFFF;
// reg_hkspi_reset = 0xFFFFFFFF; can't write 1 to it cpu would be reset
reg_hkspi_trap = 0xFFFFFFFF;
reg_hkspi_pll_trim = 0xFFFFFFFF;
reg_hkspi_pll_source = 0xFFFFFFFF;
reg_hkspi_pll_divider = 0xFFFFFFFF;
// sys
reg_clk_out_dest = 0xFFFFFFFF;
reg_hkspi_disable = 0xFFFFFFFF;
// read ones that has been written
if (reg_mprj_io_0 != 0x1FFF)
reg_debug_1 =0x1;
if (reg_mprj_io_1 != 0x1FFF)
reg_debug_1 =0x2;
if (reg_mprj_io_2 != 0x1FFF)
reg_debug_1 =0x3;
if (reg_mprj_io_3 != 0x1FFF)
reg_debug_1 =0x4;
if (reg_mprj_io_4 != 0x1FFF)
reg_debug_1 =0x5;
if (reg_mprj_io_5 != 0x1FFF)
reg_debug_1 =0x6;
if (reg_mprj_io_6 != 0x1FFF)
reg_debug_1 =0x7;
if (reg_mprj_io_7 != 0x1FFF)
reg_debug_1 =0x8;
if (reg_mprj_io_8 != 0x1FFF)
reg_debug_1 =0x9;
if (reg_mprj_io_9 != 0x1FFF)
reg_debug_1 =0xa;
if (reg_mprj_io_10 != 0x1FFF)
reg_debug_1 =0xb;
if (reg_mprj_io_11 != 0x1FFF)
reg_debug_1 =0xc;
if (reg_mprj_io_12 != 0x1FFF)
reg_debug_1 =0xd;
if (reg_mprj_io_13 != 0x1FFF)
reg_debug_1 =0xe;
if (reg_mprj_io_14 != 0x1FFF)
reg_debug_1 =0xf;
if (reg_mprj_io_15 != 0x1FFF)
reg_debug_1 =0x10;
if (reg_mprj_io_16 != 0x1FFF)
reg_debug_1 =0x11;
if (reg_mprj_io_17 != 0x1FFF)
reg_debug_1 =0x12;
if (reg_mprj_io_18 != 0x1FFF)
reg_debug_1 =0x13;
if (reg_mprj_io_19 != 0x1FFF)
reg_debug_1 =0x14;
if (reg_mprj_io_20 != 0x1FFF)
reg_debug_1 =0x15;
if (reg_mprj_io_21 != 0x1FFF)
reg_debug_1 =0x16;
if (reg_mprj_io_22 != 0x1FFF)
reg_debug_1 =0x17;
if (reg_mprj_io_23 != 0x1FFF)
reg_debug_1 =0x18;
if (reg_mprj_io_24 != 0x1FFF)
reg_debug_1 =0x19;
if (reg_mprj_io_25 != 0x1FFF)
reg_debug_1 =0x1a;
if (reg_mprj_io_26 != 0x1FFF)
reg_debug_1 =0x1b;
if (reg_mprj_io_27 != 0x1FFF)
reg_debug_1 =0x1c;
if (reg_mprj_io_28 != 0x1FFF)
reg_debug_1 =0x1d;
if (reg_mprj_io_29 != 0x1FFF)
reg_debug_1 =0x1e;
if (reg_mprj_io_30 != 0x1FFF)
reg_debug_1 =0x1f;
if (reg_mprj_io_31 != 0x1FFF)
reg_debug_1 =0x20;
if (reg_mprj_io_32 != 0x1FFF)
reg_debug_1 =0x21;
if (reg_mprj_io_33 != 0x1FFF)
reg_debug_1 =0x22;
if (reg_mprj_io_34 != 0x1FFF)
reg_debug_1 =0x23;
if (reg_mprj_io_35 != 0x1FFF)
reg_debug_1 =0x24;
if (reg_mprj_io_36 != 0x1FFF)
reg_debug_1 =0x25;
if (reg_mprj_io_37 != 0x1FFF)
reg_debug_1 =0x26;
// housekeeping
if (reg_hkspi_status != old_reg_hkspi_status) // RO
reg_debug_1 =0x27;
if (reg_hkspi_chip_id != old_reg_hkspi_chip_id) // RO
reg_debug_1 =0x28;
if (reg_hkspi_user_id != old_reg_hkspi_user_id) // RO
reg_debug_1 =0x29;
if (reg_hkspi_pll_ena != 0x3) // size =2
reg_debug_1 =0x2a;
if (reg_hkspi_pll_bypass != 0x1) // size = 1
reg_debug_1 = 0x2b;
if (reg_hkspi_irq != old_reg_hkspi_irq) // RO
reg_debug_1 = 0x2c;
if (reg_hkspi_trap != old_reg_hkspi_trap) // RO
reg_debug_1 =0x2d;
if (reg_hkspi_pll_trim != 0x3FFFFFF) // size 26
reg_debug_1 = 0x2f;
if (reg_hkspi_pll_source != 0x3F) // size 6 bits 0-2 = phase 0 divider, bits 3-5 = phase 90 divider
reg_debug_1 =0x2f;
if (reg_hkspi_pll_divider != 0x1F) // size 7 -> PLL output divider, PLL output divider2 , PLL feedback divider
reg_debug_1 =0x30;
if (reg_hkspi_disable != 0x1) // size 1
reg_debug_1 =0x31;
if (reg_clk_out_dest != 0x7) // trap and clocks redirect
reg_debug_1 =0x32;
// // write zeros to all registers
reg_mprj_io_0 = 0x0;
reg_mprj_io_1 = 0x0;
reg_mprj_io_2 = 0x0;
reg_mprj_io_3 = 0x0;
reg_mprj_io_4 = 0x0;
reg_mprj_io_5 = 0x0;
reg_mprj_io_6 = 0x0;
reg_mprj_io_7 = 0x0;
reg_mprj_io_8 = 0x0;
reg_mprj_io_9 = 0x0;
reg_mprj_io_10 = 0x0;
reg_mprj_io_11 = 0x0;
reg_mprj_io_12 = 0x0;
reg_mprj_io_13 = 0x0;
reg_mprj_io_14 = 0x0;
reg_mprj_io_15 = 0x0;
reg_mprj_io_16 = 0x0;
reg_mprj_io_17 = 0x0;
reg_mprj_io_18 = 0x0;
reg_mprj_io_19 = 0x0;
reg_mprj_io_20 = 0x0;
reg_mprj_io_21 = 0x0;
reg_mprj_io_22 = 0x0;
reg_mprj_io_23 = 0x0;
reg_mprj_io_24 = 0x0;
reg_mprj_io_25 = 0x0;
reg_mprj_io_26 = 0x0;
reg_mprj_io_27 = 0x0;
reg_mprj_io_28 = 0x0;
reg_mprj_io_29 = 0x0;
reg_mprj_io_30 = 0x0;
reg_mprj_io_31 = 0x0;
reg_mprj_io_32 = 0x0;
reg_mprj_io_33 = 0x0;
reg_mprj_io_34 = 0x0;
reg_mprj_io_35 = 0x0;
reg_mprj_io_36 = 0x0;
reg_mprj_io_37 = 0x0;
// house keeping
reg_hkspi_status = 0x0;
reg_hkspi_chip_id = 0x0;
reg_hkspi_user_id = 0x0;
reg_hkspi_pll_ena = 0x0;
reg_hkspi_pll_bypass = 0x0;
reg_hkspi_irq = 0x0;
reg_hkspi_reset = 0x0;
reg_hkspi_trap = 0x0;
reg_hkspi_pll_trim = 0x0;
reg_hkspi_pll_source = 0x0;
reg_hkspi_pll_divider = 0x0;
// sys
reg_clk_out_dest = 0x0;
reg_hkspi_disable = 0x0;
// // read zeros that has been written
if (reg_mprj_io_0 != 0x0)
reg_debug_2 =0x1;
if (reg_mprj_io_1 != 0x0)
reg_debug_2 =0x2;
if (reg_mprj_io_2 != 0x0)
reg_debug_2 =0x3;
if (reg_mprj_io_3 != 0x0)
reg_debug_2 =0x4;
if (reg_mprj_io_4 != 0x0)
reg_debug_2 =0x5;
if (reg_mprj_io_5 != 0x0)
reg_debug_2 =0x6;
if (reg_mprj_io_6 != 0x0)
reg_debug_2 =0x7;
if (reg_mprj_io_7 != 0x0)
reg_debug_2 =0x8;
if (reg_mprj_io_8 != 0x0)
reg_debug_2 =0x9;
if (reg_mprj_io_9 != 0x0)
reg_debug_2 =0xa;
if (reg_mprj_io_10 != 0x0)
reg_debug_2 =0xb;
if (reg_mprj_io_11 != 0x0)
reg_debug_2 =0xc;
if (reg_mprj_io_12 != 0x0)
reg_debug_2 =0xd;
if (reg_mprj_io_13 != 0x0)
reg_debug_2 =0xe;
if (reg_mprj_io_14 != 0x0)
reg_debug_2 =0xf;
if (reg_mprj_io_15 != 0x0)
reg_debug_2 =0x10;
if (reg_mprj_io_16 != 0x0)
reg_debug_2 =0x11;
if (reg_mprj_io_17 != 0x0)
reg_debug_2 =0x12;
if (reg_mprj_io_18 != 0x0)
reg_debug_2 =0x13;
if (reg_mprj_io_19 != 0x0)
reg_debug_2 =0x14;
if (reg_mprj_io_20 != 0x0)
reg_debug_2 =0x15;
if (reg_mprj_io_21 != 0x0)
reg_debug_2 =0x16;
if (reg_mprj_io_22 != 0x0)
reg_debug_2 =0x17;
if (reg_mprj_io_23 != 0x0)
reg_debug_2 =0x18;
if (reg_mprj_io_24 != 0x0)
reg_debug_2 =0x19;
if (reg_mprj_io_25 != 0x0)
reg_debug_2 =0x1a;
if (reg_mprj_io_26 != 0x0)
reg_debug_2 =0x1b;
if (reg_mprj_io_27 != 0x0)
reg_debug_2 =0x1c;
if (reg_mprj_io_28 != 0x0)
reg_debug_2 =0x1d;
if (reg_mprj_io_29 != 0x0)
reg_debug_2 =0x1e;
if (reg_mprj_io_30 != 0x0)
reg_debug_2 =0x1f;
if (reg_mprj_io_31 != 0x0)
reg_debug_2 =0x20;
if (reg_mprj_io_32 != 0x0)
reg_debug_2 =0x21;
if (reg_mprj_io_33 != 0x0)
reg_debug_2 =0x22;
if (reg_mprj_io_34 != 0x0)
reg_debug_2 =0x23;
if (reg_mprj_io_35 != 0x0)
reg_debug_2 =0x24;
if (reg_mprj_io_36 != 0x0)
reg_debug_2 =0x25;
if (reg_mprj_io_37 != 0x0)
reg_debug_2 =0x26;
// housekeeping
if (reg_hkspi_status != old_reg_hkspi_status) // RO
reg_debug_2 =0x27;
if (reg_hkspi_chip_id != old_reg_hkspi_chip_id) // RO
reg_debug_2 =0x28;
if (reg_hkspi_user_id != old_reg_hkspi_user_id) // RO
reg_debug_2 =0x29;
if (reg_hkspi_pll_ena != 0x0) // size =2
reg_debug_2 =0x2a;
if (reg_hkspi_pll_bypass != 0x0) // size = 1
reg_debug_2 = 0x2b;
if (reg_hkspi_irq != old_reg_hkspi_irq) // RO
reg_debug_2 = 0x2c;
if (reg_hkspi_trap != old_reg_hkspi_trap) // RO
reg_debug_2 =0x2d;
if (reg_hkspi_pll_trim != 0x0) // size 26
reg_debug_2 = 0x2f;
if (reg_hkspi_pll_source != 0x0) // size 6 bits 0-2 = phase 0 divider, bits 3-5 = phase 90 divider
reg_debug_2 =0x2f;
if (reg_hkspi_pll_divider != 0x0) // size 7 -> PLL output divider, PLL output divider2 , PLL feedback divider
reg_debug_2 =0x30;
if (reg_hkspi_disable != 0x0) // size 1
reg_debug_2 =0x31;
if (reg_clk_out_dest != 0x0) // trap and clocks redirect
reg_debug_2 =0x32;
reg_debug_2 = 0xFF;
}

View File

@ -1,213 +0,0 @@
from json.encoder import INFINITY
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
import json
reg = Regs()
'''randomly write then read housekeeping regs through wishbone'''
@cocotb.test()
@repot_test
async def hk_regs_wr_wb(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=611,num_error=INFINITY)
cpu = RiskV(dut)
cpu.cpu_force_reset()
with open('wb_models/housekeepingWB/HK_regs.json') as f:
regs = json.load(f)
await ClockCycles(caravelEnv.clk, 10)
# write then read
for i in range(random.randint(7, 20)):
bits_num = 32
mem = random.choice(['GPIO']) # can't access 'SPI' and 'sys' register from interfaces.cpu / read or write
key = random.choice(list(regs[mem].keys()))
if key == 'base_addr':
continue
key_num = int(key,16) & 0xFC
key = generate_key_from_num(key_num)
address = (int(key,16) + regs[mem]['base_addr'][1])
if address in [0x26000010,0x2600000c]: # skip testing reg_mprj_datal and reg_mprj_datah because when reading them it's getting the gpio input value
continue
data_in = random.getrandbits(bits_num)
cocotb.log.info(f"[TEST] Writing {bin(data_in)} to {regs[mem][key][0][0]} address {hex(address)} through wishbone")
await cpu.drive_data2address(address,data_in)
#calculate the expected value for each bit
data_exp = ''
keys = [generate_key_from_num(key_num+3),generate_key_from_num(key_num+2),generate_key_from_num(key_num+1),generate_key_from_num(key_num)]
for count , k in enumerate(keys):
for i in range(int(bits_num/len(keys)) * (count),int(bits_num/len(keys)) * (count+1)):
bit_exist = False
if k in regs[mem].keys():
for field in regs[mem][k]:
field_shift = field[2]
field_size = field[3]
field_access = field[4]
i_temp = (bits_num -1 -i) % (bits_num/4)
if field_shift <= i_temp and i_temp <= (field_shift + field_size-1):
if field_access == "RW":
data_exp += bin(data_in)[2:].zfill(bits_num)[i]
bit_exist = True
break
if not bit_exist:
data_exp += '0'
await ClockCycles(caravelEnv.clk,10)
cocotb.log.info(f"[TEST] expected data calculated = {data_exp}")
data_out = await cpu.read_address(address)
cocotb.log.info(f"[TEST] Read {bin(data_out)} from {regs[mem][key][0][0]} address {hex(address)} through wishbone")
if data_out != int(data_exp,2): cocotb.log.error(f"[TEST] wrong read from {regs[mem][key][0][0]} address {hex(address)} retuned val= {bin(data_out)[2:].zfill(bits_num)} expected = {data_exp}")
else: cocotb.log.info(f"[TEST] read the right value {hex(data_out)} from {regs[mem][key][0][0]} address {hex(address)} ")
'''randomly write then read housekeeping regs through wishbone'''
@cocotb.test()
@repot_test
async def hk_regs_wr_wb_cpu(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=182983,num_error=INFINITY)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
reg1 =0 # buffer
reg2 =0
regs_list = ("reg_hkspi_status","reg_hkspi_chip_id","reg_hkspi_user_id", "reg_hkspi_pll_ena","reg_hkspi_pll_bypass","reg_hkspi_irq","reg_hkspi_trap","reg_hkspi_pll_trim","reg_hkspi_pll_source","reg_hkspi_pll_divide","reg_clk_out_des","reg_hkspi_disable")
while True:
if cpu.read_debug_reg2() == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 < 38:
cocotb.log.error(f"[TEST] error while writing 0xFFFFFFFF to reg_mprj_io_{reg1-1}")
else:
cocotb.log.error(f"[TEST] error while writing 0xFFFFFFFF to {regs_list[reg1-39]}")
if reg2 != cpu.read_debug_reg2():
reg2 = cpu.read_debug_reg2()
if reg1 < 38:
cocotb.log.error(f"[TEST] error while writing 0x0 to reg_mprj_io_{reg2-1}")
else:
cocotb.log.error(f"[TEST] error while writing 0x0 to {regs_list[reg1-39]}")
await ClockCycles(caravelEnv.clk,1)
'''randomly write then read housekeeping regs through SPI'''
@cocotb.test()
@repot_test
async def hk_regs_wr_spi(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1851,num_error=INFINITY)
with open('wb_models/housekeepingWB/HK_regs.json') as f:
regs = json.load(f)
# write then read single byte
for i in range(random.randint(10, 40)):
bits_num = 8 # byte testing
mem = random.choice(['GPIO','SPI','sys'])
key = random.choice(list(regs[mem].keys()))
if key == 'base_addr':
continue
address = regs[mem][key][0][7]
if address in [111,36,10]: # 111 is for Housekeeping SPI disable, writing 1 to this address will disable the SPI and 36 is for mprj_io[03] changing bit 3 of this register would disable the spi by deassert spi_is_enabled and 10 0xa cpu irq is self resetting
continue
# address = int(key,16)
if address in [0x69,0x6A,0x6B,0x6C,0x6D,0x13]: # skip testing reg_mprj_datal and reg_mprj_datah because when reading them it's getting the gpio input value and xfer
continue
data_in = random.getrandbits(bits_num)
cocotb.log.info(f"[TEST] Writing {bin(data_in)} to reg [{regs[mem][key][0][0]}] address {hex(address)} through SPI")
await write_reg_spi(caravelEnv,address=address,data=data_in)
#calculate the expected value for each bit
is_unknown = False
data_exp = ''
for i in range(bits_num):
bit_exist = False
for field in regs[mem][key]:
field_shift = field[2]
field_size = field[3]
field_access = field[4]
reset_val = field[5]
i_temp = bits_num -1 -i
if field_shift <= i_temp and i_temp <= (field_shift + field_size-1):
if field_access == "RW":
data_exp += bin(data_in)[2:].zfill(bits_num)[i]
bit_exist = True
break
else : # read only get the value from reset
data_exp += bin(reset_val)[2:].zfill(bits_num)[i]
bit_exist = True
break
if field_access == "NA": # that mean the value is unknown as the register value can change by hardware mostly the reg value is input to the housekeeping from other blocks
is_unknown = True
break
if not bit_exist:
data_exp += '0'
if is_unknown:# that mean the value is unknown as the register value can change by hardware mostly the reg value is input to the housekeeping from other blocks
continue
await ClockCycles(caravelEnv.clk,10)
cocotb.log.info(f"[TEST] expected data calculated = {data_exp}")
data_out = await read_reg_spi(caravelEnv,address=address)
cocotb.log.info(f"[TEST] Read {bin(data_out)} from [{regs[mem][key][0][0]}] address {hex(address)} through SPI")
if data_out != int(data_exp,2): cocotb.log.error(f"[TEST] wrong read from [{regs[mem][key][0][0]}] address {hex(address)} retuned val= {bin(data_out)[2:].zfill(bits_num)} expected = {data_exp}")
else: cocotb.log.info(f"[TEST] read the right value {hex(data_out)} from [{regs[mem][key][0][0]}] address {address} ")
'''check reset value of house keeping register'''
@cocotb.test()
@repot_test
async def hk_regs_rst_spi(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=2879,num_error=INFINITY)
with open('wb_models/housekeepingWB/HK_regs.json') as f:
regs = json.load(f)
# read
bits_num = 8 # byte testing
mems = ['GPIO','SPI','sys']
for mem in mems:
keys = [k for k in regs[mem].keys()]
for key in keys:
if key == 'base_addr':
continue
address = regs[mem][key][0][7]
if address in [0x69,0x6A,0x6B,0x6C,0x6D,0x1A]: # skip testing reg_mprj_datal, reg_mprj_datah and usr2_vdd_pwrgood because when reading them it's getting the gpio input value
continue
#calculate the expected value for each bit for reset value
data_exp = ''
# for i in range(bits_num):
bit_exist = False
for field in regs[mem][key]:
field_shift = field[2]
field_size = field[3]
field_access = field[4]
reset_val = field[5]
i_temp = bits_num -1 #-i
# if field_shift <= i_temp and i_temp <= (field_shift + field_size-1):
data_exp = bin(reset_val)[2:].zfill(field_size) + data_exp
print (f'reset = {bin(reset_val)[2:].zfill(bits_num)} data exp = {data_exp} i temp = {i_temp} shift {field_shift} size {field_size}')
# bit_exist = True
# break
# if not bit_exist:
# data_exp += '0'
cocotb.log.info(f"[TEST] expected reset value for [{regs[mem][key][0][0]}] is {data_exp}")
data_out = await read_reg_spi(caravelEnv,address=address)
cocotb.log.info(f"[TEST] Read {bin(data_out)} from [{regs[mem][key][0][0]}] address {hex(address)} through wishbone")
if data_out != int(data_exp,2): cocotb.log.error(f"[TEST] wrong reset value read from [{regs[mem][key][0][0]}] address {address} retuned val= {bin(data_out)[2:].zfill(bits_num)} expected = {data_exp}")
else: cocotb.log.info(f"[TEST] read the right reset value {hex(data_out)} from [{regs[mem][key][0][0]}] address {address} ")
def generate_key_from_num(num):
hex_string = hex(num)
hex_list = [i for i in hex_string]
if len(hex_list)==3:
hex_list.insert(2,'0')
hex_string = "".join(hex_list)
return hex_string

View File

@ -1,42 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.spi_master.SPI_VIP import read_mem ,SPI_VIP
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
bit_time_ns = 0
reg = Regs()
@cocotb.test()
@repot_test
async def spi_rd_wr_nbyte(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=14833)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info (f"[TEST] start spi_rd_wr_nbyte test")
nbytes_limits= 8
# writing to the random number(1 to 8) of bits after 0x1E (gpio_configure[4]) address avoid changing gpio 3
for j in range(3):
address = random.randint(0x26 , 0x67-nbytes_limits)
n_bytes = random.randint(1,nbytes_limits)
await write_reg_spi_nbytes(caravelEnv,address,[0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F],nbytes_limits)
await write_reg_spi_nbytes(caravelEnv,address,[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0],n_bytes)
data = await read_reg_spi_nbytes(caravelEnv,address,nbytes_limits)
for i in range(nbytes_limits):
if i >= n_bytes:
if data[i] != 0x1F:
cocotb.log.error(f"[TEST] register {i} has returned value {data[i]} while it should return value 0x1F n_bytes = {n_bytes}")
else: cocotb.log.info(f"[TEST] successful read 0 from register {i} n_bytes = {n_bytes}")
else:
if data[i] != 0:
cocotb.log.error(f"[TEST] register number {i} has returned value {data[i]} > 0 while it should return value == 0 n_bytes = {n_bytes}")
else: cocotb.log.info(f"[TEST] successful read {data[i]} from register {i} n_bytes = {n_bytes}")
await ClockCycles(caravelEnv.clk,200)

View File

@ -1,58 +0,0 @@
async def write_reg_spi(caravelEnv,address,data):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(address) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(data) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
async def read_reg_spi(caravelEnv,address):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x40) # read stream command
await caravelEnv.hk_write_byte(address) # Address
data = await caravelEnv.hk_read_byte() # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
return data
async def write_reg_spi_nbytes(caravelEnv,address,data,n_bytes):
write_command = 0x2 << 6 | n_bytes << 3
print(f"command = {hex(write_command)}")
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(write_command) # Write n byte command
await caravelEnv.hk_write_byte(address) # Address (register 19 = GPIO bit-bang control)
for byte in data:
await caravelEnv.hk_write_byte(byte) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
async def read_reg_spi_nbytes(caravelEnv,address,n_bytes):
data =[]
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x40) # read stream command
await caravelEnv.hk_write_byte(address) # Address
for i in range(n_bytes):
data.append(await caravelEnv.hk_read_byte()) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
return data
async def reg_spi_user_pass_thru(caravelEnv,command,address):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0xc2) # Apply user pass-thru command to housekeeping SPI
await caravelEnv.hk_write_byte(command) # read command
address = address.to_bytes(3,'big')
await caravelEnv.hk_write_byte(address[0]) # high byte
await caravelEnv.hk_write_byte(address[1]) # middle byte
await caravelEnv.hk_write_byte(address[2]) # low byte
async def reg_spi_user_pass_thru_read(caravelEnv):
data = await caravelEnv.hk_read_byte()
return data
# use for configure in mgmt pass thru or user pass thru
async def reg_spi_op(caravelEnv,command,address):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(command) # command
await caravelEnv.hk_write_byte(address) # Address
await caravelEnv.disable_csb()

View File

@ -1,10 +0,0 @@
#include <defs.h>
#include <stub.c>
// Empty C code
void main()
{
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
return;
}

View File

@ -1,3 +0,0 @@
@00000000
6F 00 00 0B 93 01 00 00 13 02 63 57 b5 00 23 20
13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00

View File

@ -1,50 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.spi_master.SPI_VIP import read_mem ,SPI_VIP
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
bit_time_ns = 0
reg = Regs()
@cocotb.test()
@repot_test
async def user_pass_thru_rd(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=13771)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info (f"[TEST] start spi_master_rd test")
file_name = f"{os.getenv('CARAVEL_VERILOG_PATH')}/dv/cocotb/tests/housekeeping/housekeeping_spi/test_data"
mem = read_mem(file_name)
await cocotb.start(SPI_VIP(dut.bin8_monitor,dut.bin9_monitor,dut.bin10_monitor,(dut.bin11_en,dut.bin11),mem)) # fork for SPI
await wait_reg1(cpu,caravelEnv,0XAA)
cocotb.log.info (f"[TEST] Configuration finished")
#The SPI flash may need to be reset
# 0xff and 0xAB commands are suppose to have functionality in the future but for now they would do nothing
await write_reg_spi(caravelEnv,0xc2,0xff) # 0xc2 is for appling user pass-thru command to housekeeping SPI
await write_reg_spi(caravelEnv,0xc2,0xab) # 0xc2 is for appling user pass-thru command to housekeeping SPI
# start reading from memory
address = 0x0
await reg_spi_user_pass_thru(caravelEnv,command = 0x3,address=address) # read command
for i in range(8):
val = await reg_spi_user_pass_thru_read(caravelEnv)
if val != mem[address]:
cocotb.log.error(f"[TEST] reading incorrect value from address {hex(address)} expected = {hex(mem[address])} returened = {val}")
else:
cocotb.log.info(f"[TEST] reading correct value {hex(val)} from address {hex(address)} ")
address +=1
await caravelEnv.disable_csb()
# Wait for processor to restart
await wait_reg1(cpu,caravelEnv,0xBB)
cocotb.log.info(f"[TEST] processor has restarted successfully")

View File

@ -1,62 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <stub.c>
void main()
{
// This program is just to keep the processor busy while the
// housekeeping SPI is being accessed. to show that the
// processor is halted while the SPI is accessing the
// flash SPI in pass-through mode.
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// Management needs to apply output on these pads to access the user area SPI flash
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // SDI
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT; // SDO
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT; // clk
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT; // csb
// Apply configuration
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
// Start test
reg_debug_1 = 0xAA;
reg_debug_1 = 0xBB;
reg_uart_enable = 1;
// Test in progress
reg_mprj_datal = 0xa5000000;
// Test message
// print("Test message\n");
print("ABC\n");
for (int i=0; i<1200; i++);
// End test
reg_debug_1 = 0xFF;
}

View File

@ -1,103 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <csr.h>
#include <soc.h>
#include <irq_vex.h>
#include <uart.h>
#include <defs.h>
/*
Testing timer interrupts
Enable interrupt for IRQ external pin mprj_io[7] -> should be drived to 1 by the environment
**NOTE** housekeeping SPI should used to update register irq_1_inputsrc to 1 see verilog code
@wait for environment to make mprj[7] high
send packet size = 1
@received interrupt correctly test pass
send packet size = 5
@ timeout test fail
send packet size = 9
@ end test
send packet size = 3
send packet size = 3
send packet size = 3
*/
extern uint16_t flag;
void main(){
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// setting bit 7 as input
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
// automatic bitbang approach
if(1){
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
}
irq_setmask(0);
irq_setie(1);
irq_setmask(irq_getmask() | (1 << USER_IRQ_4_INTERRUPT));
reg_user4_irq_en =1;
// test interrrupt happen when mprj[7] is asserted
reg_debug_2 = 0xAA; //wait for environment to make mprj[7] high
flag = 0;
// Loop, waiting for the interrupt to change reg_mprj_datah
bool is_pass = false;
int timeout = 40;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x1B; //test pass irq sent at mprj 7
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x1E; // timeout
}
// test interrupt doesn't happened when mprj[7] is deasserted
reg_debug_2 = 0xBB;
flag = 0;
// Loop, waiting for the interrupt to change reg_mprj_datah
is_pass = false;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x2E; //test fail interrupt isn't suppose to happened
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x2B; // test pass
}
// test finish
reg_debug_2 = 0xFF;
}

View File

@ -1,69 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from tests.housekeeping.housekeeping_spi.spi_access_functions import *
reg = Regs()
"""Testbench of GPIO configuration through bit-bang method using the StriVe housekeeping SPI."""
@cocotb.test()
@repot_test
async def IRQ_external(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=155225)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start IRQ_external test")
pass_list = (0x1B,0x2B)
fail_list = (0x1E,0x2E)
phases_fails = 2
phases_passes = 0
reg1 =0 # buffer
reg2 = 0 #buffer
while True:
if reg2 != cpu.read_debug_reg2():
reg2 = cpu.read_debug_reg2()
if reg2 == 0xFF: # test finish
break
if reg2 == 0xAA: # assert mprj 7
await write_reg_spi(caravelEnv,0x1c,1)
cocotb.log.info(f"irq 1 = {dut.uut.housekeeping.irq_1_inputsrc.value}")
caravelEnv.drive_gpio_in((7,7),0)
await ClockCycles(caravelEnv.clk,10)
caravelEnv.drive_gpio_in((7,7),1)
if reg2 == 0xBB: # deassert mprj 7
caravelEnv.drive_gpio_in((7,7),0)
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
phases_passes +=1
phases_fails -=1
if reg1 == 0x1B:
cocotb.log.info(f"[TEST] Pass interrupt is detected when mprj 7 asserted")
elif reg1 == 0x2B:
cocotb.log.info(f"[TEST] Pass interrupt isn't detected when mprj 7 deasserted")
elif reg1 in fail_list: # pass phase
if reg1 == 0x1E:
cocotb.log.error(f"[TEST] Failed interrupt isn't detected when mprj 7 asserted")
elif reg1 == 0x2E:
cocotb.log.error(f"[TEST] Failed interrupt is detected when mprj 7 deasserted")
else:
cocotb.log.error(f"[TEST] debug register 1 has illegal value")
await ClockCycles(caravelEnv.clk,10)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")

View File

@ -1,88 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <csr.h>
#include <soc.h>
#include <irq_vex.h>
#include <uart.h>
#include <defs.h>
extern uint16_t flag;
void main(){
uint16_t data;
int i;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
irq_setmask(0);
irq_setie(1);
irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT));
reg_debug_2 = 0xAA; //wait for timer to send irq
flag = 0;
/* Configure timer for a single-shot countdown */
reg_timer0_config = 0;
reg_timer0_data = 30;
reg_timer0_irq_en = 1;
reg_timer0_config = 1;
// Loop, waiting for the interrupt to change reg_mprj_datah
bool is_pass = false;
int timeout = 40;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x1B; //test pass irq sent at timer0
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x1E; // timeout
}
flag = 0;
// test interrupt doesn't happened when timer isnt used
reg_debug_2 = 0xBB;
reg_timer0_config = 0; // disable counter
flag = 0;
// Loop, waiting for the interrupt to change reg_mprj_datah
is_pass = false;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x2E; //test fail interrupt isn't suppose to happened
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x2B; // test pass
}
// test finish
reg_debug_2 = 0xFF;
}

View File

@ -1,51 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
reg = Regs()
"""Testbench of GPIO configuration through bit-bang method using the StriVe housekeeping SPI."""
@cocotb.test()
@repot_test
async def IRQ_timer(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=152854)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start IRQ_timer test")
pass_list = (0x1B,0x2B)
fail_list = (0x1E,0x2E)
phases_fails = 2
phases_passes = 0
reg1 =0 # buffer
while True:
if cpu.read_debug_reg2() == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
phases_passes +=1
phases_fails -=1
if reg1 == 0x1B:
cocotb.log.info(f"[TEST] Pass interrupt is detected when timer is used")
elif reg1 == 0x2B:
cocotb.log.info(f"[TEST] Pass interrupt isn't detected when timer isnt used")
elif reg1 in fail_list: # pass phase
if reg1 == 0x1E:
cocotb.log.info(f"[TEST] Failed interrupt isn't detected when timer is used")
elif reg1 == 0x2E:
cocotb.log.error(f"[TEST] Failed interrupt is detected when timer isnt used")
else:
cocotb.log.error(f"[TEST] debug register 1 has illegal value")
await ClockCycles(caravelEnv.clk,10)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")

View File

@ -1,88 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <csr.h>
#include <soc.h>
#include <irq_vex.h>
#include <uart.h>
#include <stub.c>
extern uint16_t flag;
void main(){
flag = 0;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT;
reg_mprj_io_5 = 0x1803;
if(1){
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
}
reg_uart_enable = 1;
reg_uart_irq_en =1;
irq_setmask(0);
irq_setie(1);
irq_setmask(irq_getmask() | (1 << UART_INTERRUPT));
reg_debug_2 = 0xAA; //start sending data through the uart
print("M");
// Loop, waiting for the interrupt to change reg_mprj_datah
bool is_pass = false;
int timeout = 100;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x1B; //test pass irq sent
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x1E; // timeout
}
// test interrupt doesn't happened nothing sent at uart
reg_debug_2 = 0xBB;
flag = 0;
// Loop, waiting for the interrupt to change reg_mprj_datah
is_pass = false;
for (int i = 0; i < timeout; i++){
if (flag == 1){
reg_debug_1 = 0x2E; //test fail interrupt isn't suppose to happened
is_pass = true;
break;
}
}
if (!is_pass){
reg_debug_1 = 0x2B; // test pass
}
// test finish
reg_debug_2 = 0xFF;
}

View File

@ -1,64 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
async def write_reg_spi(caravelEnv,address,data):
await caravelEnv.enable_csb()
await caravelEnv.hk_write_byte(0x80) # Write stream command
await caravelEnv.hk_write_byte(address) # Address (register 19 = GPIO bit-bang control)
await caravelEnv.hk_write_byte(data) # Data = 0x01 (enable bit-bang mode)
await caravelEnv.disable_csb()
reg = Regs()
"""Testbench of GPIO configuration through bit-bang method using the StriVe housekeeping SPI."""
@cocotb.test()
@repot_test
async def IRQ_uart(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=318039)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start IRQ_uart test")
pass_list = (0x1B,0x2B)
fail_list = (0x1E,0x2E)
phases_fails = 2
phases_passes = 0
reg1 =0 # buffer
reg2 = 0 #buffer
while True:
if reg2 != cpu.read_debug_reg2():
reg2 = cpu.read_debug_reg2()
if reg2 == 0xFF: # test finish
break
if reg2 == 0xAA:
cocotb.log.info(f"[TEST] start sending through uart")
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
phases_passes +=1
phases_fails -=1
if reg1 == 0x1B:
cocotb.log.info(f"[TEST] Pass interrupt is detected when uart is sending data")
elif reg1 == 0x2B:
cocotb.log.info(f"[TEST] Pass interrupt isn't detected when uart isnt sending data")
elif reg1 in fail_list: # pass phase
if reg1 == 0x1E:
cocotb.log.info(f"[TEST] Failed interrupt isn't detected uart is sending data")
elif reg1 == 0x2E:
cocotb.log.error(f"[TEST] Failed interrupt is detected uart isnt sending data")
else:
cocotb.log.error(f"[TEST] debug register 1 has illegal value")
await ClockCycles(caravelEnv.clk,10)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")

View File

@ -1,16 +0,0 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

View File

@ -1,112 +0,0 @@
#include <defs.h>
#include <stub.c>
void main(){
unsigned int i, j, k;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_hkspi_disable = 1;
// Configure LA probes [63:32] and [127:96] as inputs to the cpu
// Configure LA probes [31:0] and [63:32] as outputs from the cpu
reg_la0_oenb = reg_la0_iena = 0xFFFFFFFF; // [31:0]
reg_la1_oenb = reg_la1_iena = 0x00000000; // [63:32]
reg_la2_oenb = reg_la2_iena = 0xFFFFFFFF; // [95:64]
reg_la3_oenb = reg_la3_iena = 0x00000000; // [127:96]
reg_la0_data = 0xAAAAAAAA;
reg_la2_data = 0xAAAAAAAA;
reg_debug_2 = reg_la1_data_in;
if (reg_la1_data_in != 0xAAAAAAAA)
reg_debug_1 = 0x1E;
else
reg_debug_1 = 0x1B;
reg_debug_2 = reg_la3_data_in;
if (reg_la3_data_in != 0xAAAAAAAA)
reg_debug_1 = 0x2E;
else
reg_debug_1 = 0x2B;
reg_la0_data = 0x55555555;
reg_la2_data = 0x55555555;
reg_debug_2 = reg_la1_data_in;
if (reg_la1_data_in != 0x55555555)
reg_debug_1 = 0x3E;
else
reg_debug_1 = 0x3B;
reg_debug_2 = reg_la3_data_in;
if (reg_la3_data_in != 0x55555555)
reg_debug_1 = 0x4E;
else
reg_debug_1 = 0x4B;
// Configure LA probes [31:0] and [63:32] as inputs to the cpu
// Configure LA probes [63:32] and [127:96] as outputs from the cpu
reg_la0_oenb = reg_la0_iena = 0x00000000; // [31:0]
reg_la1_oenb = reg_la1_iena = 0xFFFFFFFF; // [63:32]
reg_la2_oenb = reg_la2_iena = 0x00000000; // [95:64]
reg_la3_oenb = reg_la3_iena = 0xFFFFFFFF; // [127:96]
reg_la1_data = 0xAAAAAAAA;
reg_la3_data = 0xAAAAAAAA;
reg_debug_2 = reg_la0_data_in;
if (reg_la0_data_in != 0xAAAAAAAA)
reg_debug_1 = 0x5E;
else
reg_debug_1 = 0x5B;
reg_debug_2 = reg_la2_data_in;
if (reg_la2_data_in != 0xAAAAAAAA)
reg_debug_1 = 0x6E;
else
reg_debug_1 = 0x6B;
reg_la1_data = 0x55555555;
reg_la3_data = 0x55555555;
reg_debug_2 = reg_la0_data_in;
if (reg_la0_data_in != 0x55555555)
reg_debug_1 = 0x7E;
else
reg_debug_1 = 0x7B;
reg_debug_2 = reg_la2_data_in;
if (reg_la2_data_in != 0x55555555)
reg_debug_1 = 0x8E;
else
reg_debug_1 = 0x8B;
// Configure LA probes [31:0] and [63:32] as inputs to the cpu
// Configure LA probes [63:32] and [127:96] as disabled input and output
reg_la0_oenb = reg_la0_iena = 0x00000000; // [31:0]
reg_la1_oenb = reg_la1_iena = 0xFFFFFFFF; // [63:32]
reg_la2_oenb = reg_la2_iena = 0x00000000; // [95:64]
reg_la3_oenb = reg_la3_iena = 0xFFFFFFFF; // [127:96]
reg_la1_iena = reg_la3_iena = 0x00000000; // disable input for la1 and la3
reg_la1_data = 0xAAAAAAAA;
reg_la3_data = 0xAAAAAAAA;
reg_debug_2 = reg_la0_data_in;
if (reg_la0_data == 0xAAAAAAAA)
reg_debug_1 = 0x9E;
else
reg_debug_1 = 0x9B;
reg_debug_2 = reg_la2_data_in;
if (reg_la2_data == 0xAAAAAAAA)
reg_debug_1 = 0xaE;
else
reg_debug_1 = 0xaB;
reg_debug_2 = 0xFF;
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
}

View File

@ -1,48 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
from cocotb.binary import BinaryValue
reg = Regs()
@cocotb.test()
@repot_test
async def la(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=67415)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
pass_list = (0x1B,0x2B,0x3B,0x4B,0x5B,0x6B,0x7B,0x8B,0x9B,0xaB)
fail_list = (0x1E,0x2E,0x3E,0x4E,0x5E,0x6E,0x7E,0x8E,0x9E,0xaE)
phases_fails = 10
phases_passes = 0
reg1 =0 # buffer
while True:
if cpu.read_debug_reg2() == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
phases_passes +=1
phases_fails -=1
cocotb.log.info(f"[TEST] test passes phase {hex(reg1)[2]}")
elif reg1 in fail_list: # fail phase
cocotb.log.error(f"[TEST] test fails phase {hex(reg1)[2]} incorrect value recieved {hex(cpu.read_debug_reg2())}")
await ClockCycles(caravelEnv.clk,1)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
await ClockCycles(caravelEnv.clk, 10000)

View File

@ -1,33 +0,0 @@
#include <defs.h>
#define BYTE_SIZE 800
#define SHORT_SIZE BYTE_SIZE/2
#define INT_SIZE BYTE_SIZE/4
void main()
{
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
unsigned int *dff_start_address = (unsigned int *) 0x00000000;
unsigned int dff_size = 0x400/4;
for (unsigned int i = 0; i < dff_size; i++){
unsigned int data = (i + 7)*13;
*(dff_start_address+i) = data;
}
bool is_fail = false;
for (unsigned int i = 0; i < dff_size; i++){
unsigned int data = (i + 7)*13;
if (data != *(dff_start_address+i)){
reg_debug_2 = i;
reg_debug_1 = 0x1E;
is_fail = true;
break;
}
}
if (!is_fail)
reg_debug_1 = 0x1B;
}

View File

@ -1,33 +0,0 @@
#include <defs.h>
#define BYTE_SIZE 800
#define SHORT_SIZE BYTE_SIZE/2
#define INT_SIZE BYTE_SIZE/4
void main()
{
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
unsigned int *dff2_start_address = (unsigned int *) 0x00000400;
unsigned int dff2_size = 0x200 / 4;
for (unsigned int i = 0; i < dff2_size; i++){
unsigned int data = (i + 7)*13;
*(dff2_start_address+i) = data;
}
bool is_fail = false;
for (unsigned int i = 0; i < dff2_size; i++){
unsigned int data = (i + 7)*13;
if (data != *(dff2_start_address+i)){
reg_debug_2 = i;
reg_debug_1 = 0x1E;
is_fail = true;
break;
}
}
if (!is_fail)
reg_debug_1 = 0x1B;
}

View File

@ -1,60 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
reg = Regs()
@cocotb.test()
@repot_test
async def mem_dff2(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=1309819)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start mem stress test")
pass_list = [0x1B]
fail_list = [0x1E]
reg1 =0 # buffer
while True:
if cpu.read_debug_reg1() == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
cocotb.log.info(f"[TEST] pass writing and reading all dff2 memory ")
break
elif reg1 in fail_list: # pass phase
cocotb.log.error(f"[TEST] failed access address {hex(0x00000400 + cpu.read_debug_reg2())}")
break
await ClockCycles(caravelEnv.clk,100)
@cocotb.test()
@repot_test
async def mem_dff(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=2096205)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start mem stress test")
pass_list = [0x1B]
fail_list = [0x1E]
reg1 =0 # buffer
while True:
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
if reg1 in pass_list: # pass phase
cocotb.log.info(f"[TEST] pass writing and reading all dff memory ")
break
elif reg1 in fail_list: # pass phase
cocotb.log.error(f"[TEST] failed access address {hex(0x00000400 + cpu.read_debug_reg2())}")
break
await ClockCycles(caravelEnv.clk,100)

View File

@ -1,166 +0,0 @@
import random
import re
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
from interfaces.caravel import GPIO_MODE
reg = Regs()
"""Testbench of GPIO configuration through bit-bang method using the StriVe housekeeping SPI."""
@cocotb.test()
@repot_test
async def mgmt_gpio_out(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=91385)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start mgmt_gpio_out test")
phases_fails = 3
phases_passes = 0
reg1 =0 # buffer
reg2 = 0 #buffer
while True:
if reg2 != cpu.read_debug_reg2():
reg2 = cpu.read_debug_reg2()
if reg2 == 0xFF: # test finish
break
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
cocotb.log.info(f"[TEST] waiting for {reg1} blinks")
for i in range(reg1):
while (True):
if caravelEnv.monitor_mgmt_gpio() == 0:
break
if reg1 != cpu.read_debug_reg1():
cocotb.log.error("[TEST] error failing to catch all blinking ")
return
await ClockCycles(caravelEnv.clk,10)
while (True):
if caravelEnv.monitor_mgmt_gpio() == 1:
break
if reg1 != cpu.read_debug_reg1():
cocotb.log.error("[TEST] error failing to catch all blinking ")
return
await ClockCycles(caravelEnv.clk,10)
cocotb.log.info("[TEST] passing sending {reg1} blinks ")
phases_fails -=1
phases_passes +=1
await ClockCycles(caravelEnv.clk,10)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
@cocotb.test()
@repot_test
async def mgmt_gpio_in(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=277033)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start mgmt_gpio_in test")
phases_fails = 3
phases_passes = 0
pass_list = (0x1B,0x2B,0xFF)
fail_list = tuple([0xEE])
reg1 =0 # buffer
reg2 = 0 #buffer
while True:
if reg2 != cpu.read_debug_reg2():
reg2 = cpu.read_debug_reg2()
if reg2 in pass_list:
cocotb.log.info (f"[TEST] reg2 = {reg2}")
phases_passes +=1
phases_fails -=1
if reg2 == 0xFF: # test finish
break
elif reg2 == 0x1B:
cocotb.log.info(f"[TEST] pass sending 10 blink ")
elif reg2 == 0x2B:
cocotb.log.info(f"[TEST] pass sending 20 blink ")
if reg2 in fail_list:
cocotb.log.error(f"[TEST] gpio change without sending anything")
if reg1 != cpu.read_debug_reg1():
reg1 = cpu.read_debug_reg1()
cocotb.log.info(f"[TEST] start sending {reg1} blinks")
for i in range(reg1):
caravelEnv.drive_mgmt_gpio(1)
await wait_reg2(cpu,caravelEnv,0XAA)
caravelEnv.drive_mgmt_gpio(0)
await wait_reg2(cpu,caravelEnv,0XBB)
cocotb.log.info(f"[TEST] finish sending {reg1} blinks ")
await ClockCycles(caravelEnv.clk,10)
if phases_fails != 0:
cocotb.log.error(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
else:
cocotb.log.info(f"[TEST] finish with {phases_passes} phases passes and {phases_fails} phases fails")
@cocotb.test()
@repot_test
async def mgmt_gpio_bidir(dut):
caravelEnv,clock = await test_configure(dut,timeout_cycles=194697)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info(f"[TEST] Start mgmt_gpio_bidir test")
phases_fails = 3
phases_passes = 0
pass_list = (0x1B,0x2B,0xFF)
fail_list = tuple([0xEE])
reg2 = 0 #buffer
await wait_reg1(cpu,caravelEnv,0XAA)
num_blinks = random.randint(1, 20)
cocotb.log.info (f"[TEST] start send {num_blinks} blinks")
for i in range(num_blinks):
if i == num_blinks-1: #last iteration
# await cpu.drive_data2address(reg.get_addr('reg_debug_1'),0xFF)
cpu.write_debug_reg1_backdoor(0xFF)
caravelEnv.drive_mgmt_gpio(1)
await ClockCycles(caravelEnv.clk,4000)
caravelEnv.drive_mgmt_gpio(0)
await ClockCycles(caravelEnv.clk,4000)
cocotb.log.info(f"[TEST] finish sending {num_blinks} blinks ")
cocotb.log.info(f"[TEST] waiting for {num_blinks} blinks ")
recieved_blinks = 0
while True:
cocotb.log.info(f"[TEST] here 0 ")
if cpu.read_debug_reg2() == 0xFF: #test finish
break
while (True):
if caravelEnv.monitor_mgmt_gpio() == 0:
break
if cpu.read_debug_reg2() == 0xFF: #test finish
break
cocotb.log.info(f"[TEST] here 1 ")
await ClockCycles(caravelEnv.clk,10)
while (True):
if caravelEnv.monitor_mgmt_gpio() == 1:
recieved_blinks +=1
break
if cpu.read_debug_reg2() == 0xFF: #test finish
break
cocotb.log.info(f"[TEST] here 2 ")
await ClockCycles(caravelEnv.clk,10)
await ClockCycles(caravelEnv.clk,1)
if recieved_blinks == num_blinks:
cocotb.log.info(f"[TEST] recieved the correct number of blinks {num_blinks}")
else:
cocotb.log.error(f"[TEST] recieved the incorrect number of blinks recieved = {recieved_blinks} expected = {num_blinks}")

View File

@ -1,63 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <stub.c>
// --------------------------------------------------------
/*
* Management SoC GPIO Pin Test
* Tests writing to the GPIO pin.
*/
void main()
{
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_gpio_mode1 = 1;
reg_gpio_mode0 = 0; // for full swing
reg_gpio_ien = 1;
reg_gpio_oe = 0;
int num_blinks = 0;
reg_debug_1 = 0xAA; // start of the test
int z = reg_debug_1;
while (true) {
// reg_debug_2 = z;
// z= reg_debug_1;
while(reg_gpio_in == 0);
while(reg_gpio_in == 1);
num_blinks++;
if (reg_debug_1 == 0xFF)
break;
}
reg_gpio_ien = 0;
reg_gpio_oe = 1;
for (int i = 0; i < num_blinks; i++) {
/* Fast blink for simulation */
reg_gpio_out = 1;
reg_gpio_out = 0;
}
reg_debug_2 = 0xFF; //finish test
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
}

View File

@ -1,67 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
// --------------------------------------------------------
/*
* Management SoC GPIO Pin Test
* Tests writing to the GPIO pin.
*/
void main()
{
int temp_in;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_gpio_mode1 = 1;
reg_gpio_mode0 = 0; // for full swing
reg_gpio_ien = 1;
reg_gpio_oe = 1;
reg_debug_1 = 10; // wait for 10 blinks
for (int i = 0; i < 10; i++) {
while(reg_gpio_in == 0);
reg_debug_2 = 0XAA; // 1 is recieved
while(reg_gpio_in == 1);
reg_debug_2 = 0XBB; // 0 is recieved
}
reg_debug_2 = 0x1B;
reg_debug_1 = 20;
for (int i = 0; i < 20; i++) {
while(reg_gpio_in == 0);
reg_debug_2 = 0XAA; // 1 is recieved
while(reg_gpio_in == 1);
reg_debug_2 = 0XBB; // 0 is recieved
}
reg_debug_2 = 0x2B;
temp_in = reg_gpio_in;
reg_debug_1 = 0;
for (int i =0; i<50;i++){ // timeout
if (temp_in != reg_gpio_in)
reg_debug_2 = 0xEE; //finish test
}
reg_debug_2 = 0xFF; //finish test
}

View File

@ -1,59 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
// --------------------------------------------------------
/*
* Management SoC GPIO Pin Test
* Tests writing to the GPIO pin.
*/
void main()
{
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
reg_gpio_mode1 = 1;
reg_gpio_mode0 = 0; // for full swing
reg_gpio_ien = 1;
reg_gpio_oe = 1;
reg_debug_1 = 10;
for (int i = 0; i < 10; i++) {
/* Fast blink for simulation */
reg_gpio_out = 1;
reg_gpio_out = 0;
}
reg_debug_1 = 20;
for (int i = 0; i < 20; i++) {
/* Fast blink for simulation */
reg_gpio_out = 1;
reg_gpio_out = 0;
}
reg_debug_1 = 0;
reg_debug_1 = 0; // for more delay
reg_debug_1 = 0;
reg_debug_2 = 0xFF; //finish test
}

View File

@ -1,389 +0,0 @@
# Begin_DVE_Session_Save_Info
# DVE full session
# Saved on Tue Oct 11 10:47:30 2022
# Designs open: 1
# V1: bitbang_spi_i.vpd
# Toplevel windows open: 2
# TopLevel.1
# TopLevel.2
# Source.1: caravel_top
# Wave.1: 19 signals
# Group count = 4
# Group Group1 signal count = 4
# Group Group2 signal count = 6
# Group Group3 signal count = 6
# Group Group4 signal count = 3
# End_DVE_Session_Save_Info
# DVE version: T-2022.06_Full64
# DVE build date: May 31 2022 20:53:03
#<Session mode="Full" path="/home/rady/caravel/caravel_redesign_cocotb_new/caravel/verilog/dv/cocotb/session.bitbang_spi_i.vpd.tcl" type="Debug">
gui_set_loading_session_type Post
gui_continuetime_set
# Close design
if { [gui_sim_state -check active] } {
gui_sim_terminate
}
gui_close_db -all
gui_expr_clear_all
# Close all windows
gui_close_window -type Console
gui_close_window -type Wave
gui_close_window -type Source
gui_close_window -type Schematic
gui_close_window -type Data
gui_close_window -type DriverLoad
gui_close_window -type List
gui_close_window -type Memory
gui_close_window -type HSPane
gui_close_window -type DLPane
gui_close_window -type Assertion
gui_close_window -type CovHier
gui_close_window -type CoverageTable
gui_close_window -type CoverageMap
gui_close_window -type CovDetail
gui_close_window -type Local
gui_close_window -type Stack
gui_close_window -type Watch
gui_close_window -type Group
gui_close_window -type Transaction
# Application preferences
gui_set_pref_value -key app_default_font -value {Helvetica,10,-1,5,50,0,0,0,0,0}
gui_src_preferences -tabstop 8 -maxbits 24 -windownumber 1
#<WindowLayout>
# DVE top-level session
# Create and position top-level window: TopLevel.1
if {![gui_exist_window -window TopLevel.1]} {
set TopLevel.1 [ gui_create_window -type TopLevel \
-icon $::env(DVE)/auxx/gui/images/toolbars/dvewin.xpm]
} else {
set TopLevel.1 TopLevel.1
}
gui_show_window -window ${TopLevel.1} -show_state maximized -rect {{0 29} {2559 1336}}
# ToolBar settings
gui_set_toolbar_attributes -toolbar {TimeOperations} -dock_state top
gui_set_toolbar_attributes -toolbar {TimeOperations} -offset 0
gui_show_toolbar -toolbar {TimeOperations}
gui_hide_toolbar -toolbar {&File}
gui_set_toolbar_attributes -toolbar {&Edit} -dock_state top
gui_set_toolbar_attributes -toolbar {&Edit} -offset 0
gui_show_toolbar -toolbar {&Edit}
gui_hide_toolbar -toolbar {CopyPaste}
gui_set_toolbar_attributes -toolbar {&Trace} -dock_state top
gui_set_toolbar_attributes -toolbar {&Trace} -offset 0
gui_show_toolbar -toolbar {&Trace}
gui_hide_toolbar -toolbar {TraceInstance}
gui_hide_toolbar -toolbar {BackTrace}
gui_set_toolbar_attributes -toolbar {&Scope} -dock_state top
gui_set_toolbar_attributes -toolbar {&Scope} -offset 0
gui_show_toolbar -toolbar {&Scope}
gui_set_toolbar_attributes -toolbar {&Window} -dock_state top
gui_set_toolbar_attributes -toolbar {&Window} -offset 0
gui_show_toolbar -toolbar {&Window}
gui_set_toolbar_attributes -toolbar {Signal} -dock_state top
gui_set_toolbar_attributes -toolbar {Signal} -offset 0
gui_show_toolbar -toolbar {Signal}
gui_set_toolbar_attributes -toolbar {Zoom} -dock_state top
gui_set_toolbar_attributes -toolbar {Zoom} -offset 0
gui_show_toolbar -toolbar {Zoom}
gui_set_toolbar_attributes -toolbar {Zoom And Pan History} -dock_state top
gui_set_toolbar_attributes -toolbar {Zoom And Pan History} -offset 0
gui_show_toolbar -toolbar {Zoom And Pan History}
gui_set_toolbar_attributes -toolbar {Grid} -dock_state top
gui_set_toolbar_attributes -toolbar {Grid} -offset 0
gui_show_toolbar -toolbar {Grid}
gui_hide_toolbar -toolbar {Simulator}
gui_hide_toolbar -toolbar {Interactive Rewind}
gui_hide_toolbar -toolbar {Testbench}
# End ToolBar settings
# Docked window settings
set HSPane.1 [gui_create_window -type HSPane -parent ${TopLevel.1} -dock_state left -dock_on_new_line true -dock_extent 343]
catch { set Hier.1 [gui_share_window -id ${HSPane.1} -type Hier] }
gui_set_window_pref_key -window ${HSPane.1} -key dock_width -value_type integer -value 343
gui_set_window_pref_key -window ${HSPane.1} -key dock_height -value_type integer -value -1
gui_set_window_pref_key -window ${HSPane.1} -key dock_offset -value_type integer -value 0
gui_update_layout -id ${HSPane.1} {{left 0} {top 0} {width 342} {height 773} {dock_state left} {dock_on_new_line true} {child_hier_colhier 298} {child_hier_coltype 100} {child_hier_colpd 0} {child_hier_col1 0} {child_hier_col2 1} {child_hier_col3 -1}}
set DLPane.1 [gui_create_window -type DLPane -parent ${TopLevel.1} -dock_state left -dock_on_new_line true -dock_extent 354]
catch { set Data.1 [gui_share_window -id ${DLPane.1} -type Data] }
gui_set_window_pref_key -window ${DLPane.1} -key dock_width -value_type integer -value 354
gui_set_window_pref_key -window ${DLPane.1} -key dock_height -value_type integer -value 772
gui_set_window_pref_key -window ${DLPane.1} -key dock_offset -value_type integer -value 0
gui_update_layout -id ${DLPane.1} {{left 0} {top 0} {width 353} {height 773} {dock_state left} {dock_on_new_line true} {child_data_colvariable 265} {child_data_colvalue 65} {child_data_coltype 64} {child_data_col1 0} {child_data_col2 1} {child_data_col3 2}}
set Console.1 [gui_create_window -type Console -parent ${TopLevel.1} -dock_state bottom -dock_on_new_line true -dock_extent 454]
gui_set_window_pref_key -window ${Console.1} -key dock_width -value_type integer -value 2500
gui_set_window_pref_key -window ${Console.1} -key dock_height -value_type integer -value 454
gui_set_window_pref_key -window ${Console.1} -key dock_offset -value_type integer -value 0
gui_update_layout -id ${Console.1} {{left 0} {top 0} {width 2559} {height 453} {dock_state bottom} {dock_on_new_line true}}
#### Start - Readjusting docked view's offset / size
set dockAreaList { top left right bottom }
foreach dockArea $dockAreaList {
set viewList [gui_ekki_get_window_ids -active_parent -dock_area $dockArea]
foreach view $viewList {
if {[lsearch -exact [gui_get_window_pref_keys -window $view] dock_width] != -1} {
set dockWidth [gui_get_window_pref_value -window $view -key dock_width]
set dockHeight [gui_get_window_pref_value -window $view -key dock_height]
set offset [gui_get_window_pref_value -window $view -key dock_offset]
if { [string equal "top" $dockArea] || [string equal "bottom" $dockArea]} {
gui_set_window_attributes -window $view -dock_offset $offset -width $dockWidth
} else {
gui_set_window_attributes -window $view -dock_offset $offset -height $dockHeight
}
}
}
}
#### End - Readjusting docked view's offset / size
gui_sync_global -id ${TopLevel.1} -option true
# MDI window settings
set Source.1 [gui_create_window -type {Source} -parent ${TopLevel.1}]
gui_show_window -window ${Source.1} -show_state maximized
gui_update_layout -id ${Source.1} {{show_state maximized} {dock_state undocked} {dock_on_new_line false}}
# End MDI window settings
# Create and position top-level window: TopLevel.2
if {![gui_exist_window -window TopLevel.2]} {
set TopLevel.2 [ gui_create_window -type TopLevel \
-icon $::env(DVE)/auxx/gui/images/toolbars/dvewin.xpm]
} else {
set TopLevel.2 TopLevel.2
}
gui_show_window -window ${TopLevel.2} -show_state maximized -rect {{0 29} {2559 1336}}
# ToolBar settings
gui_set_toolbar_attributes -toolbar {TimeOperations} -dock_state top
gui_set_toolbar_attributes -toolbar {TimeOperations} -offset 0
gui_show_toolbar -toolbar {TimeOperations}
gui_hide_toolbar -toolbar {&File}
gui_set_toolbar_attributes -toolbar {&Edit} -dock_state top
gui_set_toolbar_attributes -toolbar {&Edit} -offset 0
gui_show_toolbar -toolbar {&Edit}
gui_hide_toolbar -toolbar {CopyPaste}
gui_set_toolbar_attributes -toolbar {&Trace} -dock_state top
gui_set_toolbar_attributes -toolbar {&Trace} -offset 0
gui_show_toolbar -toolbar {&Trace}
gui_hide_toolbar -toolbar {TraceInstance}
gui_hide_toolbar -toolbar {BackTrace}
gui_set_toolbar_attributes -toolbar {&Scope} -dock_state top
gui_set_toolbar_attributes -toolbar {&Scope} -offset 0
gui_show_toolbar -toolbar {&Scope}
gui_set_toolbar_attributes -toolbar {&Window} -dock_state top
gui_set_toolbar_attributes -toolbar {&Window} -offset 0
gui_show_toolbar -toolbar {&Window}
gui_set_toolbar_attributes -toolbar {Signal} -dock_state top
gui_set_toolbar_attributes -toolbar {Signal} -offset 0
gui_show_toolbar -toolbar {Signal}
gui_set_toolbar_attributes -toolbar {Zoom} -dock_state top
gui_set_toolbar_attributes -toolbar {Zoom} -offset 0
gui_show_toolbar -toolbar {Zoom}
gui_set_toolbar_attributes -toolbar {Zoom And Pan History} -dock_state top
gui_set_toolbar_attributes -toolbar {Zoom And Pan History} -offset 0
gui_show_toolbar -toolbar {Zoom And Pan History}
gui_set_toolbar_attributes -toolbar {Grid} -dock_state top
gui_set_toolbar_attributes -toolbar {Grid} -offset 0
gui_show_toolbar -toolbar {Grid}
gui_hide_toolbar -toolbar {Simulator}
gui_hide_toolbar -toolbar {Interactive Rewind}
gui_set_toolbar_attributes -toolbar {Testbench} -dock_state top
gui_set_toolbar_attributes -toolbar {Testbench} -offset 0
gui_show_toolbar -toolbar {Testbench}
# End ToolBar settings
# Docked window settings
gui_sync_global -id ${TopLevel.2} -option true
# MDI window settings
set Wave.1 [gui_create_window -type {Wave} -parent ${TopLevel.2}]
gui_show_window -window ${Wave.1} -show_state maximized
gui_update_layout -id ${Wave.1} {{show_state maximized} {dock_state undocked} {dock_on_new_line false} {child_wave_left 743} {child_wave_right 1811} {child_wave_colname 369} {child_wave_colvalue 369} {child_wave_col1 0} {child_wave_col2 1}}
# End MDI window settings
gui_set_env TOPLEVELS::TARGET_FRAME(Source) ${TopLevel.1}
gui_set_env TOPLEVELS::TARGET_FRAME(Schematic) ${TopLevel.1}
gui_set_env TOPLEVELS::TARGET_FRAME(PathSchematic) ${TopLevel.1}
gui_set_env TOPLEVELS::TARGET_FRAME(Wave) none
gui_set_env TOPLEVELS::TARGET_FRAME(List) none
gui_set_env TOPLEVELS::TARGET_FRAME(Memory) ${TopLevel.1}
gui_set_env TOPLEVELS::TARGET_FRAME(DriverLoad) none
gui_update_statusbar_target_frame ${TopLevel.1}
gui_update_statusbar_target_frame ${TopLevel.2}
#</WindowLayout>
#<Database>
# DVE Open design session:
if { ![gui_is_db_opened -db {bitbang_spi_i.vpd}] } {
gui_open_db -design V1 -file bitbang_spi_i.vpd -to 8464250000 -nosource
}
gui_set_precision 1ps
gui_set_time_units 1ps
#</Database>
# DVE Global setting session:
# Global: Bus
# Global: Expressions
# Global: Signal Time Shift
# Global: Signal Compare
# Global: Signal Groups
set _session_group_1 Group1
gui_sg_create "$_session_group_1"
set Group1 "$_session_group_1"
gui_sg_addsignal -group "$_session_group_1" { {caravel_top.uut.gpio_control_bidir_1[0].serial_clock} {caravel_top.uut.gpio_control_bidir_1[0].serial_load} {caravel_top.uut.gpio_control_bidir_1[0].serial_data_in} {caravel_top.uut.gpio_control_bidir_1[0].shift_register} }
set _session_group_2 Group2
gui_sg_create "$_session_group_2"
set Group2 "$_session_group_2"
gui_sg_addsignal -group "$_session_group_2" { caravel_top.uut.housekeeping.serial_bb_clock caravel_top.uut.housekeeping.serial_bb_load caravel_top.uut.housekeeping.serial_bb_resetn caravel_top.uut.housekeeping.serial_bb_data_1 caravel_top.uut.housekeeping.serial_bb_data_2 caravel_top.uut.housekeeping.serial_bb_enable }
set _session_group_3 Group3
gui_sg_create "$_session_group_3"
set Group3 "$_session_group_3"
gui_sg_addsignal -group "$_session_group_3" { caravel_top.uut.housekeeping.hkspi.SCK caravel_top.uut.housekeeping.hkspi.SDI caravel_top.uut.housekeeping.hkspi.CSB caravel_top.uut.housekeeping.cdata caravel_top.uut.housekeeping.caddr caravel_top.uut.housekeeping.hkspi.wrstb }
set _session_group_4 Group4
gui_sg_create "$_session_group_4"
set Group4 "$_session_group_4"
gui_sg_addsignal -group "$_session_group_4" { caravel_top.uut.housekeeping.hkspi.SCK caravel_top.uut.housekeeping.csclk caravel_top.uut.housekeeping.wbbd_sck }
# Global: Highlighting
# Global: Stack
gui_change_stack_mode -mode list
# Post database loading setting...
# Restore C1 time
gui_set_time -C1_only 665850000
# Save global setting...
# Wave/List view global setting
gui_cov_show_value -switch false
# Close all empty TopLevel windows
foreach __top [gui_ekki_get_window_ids -type TopLevel] {
if { [llength [gui_ekki_get_window_ids -parent $__top]] == 0} {
gui_close_window -window $__top
}
}
gui_set_loading_session_type noSession
# DVE View/pane content session:
# Hier 'Hier.1'
gui_show_window -window ${Hier.1}
gui_list_set_filter -id ${Hier.1} -list { {Package 1} {All 0} {Process 1} {VirtPowSwitch 0} {UnnamedProcess 1} {UDP 0} {Function 1} {Block 1} {SrsnAndSpaCell 0} {OVA Unit 1} {LeafScCell 1} {LeafVlgCell 1} {Interface 1} {LeafVhdCell 1} {$unit 1} {NamedBlock 1} {Task 1} {VlgPackage 1} {ClassDef 1} {VirtIsoCell 0} }
gui_list_set_filter -id ${Hier.1} -text {*house*}
gui_hier_list_init -id ${Hier.1}
gui_change_design -id ${Hier.1} -design V1
catch {gui_list_expand -id ${Hier.1} caravel_top}
catch {gui_list_expand -id ${Hier.1} caravel_top.uut}
catch {gui_list_select -id ${Hier.1} {caravel_top.uut.housekeeping}}
gui_view_scroll -id ${Hier.1} -vertical -set 0
gui_view_scroll -id ${Hier.1} -horizontal -set 0
# Data 'Data.1'
gui_list_set_filter -id ${Data.1} -list { {Buffer 1} {Input 1} {Others 1} {Linkage 1} {Output 1} {LowPower 1} {Parameter 1} {All 1} {Aggregate 1} {LibBaseMember 1} {Event 1} {Assertion 1} {Constant 1} {Interface 1} {BaseMembers 1} {Signal 1} {$unit 1} {Inout 1} {Variable 1} }
gui_list_set_filter -id ${Data.1} -text {*wbbd_sck*}
gui_list_show_data -id ${Data.1} {caravel_top.uut.housekeeping}
gui_show_window -window ${Data.1}
catch { gui_list_select -id ${Data.1} {caravel_top.uut.housekeeping.wbbd_sck }}
gui_view_scroll -id ${Data.1} -vertical -set 0
gui_view_scroll -id ${Data.1} -horizontal -set 0
gui_view_scroll -id ${Hier.1} -vertical -set 0
gui_view_scroll -id ${Hier.1} -horizontal -set 0
# Source 'Source.1'
gui_src_value_annotate -id ${Source.1} -switch false
gui_set_env TOGGLE::VALUEANNOTATE 0
gui_open_source -id ${Source.1} -replace -active caravel_top /home/rady/caravel/caravel_redesign_cocotb_new/caravel/verilog/dv/cocotb/caravel_top.sv
gui_src_value_annotate -id ${Source.1} -switch true
gui_set_env TOGGLE::VALUEANNOTATE 1
gui_view_scroll -id ${Source.1} -vertical -set 160
gui_src_set_reusable -id ${Source.1}
# View 'Wave.1'
gui_wv_sync -id ${Wave.1} -switch false
set groupExD [gui_get_pref_value -category Wave -key exclusiveSG]
gui_set_pref_value -category Wave -key exclusiveSG -value {false}
set origWaveHeight [gui_get_pref_value -category Wave -key waveRowHeight]
gui_list_set_height -id Wave -height 25
set origGroupCreationState [gui_list_create_group_when_add -wave]
gui_list_create_group_when_add -wave -disable
gui_marker_create -id ${Wave.1} C2 620210463
gui_marker_select -id ${Wave.1} { C2 }
gui_marker_set_ref -id ${Wave.1} C1
gui_wv_zoom_timerange -id ${Wave.1} 665193119 667348726
gui_list_add_group -id ${Wave.1} -after {New Group} {Group1}
gui_list_add_group -id ${Wave.1} -after {New Group} {Group2}
gui_list_add_group -id ${Wave.1} -after {New Group} {Group3}
gui_list_add_group -id ${Wave.1} -after {New Group} {Group4}
gui_list_select -id ${Wave.1} {caravel_top.uut.housekeeping.csclk }
gui_seek_criteria -id ${Wave.1} {Rising}
gui_set_env TOGGLE::DEFAULT_WAVE_WINDOW ${Wave.1}
gui_set_pref_value -category Wave -key exclusiveSG -value $groupExD
gui_list_set_height -id Wave -height $origWaveHeight
if {$origGroupCreationState} {
gui_list_create_group_when_add -wave -enable
}
if { $groupExD } {
gui_msg_report -code DVWW028
}
gui_list_set_filter -id ${Wave.1} -list { {Buffer 1} {Input 1} {Others 1} {Linkage 1} {Output 1} {Parameter 1} {All 1} {Aggregate 1} {LibBaseMember 1} {Event 1} {Assertion 1} {Constant 1} {Interface 1} {BaseMembers 1} {Signal 1} {$unit 1} {Inout 1} {Variable 1} }
gui_list_set_filter -id ${Wave.1} -text {*}
gui_list_set_insertion_bar -id ${Wave.1} -group Group4 -item caravel_top.uut.housekeeping.wbbd_sck -position below
gui_marker_move -id ${Wave.1} {C1} 665850000
gui_view_scroll -id ${Wave.1} -vertical -set 0
gui_show_grid -id ${Wave.1} -enable false
# Restore toplevel window zorder
# The toplevel window could be closed if it has no view/pane
if {[gui_exist_window -window ${TopLevel.1}]} {
gui_set_active_window -window ${TopLevel.1}
gui_set_active_window -window ${Source.1}
gui_set_active_window -window ${DLPane.1}
}
if {[gui_exist_window -window ${TopLevel.2}]} {
gui_set_active_window -window ${TopLevel.2}
gui_set_active_window -window ${Wave.1}
}
#</Session>

View File

@ -1,86 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
import cocotb.log
from tests.common_functions.test_functions import *
from tests.bitbang.bitbang_functions import *
#VIP for SPI
"""
support commands
00000000 -> No operation
00000011 -> Read in streaming mode
"""
async def SPI_VIP(csb,clk,SDI,SDO,mem):
while True:
await FallingEdge(csb)
cocotb.log.info (f"[SPI_VIP] CSB is asserted operation has begin ")
op = await cocotb.start(SPI_op(clk,SDI,SDO,mem))
await csb_watcher(csb,op)
cocotb.log.info (f"[SPI_VIP] CSB is deasserted operation has been killed")
# watch the csb and when it's diable kill the SPI_op thread
async def csb_watcher(csb,thread):
cocotb.log.info (f"[csb_watcher] start CSB watching")
await RisingEdge(csb)
thread.kill()
# detect command and address and apply the command
async def SPI_op(clk,SDI,SDO,mem):
address =''
command =''
await RisingEdge(clk)
# command
for i in range(8):
command = command + SDI.value.binstr
await RisingEdge(clk)
cocotb.log.info (f"[SPI_VIP] [SPI_op] command = {command}")
# address
address =''
for i in range(8*3): # address is 3 parts each part are 8 bits
address = address + SDI.value.binstr
if i != 23: # skip last cycle wait
await RisingEdge(clk)
cocotb.log.info (f"[SPI_VIP] [SPI_op] address = {address}")
address = int(address,2)
#data
if command == "10000000" and False: # not sure about the read command
for i in range(8):
data_in += SDI
await RisingEdge(clk)
elif command == "00000011":
await FallingEdge(clk)
while True:
data = bin(mem[address])[2:].zfill(8)
for i in range(8):
SDO[0].value = 1 # enable
SDO[1].value = int(data[i],2) # bin
cocotb.log.debug (f"[SPI_VIP] [SPI_op] SDO = {data[i]} ")
await FallingEdge(clk)
SDO[0].value = 0 # enable
cocotb.log.info (f"[SPI_VIP] [SPI_op] finish reading address {hex(address) } data = {hex(int(data,2))} ")
address +=1
def read_mem (file_name):
with open(file_name, 'r') as file:
lines = file.readlines()
mem = dict()
for line in lines:
if line[0] == "@":
address = int(line[1:],16)
cocotb.log.debug (f" found line = {line} address = {hex(address)} ")
else:
line_no_space = line.strip().replace(' ','')
for i in range (0,len(line_no_space),2):
cocotb.log.debug (f" i = {i} ine_no_space[{i}:{i+2}] = {line_no_space[i:i+2]} address = {hex(address)}")
mem[address] = int(line_no_space[i:i+2],16)
address +=1
cocotb.log.debug (f" found line = {line} line_no_space = {line_no_space} size = {len(line_no_space)}")
cocotb.log.info (f"[read_mem] SPI mem = {mem}")
return mem

View File

@ -1,106 +0,0 @@
import random
import cocotb
from cocotb.triggers import FallingEdge,RisingEdge,ClockCycles,Timer
import cocotb.log
from interfaces.cpu import RiskV
from interfaces.defsParser import Regs
from cocotb.result import TestSuccess
from tests.common_functions.test_functions import *
from tests.spi_master.SPI_VIP import read_mem ,SPI_VIP
from interfaces.caravel import GPIO_MODE
bit_time_ns = 0
reg = Regs()
@cocotb.test()
@repot_test
async def spi_master_rd(dut):
""" the firmware is configured to always send clk to spi so I can't insert alot of logics reading values
the method of testing used can't work if 2 addresses Consecutive have the same address
"""
caravelEnv,clock = await test_configure(dut,timeout_cycles=213888)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info (f"[TEST] start spi_master_rd test")
file_name = f"{os.getenv('CARAVEL_VERILOG_PATH')}/dv/cocotb/tests/spi_master/test_data"
mem = read_mem(file_name)
await cocotb.start(SPI_VIP(dut.bin33_monitor,dut.bin32_monitor,dut.bin35_monitor,(dut.bin34_en,dut.bin34),mem)) # fork for SPI
addresses_to_read = (0x04,0x05,0x06,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf) # the addresses that the firmware read from mem file
await wait_reg2(cpu,caravelEnv,0XAA)
cocotb.log.info (f"[TEST] GPIO configuration finished ans start reading from mememory")
val =0
for address in addresses_to_read:
# await wait_reg2(cpu,caravelEnv,0x55) # value is ready to be read
#wait until value change
while True:
if val != cpu.read_debug_reg1():
break
await ClockCycles(caravelEnv.clk,100)
expected_val = mem[address]
val = cpu.read_debug_reg1()
if val == expected_val:
cocotb.log.info(f"[TEST] correct read of value {hex(val)} from address {hex(address)} ")
else:
cocotb.log.error(f"[TEST] wrong read from address {hex(address)} expected value = {hex(expected_val)} value {hex(val)} ")
# cpu.write_debug_reg2_backdoor(0xCC)
await ClockCycles(caravelEnv.clk,1000)
@cocotb.test()
@repot_test
async def spi_master_temp(dut):
""" the firmware is configured to always send clk to spi so I can't insert alot of logics reading values
the method of testing used can't work if 2 addresses Consecutive have the same address
"""
caravelEnv,clock = await test_configure(dut,timeout_cycles=39554)
cpu = RiskV(dut)
cpu.cpu_force_reset()
cpu.cpu_release_reset()
cocotb.log.info (f"[TEST] start spi_master_temp test")
await FallingEdge(dut.bin33_monitor)
await RisingEdge(dut.bin32_monitor)
a = ''
b = ''
# first value
for i in range(8):
a = a + dut.bin35_monitor.value.binstr
await RisingEdge(dut.bin32_monitor)
cocotb.log.info (f" [TEST] a = {a} = {int(a,2)}")
# second val
for i in range(8):
b = b + dut.bin35_monitor.value.binstr
if i != 7: # skip last cycle wait
await RisingEdge(dut.bin32_monitor)
cocotb.log.info (f" [TEST] b = {b} = {int(b,2)}")
s = int(a,2) + int(b,2)
s_bin = bin(s)[2:].zfill(8)
cocotb.log.info (f" [TEST] sending sum of {int(a,2)} + {int(b,2)} = {s} = {s_bin}")
await FallingEdge(dut.bin32_monitor)
for i in range(8):
dut.bin34_en.value = 1
dut.bin34.value = int(s_bin[i],2) # bin
cocotb.log.debug (f"[SPI_VIP] [SPI_op] SDO = {s_bin[i]} ")
await FallingEdge(dut.bin32_monitor)
dut.bin34_en.value = 0 # enable
while True:
if cpu.read_debug_reg1() == 0xBB:
cocotb.log.info(f" [TEST] firmware recieve the right value {s}")
break
elif cpu.read_debug_reg1() == 0xBB:
cocotb.log.error(f" [TEST] firmware recieve the incorrect value {cpu.read_debug_reg2()} instead of {s}")
break
await ClockCycles(caravelEnv.clk,10)

View File

@ -1,182 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <csr.h>
#include <stub.c>
// --------------------------------------------------------
/*
* SPI master Test
* - Enables SPI master
* - Uses SPI master to talk to external SPI module
*/
void spi_write(char c)
{
reg_spimaster_wdata = (unsigned long) c;
// reg_spimaster_wdata = c;
// spi_master_control_length_write(8);
// spi_master_control_start_write(1);
// reg_spimaster_control = 0x0800;
reg_spimaster_control = 0x0801;
}
char spi_read()
{
// reg_spimaster_wdata = c;
// spi_master_control_length_write(8);
// spi_master_control_start_write(1);
// reg_spimaster_control = 0x0800;
// spi_write(0x00);
// reg_spimaster_rdata = 0x00;
// reg_spimaster_control = 0x0801;
spi_write(0x00);
while (reg_spimaster_status != 1);
return reg_spimaster_rdata;
}
void main()
{
int i;
uint32_t value;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// For SPI operation, GPIO 1 should be an input, and GPIOs 2 to 4
// should be outputs.
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // SDI
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL; // SDO
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT; // CSB
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT; // SCK
/* Apply configuration */
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_2 =0xAA;
reg_spi_enable = 1;
// For SPI operation, GPIO 1 should be an input, and GPIOs 2 to 4
// should be outputs.
// Start test
// Enable SPI master
// SPI master configuration bits:
// bits 7-0: Clock prescaler value (default 2)
// bit 8: MSB/LSB first (0 = MSB first, 1 = LSB first)
// bit 9: CSB sense (0 = inverted, 1 = noninverted)
// bit 10: SCK sense (0 = noninverted, 1 = inverted)
// bit 11: mode (0 = read/write opposite edges, 1 = same edges)
// bit 12: stream (1 = CSB ends transmission)
// bit 13: enable (1 = enabled)
// bit 14: IRQ enable (1 = enabled)
// bit 15: (unused)
reg_spimaster_cs = 0x10001; // sel=0, manual CS
spi_write(0x03); // Write 0x03 (read mode)
spi_write(0x00); // Write 0x00 (start address high byte)
spi_write(0x00); // Write 0x00 (start address middle byte)
spi_write(0x04); // Write 0x04 (start address low byte)
value = spi_read(); // 0x93
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x01
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x00
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
reg_spimaster_cs = 0x0000; // release CS
reg_spimaster_cs = 0x10001; // sel=0, manual CS
spi_write(0x03); // Write 0x03 (read mode)
spi_write(0x00); // Write 0x00 (start address high byte)
spi_write(0x00); // Write 0x00 (start address middle byte)
spi_write(0x08); // Write 0x08 (start address low byte)
value = spi_read(); // 0x13
if (value == 0x13)
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x02
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
reg_spimaster_cs = 0x0000; // release CS
reg_spimaster_cs = 0x10001; // sel=0, manual CS
spi_write(0x03); // Write 0x03 (read mode)
spi_write(0x00); // Write 0x00 (start address high byte)
spi_write(0x00); // Write 0x00 (start address middle byte)
spi_write(0x0a); // Write 0x0a (start address low byte)
value = spi_read(); // 0x63
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x57
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0xb5
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x00
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read();// 0x23
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
value = spi_read(); // 0x20
reg_debug_1 = value;
// reg_debug_2 =0x55; // value is ready to be read
// while (reg_debug_2 != 0xCC) // testbench has read the value
reg_spimaster_cs = 0x0000; // release CS
reg_spimaster_cs = 0x10001; // sel=0, manual CS
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
}

View File

@ -1,113 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Efabless Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/
#include <defs.h>
#include <csr.h>
#include <stub.c>
// --------------------------------------------------------
/*
* SPI master Test
* - Enables SPI master
* - Uses SPI master to talk to external SPI module
*/
void spi_write(char c)
{
reg_spimaster_wdata = (unsigned long) c;
// reg_spimaster_wdata = c;
// spi_master_control_length_write(8);
// spi_master_control_start_write(1);
// reg_spimaster_control = 0x0800;
reg_spimaster_control = 0x0801;
}
char spi_read()
{
// reg_spimaster_wdata = c;
// spi_master_control_length_write(8);
// spi_master_control_start_write(1);
// reg_spimaster_control = 0x0800;
// spi_write(0x00);
// reg_spimaster_rdata = 0x00;
// reg_spimaster_control = 0x0801;
spi_write(0x00);
while (reg_spimaster_status != 1);
return reg_spimaster_rdata;
}
void main()
{
int i;
uint32_t value;
reg_wb_enable =1; // for enable writing to reg_debug_1 and reg_debug_2
reg_debug_1 = 0x0;
reg_debug_2 = 0x0;
// For SPI operation, GPIO 1 should be an input, and GPIOs 2 to 4
// should be outputs.
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // SDI
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_BIDIRECTIONAL; // SDO
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT; // CSB
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT; // SCK
/* Apply configuration */
reg_mprj_xfer = 1;
while (reg_mprj_xfer == 1);
reg_debug_2 =0xAA;
reg_spi_enable = 1;
// For SPI operation, GPIO 1 should be an input, and GPIOs 2 to 4
// should be outputs.
// Start test
// Enable SPI master
// SPI master configuration bits:
// bits 7-0: Clock prescaler value (default 2)
// bit 8: MSB/LSB first (0 = MSB first, 1 = LSB first)
// bit 9: CSB sense (0 = inverted, 1 = noninverted)
// bit 10: SCK sense (0 = noninverted, 1 = inverted)
// bit 11: mode (0 = read/write opposite edges, 1 = same edges)
// bit 12: stream (1 = CSB ends transmission)
// bit 13: enable (1 = enabled)
// bit 14: IRQ enable (1 = enabled)
// bit 15: (unused)
reg_spimaster_cs = 0x10001; // sel=0, manual CS
spi_write(0x08); // Write 0x03 (read mode)
spi_write(0x05); // Write 0x00 (start address high byte)
value = spi_read(); // 0x93
if (value == 0xD)
reg_debug_1 = 0xBB; // get correct value
else {
reg_debug_2 = value;
reg_debug_1 = 0xEE; // get wrong value
}
reg_spimaster_cs = 0x0000; // release CS
reg_spimaster_cs = 0x10001; // sel=0, manual CS
print("adding a very very long delay because cpu produces X's when code finish and this break the simulation");
}

View File

@ -1,3 +0,0 @@
@00000000
6F 00 00 0B 93 01 00 00 13 02 63 57 b5 00 23 20
13 00 00 00 13 00 00 00 13 00 00 00 13 00 00 00

Some files were not shown because too many files have changed in this diff Show More