Skip to content

Commit a848e3a

Browse files
author
M0stafaRady
committed
Add cocotb flow to caravel_user_project_analog and port the mprj_por test to cocotb
1 parent c020fde commit a848e3a

16 files changed

+271
-1
lines changed

verilog/dv/cocotb/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sim/
2+
*.log
3+
*.vcd
4+
*.pyc

verilog/dv/cocotb/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Overview
2+
========
3+
This directory contain tests to verify the example user project 16 bit counter and 2 other simple tests as examples.
4+
5+
directory hierarchy
6+
=====================
7+
8+
# counter_tests
9+
10+
contain tests for 16 bit counter for more info refer to [counter_tests](counter_tests/README.md)
11+
12+
# hello_world
13+
14+
Example test with empty firmware that only power and reset caravel the print "Hello World"
15+
16+
# hello_world_uart
17+
18+
Example test That uses the firmware to send "Hello World" using UART TX
19+
20+
# cocotb_tests.py
21+
22+
Module that should import all the tests used to be seen for cocotb as a test
23+
24+
25+
Run tests
26+
===========
27+
# run hello_world_uart
28+
```bash
29+
caravel_cocotb -t hello_world_uart -tag hello_world
30+
```
31+
# run all counter testlist
32+
```bash
33+
caravel_cocotb -tl counter_tests/counter_tests.yaml -tag counter_tests
34+
```
35+
# run from different directory
36+
```bash
37+
caravel_cocotb -t hello_world_uart -tag hello_world -design_info <path to design_info.yaml>
38+
```
39+
# run with changing the results directory
40+
```bash
41+
caravel_cocotb -t hello_world_uart -tag hello_world -sim <path to results directory>
42+
```
43+

verilog/dv/cocotb/cocotb_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from hello_world.hello_world import hello_world
2+
from hello_world_uart.hello_world_uart import hello_world_uart
3+
from mprj_por.mprj_por import mprj_por

verilog/dv/cocotb/design_info.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CARAVEL_ROOT: <path to>/caravel
2+
MCW_ROOT: <path to>/litex
3+
PDK: sky130A
4+
PDK_ROOT: <path to>/pdk
5+
USER_PROJECT_ROOT: <path to>/caravel_user_project_analog/
6+
caravan: true
7+
clk: 25
8+
emailto:
9+
- null
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <firmware_apis.h>
2+
void main(){
3+
return;
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from caravel_cocotb.caravel_interfaces import test_configure
2+
from caravel_cocotb.caravel_interfaces import report_test
3+
import cocotb
4+
5+
@cocotb.test()
6+
@report_test
7+
async def hello_world(dut):
8+
caravelEnv = await test_configure(dut,timeout_cycles=9373)
9+
cocotb.log.info("Hello World")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# Yalm file contain general design information that would mostly need to be updated in the first run only
3+
# example
4+
## tests: [debug,clock_redirect]
5+
## sim: [RTL,RTL]
6+
Tests:
7+
- {name: hello_world, sim: RTL}
8+
9+
10+
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <firmware_apis.h>
2+
3+
void main(){
4+
ManagmentGpio_write(0);
5+
ManagmentGpio_outputEnable();
6+
GPIOs_configure(6,GPIO_MODE_MGMT_STD_OUTPUT);
7+
GPIOs_loadConfigs();
8+
UART_enableTX(1);
9+
ManagmentGpio_write(1); // configuration finished
10+
11+
print("Hello World\n");
12+
return;
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from caravel_cocotb.caravel_interfaces import test_configure
2+
from caravel_cocotb.caravel_interfaces import report_test
3+
import cocotb
4+
from caravel_cocotb.caravel_interfaces import UART
5+
6+
@cocotb.test()
7+
@report_test
8+
async def hello_world_uart(dut):
9+
caravelEnv = await test_configure(dut,timeout_cycles=3346140)
10+
11+
cocotb.log.info(f"[TEST] Start uart test")
12+
expected_msg = "Hello World"
13+
uart = UART(caravelEnv)
14+
# wait for start of sending
15+
await caravelEnv.wait_mgmt_gpio(1)
16+
# read the msg sent
17+
msg = await uart.get_line()
18+
if msg in expected_msg :
19+
cocotb.log.info (f"[TEST] Pass recieve the full expected msg '{msg}'")
20+
else:
21+
cocotb.log.error (f"[TEST] recieved wrong msg from uart msg recieved:'{msg}' expected '{expected_msg}'")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Yalm file contain general design information that would mostly need to be updated in the first run only
3+
4+
Tests:
5+
- {name: hello_world_uart, sim: RTL}
6+
7+

verilog/dv/cocotb/mprj_por/mprj_por.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2020 Efabless Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* SPDX-License-Identifier: Apache-2.0
16+
*/
17+
18+
#include <firmware_apis.h>
19+
20+
// --------------------------------------------------------
21+
22+
void main()
23+
{
24+
ManagmentGpio_write(0);
25+
ManagmentGpio_outputEnable();
26+
GPIOs_writeLow(0x00000000);
27+
GPIOs_writeHigh(0x00000000);
28+
29+
// Configure mprj_io 10 and 25 as analog (digital in/out = off)
30+
// Configure mprj_io 11, 12, 26, and 27 as digital output
31+
// mprj_io 14 to 24 are analog pads and cannot be configured
32+
GPIOs_configure(27, GPIO_MODE_USER_STD_OUTPUT);
33+
GPIOs_configure(26, GPIO_MODE_USER_STD_OUTPUT);
34+
GPIOs_configure(25, GPIO_MODE_USER_STD_ANALOG);
35+
36+
GPIOs_configure(12, GPIO_MODE_USER_STD_OUTPUT);
37+
GPIOs_configure(11, GPIO_MODE_USER_STD_OUTPUT);
38+
GPIOs_configure(10, GPIO_MODE_USER_STD_ANALOG);
39+
40+
GPIOs_loadConfigs();
41+
ManagmentGpio_write(1); // finish configuration
42+
43+
/* Block until end of test */
44+
while (1);
45+
}
46+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from caravel_cocotb.caravel_interfaces import test_configure
2+
from caravel_cocotb.caravel_interfaces import report_test
3+
import cocotb
4+
from cocotb.triggers import ClockCycles
5+
6+
7+
@cocotb.test()
8+
@report_test
9+
async def mprj_por(dut):
10+
caravelEnv = await test_configure(dut,timeout_cycles=3346140)
11+
# Power supply for POR
12+
caravelEnv.drive_gpio_in(18, 0)
13+
await caravelEnv.reset()
14+
await cocotb.start(power_por(caravelEnv))
15+
await wait_status(caravelEnv, "01")
16+
check_bits = caravelEnv.monitor_discontinuous_gpios([27, 26, 12, 11])
17+
if check_bits != "1001":
18+
cocotb.log.error(f"[TEST] POR test failed expected 1001 got {check_bits}")
19+
else:
20+
cocotb.log.info(f"[TEST] phase 1 passed seen 1001 at gpios 27 26 12 11")
21+
await wait_status(caravelEnv, "11")
22+
check_bits = caravelEnv.monitor_discontinuous_gpios([27, 26, 12, 11])
23+
if check_bits != "0101":
24+
cocotb.log.error(f"[TEST] POR test failed expected 0101 got {check_bits}")
25+
else:
26+
cocotb.log.info(f"[TEST] phase 2 passed seen 0101 at gpios 27 26 12 11")
27+
28+
29+
async def wait_status(caravelEnv, val_to_wait):
30+
while True:
31+
if caravelEnv.monitor_discontinuous_gpios([25, 10]) == val_to_wait:
32+
break
33+
await ClockCycles(caravelEnv.clk, 1)
34+
await ClockCycles(caravelEnv.clk, 3)
35+
36+
37+
38+
async def power_por(caravelEnv):
39+
await caravelEnv.wait_mgmt_gpio(1) # wait configuration finished
40+
await ClockCycles(caravelEnv.clk, 10)
41+
caravelEnv.drive_gpio_in(18, 1)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-FileCopyrightText: 2020 Efabless Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// SPDX-License-Identifier: Apache-2.0
15+
16+
// Caravel user project includes
17+
$USER_PROJECT_VERILOG/gl/user_project_wrapper.v
18+
$USER_PROJECT_VERILOG/gl/user_proj_example.v
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2020 Efabless Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# SPDX-License-Identifier: Apache-2.0
15+
16+
# Caravel user project includes
17+
-v $(USER_PROJECT_VERILOG)/gl/user_project_wrapper.v
18+
-v $(USER_PROJECT_VERILOG)/gl/user_proj_example.v
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2020 Efabless Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# SPDX-License-Identifier: Apache-2.0
15+
16+
# Caravel user project includes
17+
-v $(USER_PROJECT_VERILOG)/rtl/example_por.v
18+
-v $(USER_PROJECT_VERILOG)/rtl/user_analog_proj_example.v
19+
-v $(USER_PROJECT_VERILOG)/rtl/user_analog_project_wrapper.v
20+
-v $(USER_PROJECT_VERILOG)/rtl/user_defines.v
21+
22+

verilog/rtl/user_analog_proj_example.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
`default_nettype none
1717

18+
`ifndef COCOTB_SIM
1819
`include "example_por.v"
19-
20+
`endif
2021
/*
2122
* I/O mapping for analog
2223
*

0 commit comments

Comments
 (0)