Skip to content

Commit

Permalink
Merge pull request #345 from efabless/gf180mcu_cocotb
Browse files Browse the repository at this point in the history
add cocotb to Gf180mcu
  • Loading branch information
jeffdi authored Dec 6, 2023
2 parents 8988593 + 1d0469b commit 0b5fee5
Show file tree
Hide file tree
Showing 28 changed files with 935 additions and 0 deletions.
4 changes: 4 additions & 0 deletions verilog/dv/cocotb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sim/
*.log
*.vcd
*.pyc
43 changes: 43 additions & 0 deletions verilog/dv/cocotb/README.md
Original file line number Diff line number Diff line change
@@ -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>
```

7 changes: 7 additions & 0 deletions verilog/dv/cocotb/cocotb_tests.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions verilog/dv/cocotb/design_info.yaml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions verilog/dv/cocotb/gpio_test/gpio_test.c
Original file line number Diff line number Diff line change
@@ -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;
}
36 changes: 36 additions & 0 deletions verilog/dv/cocotb/gpio_test/gpio_test.py
Original file line number Diff line number Diff line change
@@ -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)}")


19 changes: 19 additions & 0 deletions verilog/dv/cocotb/hello_world/hello_world.c
Original file line number Diff line number Diff line change
@@ -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;
}
25 changes: 25 additions & 0 deletions verilog/dv/cocotb/hello_world/hello_world.py
Original file line number Diff line number Diff line change
@@ -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")
27 changes: 27 additions & 0 deletions verilog/dv/cocotb/hello_world/hello_world.yaml
Original file line number Diff line number Diff line change
@@ -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}




28 changes: 28 additions & 0 deletions verilog/dv/cocotb/hello_world_uart/hello_world_uart.c
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions verilog/dv/cocotb/hello_world_uart/hello_world_uart.py
Original file line number Diff line number Diff line change
@@ -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}'")
24 changes: 24 additions & 0 deletions verilog/dv/cocotb/hello_world_uart/hello_world_uart.yaml
Original file line number Diff line number Diff line change
@@ -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}


26 changes: 26 additions & 0 deletions verilog/dv/cocotb/user_proj_tests/README.md
Original file line number Diff line number Diff line change
@@ -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

44 changes: 44 additions & 0 deletions verilog/dv/cocotb/user_proj_tests/counter_la/counter_la.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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
#ifdef GF180
LogicAnalyzer_write(1,7<<14);
LogicAnalyzer_outputEnable(1,0xC0000000);
#else
LogicAnalyzer_write(1,7<<16);
LogicAnalyzer_outputEnable(1,0);
#endif // GF180
ManagmentGpio_write(0); // configuration finished
LogicAnalyzer_outputEnable(1,0xFFFFFFFF);
return;
}
Loading

0 comments on commit 0b5fee5

Please sign in to comment.