Initial commit

This commit is contained in:
2026-02-23 20:42:11 -07:00
committed by GitHub
commit 2ba96a115d
462 changed files with 9166588 additions and 0 deletions

4
verilog/dv/cocotb/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
sim/
*.log
*.vcd
*.pyc

View File

@@ -0,0 +1,43 @@
Overview
========
This directory contain tests to verify the example user project 16 bit counter and 2 other simple tests as examples.
directory hierarchy
=====================
# counter_tests
contain tests for 16 bit counter for more info refer to [counter_tests](counter_tests/README.md)
# hello_world
Example test with empty firmware that only power and reset caravel the print "Hello World"
# hello_world_uart
Example test That uses the firmware to send "Hello World" using UART TX
# cocotb_tests.py
Module that should import all the tests used to be seen for cocotb as a test
Run tests
===========
# run hello_world_uart
```bash
caravel_cocotb -t hello_world_uart -tag hello_world
```
# run all counter testlist
```bash
caravel_cocotb -tl counter_tests/counter_tests.yaml -tag counter_tests
```
# run from different directory
```bash
caravel_cocotb -t hello_world_uart -tag hello_world -design_info <path to design_info.yaml>
```
# run with changing the results directory
```bash
caravel_cocotb -t hello_world_uart -tag hello_world -sim <path to results directory>
```

View File

@@ -0,0 +1,7 @@
from hello_world.hello_world import hello_world
from hello_world_uart.hello_world_uart import hello_world_uart
from user_proj_tests.counter_wb.counter_wb import counter_wb
from user_proj_tests.counter_la.counter_la import counter_la
from user_proj_tests.counter_la_reset.counter_la_reset import counter_la_reset
from user_proj_tests.counter_la_clk.counter_la_clk import counter_la_clk
from gpio_test.gpio_test import gpio_test

View File

@@ -0,0 +1,9 @@
CARAVEL_ROOT: /usr/caravel_user_project/caravel
MCW_ROOT: /usr/caravel_user_project/mgmt_core_wrapper
PDK: sky130A
PDK_ROOT: /usr/pdk
USER_PROJECT_ROOT: /usr/caravel_user_project
caravan: false
clk: 25
emailto:
- null

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h> // include required APIs
void main(){
// Enable managment gpio as output to use as indicator for finishing configuration
ManagmentGpio_outputEnable();
ManagmentGpio_write(0);
enableHkSpi(0); // disable housekeeping spi
//GPIOs_configureAll(GPIO_MODE_MGMT_STD_OUT);
GPIOs_configureAll(GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_loadConfigs();
GPIOs_writeLow(0x8F);
ManagmentGpio_write(1); // configuration finished
return;
}

View File

@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import * # import python APIs
import cocotb
@cocotb.test() # cocotb test marker
@report_test # wrapper for configure test reporting files
async def gpio_test(dut):
caravelEnv = await test_configure(dut) #configure, start up and reset caravel
#await caravelEnv.release_csb()
await caravelEnv.wait_mgmt_gpio(1)
gpios_value_str = caravelEnv.monitor_gpio(37, 0).binstr
cocotb.log.info (f"All gpios '{gpios_value_str}'")
gpio_value_int = caravelEnv.monitor_gpio(37, 0).integer
#expected_gpio_value = 0xF8
expected_gpio_value = 0x8F
if (gpio_value_int == expected_gpio_value):
cocotb.log.info (f"[TEST] Pass the gpio value is '{hex(gpio_value_int)}'")
else:
cocotb.log.error (f"[TEST] Fail the gpio value is :'{hex(gpio_value_int)}' expected {hex(expected_gpio_value)}")

View File

@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
return;
}

View File

@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
@cocotb.test()
@report_test
async def hello_world(dut):
caravelEnv = await test_configure(dut,timeout_cycles=9373)
cocotb.log.info("Hello World")

View File

@@ -0,0 +1,27 @@
---
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
# example
## tests: [debug,clock_redirect]
## sim: [RTL,RTL]
Tests:
- {name: hello_world, sim: RTL}

View File

@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
ManagmentGpio_write(0);
ManagmentGpio_outputEnable();
GPIOs_configure(6,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_loadConfigs();
UART_enableTX(1);
ManagmentGpio_write(1); // configuration finished
print("Hello World\n");
return;
}

View File

@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
from caravel_cocotb.caravel_interfaces import UART
@cocotb.test()
@report_test
async def hello_world_uart(dut):
caravelEnv = await test_configure(dut,timeout_cycles=3346140)
cocotb.log.info(f"[TEST] Start uart test")
expected_msg = "Hello World"
uart = UART(caravelEnv)
# wait for start of sending
await caravelEnv.wait_mgmt_gpio(1)
# read the msg sent
msg = await uart.get_line()
if msg in expected_msg :
cocotb.log.info (f"[TEST] Pass recieve the full expected msg '{msg}'")
else:
cocotb.log.error (f"[TEST] recieved wrong msg from uart msg recieved:'{msg}' expected '{expected_msg}'")

View File

@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: hello_world_uart, sim: RTL}

View File

@@ -0,0 +1,26 @@
Tests hierarchy
=====================
# counter_wb
Test that overwrite the counter value using wishbone interface
# counter_la
Test that overwrite the counter value using logic analyzer interface
# counter_la_clk
Counter can work by 2 different clocks wishbone clock or clock provided through logic analyzers.
By default the wishbone clock is the used one. This test uses the logic analyzers clock
# counter_la_reset
Counter reset also provided through wishbone or logic analyzers. this test uses the logic analyzers reset
# counter_tests.yaml
Testlist contain all counter tests

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
// Enable managment gpio as output to use as indicator for finishing configuration
ManagmentGpio_outputEnable();
ManagmentGpio_write(0);
enableHkSpi(0); // disable housekeeping spi
// configure all gpios as user out then chenge gpios from 32 to 37 before loading this configurations
GPIOs_configureAll(GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(32,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(33,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(34,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(35,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(36,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(37,GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_loadConfigs(); // load the configuration
ManagmentGpio_write(1); // configuration finished
// configure la [63:32] as output from cpu
LogicAnalyzer_write(1,7<<16);
LogicAnalyzer_outputEnable(1,0);
ManagmentGpio_write(0); // configuration finished
LogicAnalyzer_outputEnable(1,0xFFFFFFFF);
return;
}

View File

@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
@cocotb.test()
@report_test
async def counter_la(dut):
caravelEnv = await test_configure(dut, timeout_cycles=59844)
cocotb.log.info(f"[TEST] Start counter_la test")
# wait for start of sending
await caravelEnv.release_csb()
await caravelEnv.wait_mgmt_gpio(1)
cocotb.log.info(f"[TEST] finish configuration")
overwrite_val = 7 # value will be written to the counter by la
# expect value bigger than 7
await caravelEnv.wait_mgmt_gpio(0) # wait until writing 7 through la
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
counter = overwrite_val
if received_val != counter :
cocotb.log.fatal(f"LA writing is incorrect: {overwrite_val} receieved: {received_val}")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
# wait until the LA writing is disabled
while (received_val == counter):
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
counter = received_val
for i in range(100):
if counter != int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) :
cocotb.log.error(f"counter have wrong value expected = {counter} recieved = {int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) }")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
counter +=1

View File

@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: counter_la, sim: RTL}

View File

@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
// Enable managment gpio as output to use as indicator for finishing configuration
ManagmentGpio_outputEnable();
ManagmentGpio_write(0);
enableHkSpi(0); // disable housekeeping spi
// configure all gpios as user out then chenge gpios from 32 to 37 before loading this configurations
GPIOs_configureAll(GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(32,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(33,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(34,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(35,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(36,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(37,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_loadConfigs(); // load the configuration
// configure la 64 (clk enable by la) as output from cpu
// writing 1 in bit 64(first bit in reg 2) to reset
LogicAnalyzer_write(2,0);
// LogicAnalyzer_inputEnable(2,0x1);
LogicAnalyzer_outputEnable(2,0xFFFFFFFC);
// reset counter
// reset 1
LogicAnalyzer_write(2,3); // clk pose edge
LogicAnalyzer_write(2,2);// clk pose edge
// reset 0
LogicAnalyzer_write(2,1); // clk pose edge
LogicAnalyzer_write(2,0);// clk pose edge
ManagmentGpio_write(1); // configuration finished
for (int i = 0; i < 7; i++){
LogicAnalyzer_write(2,1); // clk pose edge
ManagmentGpio_write(0);
LogicAnalyzer_write(2,0);// clk pose edge
ManagmentGpio_write(1);
}
return;
}

View File

@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
@cocotb.test()
@report_test
async def counter_la_clk(dut):
caravelEnv = await test_configure(dut,timeout_cycles=61011)
cocotb.log.info(f"[TEST] Start counter_wb test")
# wait for start of sending
await caravelEnv.release_csb()
await caravelEnv.wait_mgmt_gpio(1)
cocotb.log.info(f"[TEST] finish configuration")
overwrite_val = 0 # because of the reset
# expect value bigger than 7
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
counter = received_val
for i in range(5):
if counter != int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) :
cocotb.log.error(f"counter have wrong value expected = {counter} recieved = {int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) }")
await wait_la_clock_cycle(caravelEnv)
counter +=1
async def wait_la_clock_cycle(caravelEnv):
# clock is synced with mgmt_gpio
await caravelEnv.wait_mgmt_gpio(0)
await caravelEnv.wait_mgmt_gpio(1)

View File

@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: counter_la_clk, sim: RTL}

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
// Enable managment gpio as output to use as indicator for finishing configuration
ManagmentGpio_outputEnable();
ManagmentGpio_write(0);
enableHkSpi(0); // disable housekeeping spi
// configure all gpios as user out then chenge gpios from 32 to 37 before loading this configurations
GPIOs_configureAll(GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_configure(32,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(33,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(34,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(35,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(36,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_configure(37,GPIO_MODE_MGMT_STD_OUTPUT);
GPIOs_loadConfigs(); // load the configuration
// reset counter
LogicAnalyzer_outputEnable(2,0xFFFFFFFD);
LogicAnalyzer_write(2,2);
LogicAnalyzer_write(2,0);
ManagmentGpio_write(1); // configuration finished
// configure la 65 (reset enable by la) as output from cpu
// writing 1 in bit 65(second bit in reg 2) to reset
// asset reset
LogicAnalyzer_write(2,2);
LogicAnalyzer_inputEnable(2,0x2);
LogicAnalyzer_outputEnable(2,0xFFFFFFFD);
// deassert reset
LogicAnalyzer_inputEnable(2,0);
LogicAnalyzer_outputEnable(2,0xFFFFFFFF);
return;
}

View File

@@ -0,0 +1,58 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
@cocotb.test()
@report_test
async def counter_la_reset(dut):
caravelEnv = await test_configure(dut,timeout_cycles=1346140)
cocotb.log.info(f"[TEST] Start counter_wb test")
# wait for start of sending
await caravelEnv.release_csb()
await caravelEnv.wait_mgmt_gpio(1)
cocotb.log.info(f"[TEST] finish configuration")
overwrite_val = 0 # because of the reset
# expect value bigger than 7
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
counter = received_val
if received_val <= overwrite_val :
cocotb.log.error(f"counter started late and value captured after configuration is smaller than overwrite value: {overwrite_val} receieved: {received_val}")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
while True: # wait until reset asserted
if await get_reset_val(caravelEnv) == 1:
cocotb.log.info(f"[TEST] Reset asserted by la")
break
while True: # wait until reset deasserted
if await get_reset_val(caravelEnv) == 0:
cocotb.log.info(f"[TEST] Reset deasserted by la")
break
counter =0
for i in range(100):
if counter != int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) :
cocotb.log.error(f"counter have wrong value expected = {counter} recieved = {int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) }")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
counter +=1
async def get_reset_val(caravelEnv):
""" get the counter reset value"""
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
return caravelEnv.user_hdl.mprj.counter.reset.value

View File

@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: counter_la_reset, sim: RTL}

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2023 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.
#include <firmware_apis.h>
void main(){
// Enable managment gpio as output to use as indicator for finishing configuration
ManagmentGpio_outputEnable();
ManagmentGpio_write(0);
enableHkSpi(0); // disable housekeeping spi
// configure all gpios as user out then chenge gpios from 32 to 37 before loading this configurations
GPIOs_configureAll(GPIO_MODE_USER_STD_OUT_MONITORED);
GPIOs_loadConfigs(); // load the configuration
User_enableIF(); // this necessary when reading or writing between wishbone and user project if interface isn't enabled no ack would be recieve and the command will be stuck
// user la reset and wb clk
LogicAnalyzer_outputEnable(2,1);
// reset counter
LogicAnalyzer_write(2,2);
LogicAnalyzer_write(2,0);
ManagmentGpio_write(1); // configuration finished
// writing to any address inside user project address space would reload the counter value
USER_writeWord(0x7,0x88);
ManagmentGpio_write(0); // start counting from 0
return;
}

View File

@@ -0,0 +1,63 @@
# SPDX-FileCopyrightText: 2023 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
from caravel_cocotb.caravel_interfaces import test_configure
from caravel_cocotb.caravel_interfaces import report_test
import cocotb
@cocotb.test()
@report_test
async def counter_wb(dut):
caravelEnv = await test_configure(dut,timeout_cycles=32620)
cocotb.log.info(f"[TEST] Start counter_wb test")
# wait for start of sending
await caravelEnv.release_csb()
await caravelEnv.wait_mgmt_gpio(1)
cocotb.log.info(f"[TEST] finish configuration")
overwrite_val = 7 # value will be written to the counter by wishbone
# expect value bigger than 7
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
counter = received_val
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
while True: # wait until the value 1 start counting after the initial
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
if counter == 0xFFFF: # rollover
counter = 0
else:
counter +=1
if received_val != counter:
if received_val == overwrite_val:
counter = received_val +1
cocotb.log.info(f"Counter value has been overwritten by wishbone to be {received_val}")
while True: #wait until the wishbone writing finished and the counter start running again
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
if counter == received_val:
break
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
cocotb.log.info(f"Counter value has been overwritten by wishbone to be {received_val}")
break
else:
cocotb.log.error(f"Counter has wrong value before overwrite happened expected: {counter} received: {received_val}")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
for i in range(100):
if counter != int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) :
cocotb.log.error(f"Counter have wrong value expected = {counter} recieved = {int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) }")
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
counter +=1

View File

@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 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
# Yalm file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: counter_wb, sim: RTL}

View File

@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2023 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
# yaml file contain general design information that would mostly need to be updated in the first run only
includes:
- counter_la/counter_la.yaml
- counter_wb/counter_wb.yaml
- counter_la_reset/counter_la_reset.yaml
- counter_la_clk/counter_la_clk.yaml

View File

@@ -0,0 +1,8 @@
---
# yaml file contain general design information that would mostly need to be updated in the first run only
Tests:
- {name: counter_wb, sim: GL}
- {name: counter_la, sim: GL}
- {name: counter_la_reset, sim: GL}
- {name: counter_la_clk, sim: GL}