Skip to content
Snippets Groups Projects
Commit 69bc0c7b authored by dam1n19's avatar dam1n19
Browse files

Created Seperate Cocotb drivers file and added simple write test

parent b3de40e5
Branches
No related tags found
No related merge requests found
...@@ -55,6 +55,8 @@ COCOTB_SCRATCH_DIR := $(COCOTB_DIR)/scratch ...@@ -55,6 +55,8 @@ COCOTB_SCRATCH_DIR := $(COCOTB_DIR)/scratch
# Filelist for Cocotb # Filelist for Cocotb
MAKEFILE_FILELIST := $(COCOTB_DIR)/makefile.flist MAKEFILE_FILELIST := $(COCOTB_DIR)/makefile.flist
MODULE ?= test_adp
# Create a List of PHONY Targets # Create a List of PHONY Targets
.PHONY: compile_$(SIMULATOR) run_$(SIMULATOR) sim_$(SIMULATOR) .PHONY: compile_$(SIMULATOR) run_$(SIMULATOR) sim_$(SIMULATOR)
...@@ -162,7 +164,7 @@ run_cocotb: DEFINES_VC += COCOTB_SIM ...@@ -162,7 +164,7 @@ run_cocotb: DEFINES_VC += COCOTB_SIM
run_cocotb: flist_makefile_nanosoc run_cocotb: flist_makefile_nanosoc
@mkdir -p $(SIM_DIR) @mkdir -p $(SIM_DIR)
@cd $(SIM_DIR); $(MAKE) -C $(SOCLABS_NANOSOC_TECH_DIR)/verif/cocotb clean SIM_BUILD=$(COCOTB_SCRATCH_DIR) @cd $(SIM_DIR); $(MAKE) -C $(SOCLABS_NANOSOC_TECH_DIR)/verif/cocotb clean SIM_BUILD=$(COCOTB_SCRATCH_DIR)
@cd $(SIM_DIR); $(MAKE) -C $(SOCLABS_NANOSOC_TECH_DIR)/verif/cocotb sim SIM=$(COCOTB_SIMULATOR) TESTCASE=$(TESTNAME) GUI=$(GUI) SIM_BUILD=$(COCOTB_SCRATCH_DIR) ACCELERATOR=$(ACCELERATOR) @cd $(SIM_DIR); $(MAKE) -C $(SOCLABS_NANOSOC_TECH_DIR)/verif/cocotb sim MODULE=$(MODULE) SIM=$(COCOTB_SIMULATOR) TESTCASE=$(TESTNAME) GUI=$(GUI) SIM_BUILD=$(COCOTB_SCRATCH_DIR) ACCELERATOR=$(ACCELERATOR)
sim_cocotb: GUI=1 sim_cocotb: GUI=1
sim_cocotb: run_cocotb sim_cocotb: run_cocotb
#-----------------------------------------------------------------------------
# SoCLabs ADP Cocotb Drivers
# Contributors
#
# David Mapstone (d.a.mapstone@soton.ac.uk)
#
# Copyright 2021-3, SoC Labs (www.soclabs.org)
#-----------------------------------------------------------------------------
import cocotb
# Class for ADP AXI Stream Interface
class ADP():
def __init__(self, dut, send, recieve):
self.dut = dut
# Send Stream to NanoSoC
self.send = send
# Send Recieve to NanoSoC
self.recieve = recieve
self.monitor_mode = False
# Read Block from ADP
@cocotb.coroutine
async def read(self, length):
read_str = ""
for i in range(length):
data = await self.recieve.read()
read_str += chr(data[0])
return read_str
# Read ADP String
@cocotb.coroutine
async def readLine(self):
read_str = ""
while True:
# Read Bytes from ADP AXI Stream
data = await self.recieve.read()
curr_char = chr(data[0])
# Combine Bytes into String
if (curr_char != '\n'):
read_str += curr_char
else:
return read_str.strip()
# Write ADP String
@cocotb.coroutine
async def write(self, string):
for i in string:
await self.send.write([ord(i)])
await self.send.write([0x0a])
read_str = await self.readLine()
self.dut.log.info(read_str)
# Enter Monitor Mode
@cocotb.coroutine
async def monitorModeEnter(self):
self.dut.log.info("Entering ADP Monitor Mode")
await self.send.write([0x1b])
self.monitor_mode = True
# Exit Monitor Mode
@cocotb.coroutine
async def monitorModeEnter(self):
self.dut.log.info("Exiting ADP Monitor Mode")
await self.send.write([0x04])
self.monitor_mode = False
\ No newline at end of file
#-----------------------------------------------------------------------------
# SoCLabs Cocotb ADP Testcases
# Contributors
#
# David Mapstone (d.a.mapstone@soton.ac.uk)
#
# Copyright 2021-3, SoC Labs (www.soclabs.org)
#-----------------------------------------------------------------------------
from random import randint, randrange, getrandbits, shuffle from random import randint, randrange, getrandbits, shuffle
from collections.abc import Iterable from collections.abc import Iterable
...@@ -9,52 +17,17 @@ from cocotb.result import TestFailure ...@@ -9,52 +17,17 @@ from cocotb.result import TestFailure
from cocotb.triggers import ClockCycles, Combine, Join, RisingEdge from cocotb.triggers import ClockCycles, Combine, Join, RisingEdge
from cocotbext.axi import AxiStreamBus, AxiStreamSource, AxiStreamSink, AxiStreamMonitor from cocotbext.axi import AxiStreamBus, AxiStreamSource, AxiStreamSink, AxiStreamMonitor
from adp_cocotb_driver import ADP
CLK_PERIOD = (10, "ns") CLK_PERIOD = (10, "ns")
# Class for ADP AXI Stream Interface
class ADPDriver():
def __init__(self, send, recieve):
# Send Stream to NanoSoC
self.send = send
# Send Recieve to NanoSoC
self.recieve = recieve
# Read ADP String
@cocotb.coroutine
async def read(self):
read_str = ""
while True:
# Read Bytes from ADP AXI Stream
data = await self.recieve.read()
curr_char = chr(data[0])
# Combine Bytes into String
if (curr_char != '\n'):
read_str += curr_char
else:
return read_str
# Write ADP String
# @cocotb.coroutine
# async def read(self):
# read_str = ""
# while True:
# # Read Bytes from ADP AXI Stream
# data = await self.recieve.read()
# curr_char = chr(data[0])
# # Combine Bytes into String
# if (curr_char != '\n'):
# read_str += curr_char
# else:
# return read_str
# Control ADP AXI Stream bus and create ADP Driver Object # Control ADP AXI Stream bus and create ADP Driver Object
def setup_adp(dut): def setup_adp(dut):
adp_sender = AxiStreamSource(AxiStreamBus.from_prefix(dut, "txd8"), dut.XTAL1, dut.NRST) adp_sender = AxiStreamSource(AxiStreamBus.from_prefix(dut, "txd8"), dut.XTAL1, dut.NRST)
adp_reciever = AxiStreamSink(AxiStreamBus.from_prefix(dut, "rxd8"), dut.XTAL1, dut.NRST) adp_reciever = AxiStreamSink(AxiStreamBus.from_prefix(dut, "rxd8"), dut.XTAL1, dut.NRST)
logging.getLogger("cocotb.nanosoc_tb.rxd8").setLevel(logging.WARNING) logging.getLogger("cocotb.nanosoc_tb.rxd8").setLevel(logging.WARNING)
driver = ADPDriver(adp_sender, adp_reciever) logging.getLogger("cocotb.nanosoc_tb.txd8").setLevel(logging.WARNING)
driver = ADP(dut, adp_sender, adp_reciever)
return driver return driver
# Start Clocks and Reset System # Start Clocks and Reset System
...@@ -66,28 +39,12 @@ async def setup_dut(dut): ...@@ -66,28 +39,12 @@ async def setup_dut(dut):
dut.NRST.value = 1 dut.NRST.value = 1
await ClockCycles(dut.XTAL1, 2) await ClockCycles(dut.XTAL1, 2)
@cocotb.coroutine
async def write(driver, buf):
wr_count = 0
for i in buf:
print(i)
await driver.tx.send(str(ord(i)))
return wr_count
@cocotb.coroutine
async def write(driver, buf):
wr_count = 0
for i in buf:
print(i)
await driver.tx.send(str(ord(i)))
return wr_count
# Wait for bootcode to finish # Wait for bootcode to finish
@cocotb.coroutine @cocotb.coroutine
async def wait_bootcode(dut, driver): async def wait_bootcode(dut, driver):
bootcode_last = "** Remap->IMEM0" bootcode_last = "** Remap->IMEM0"
while True: while True:
read_str = await driver.read() read_str = await driver.readLine()
dut.log.info(read_str) dut.log.info(read_str)
if read_str == bootcode_last: if read_str == bootcode_last:
break break
...@@ -118,6 +75,12 @@ async def test_adp_write(dut): ...@@ -118,6 +75,12 @@ async def test_adp_write(dut):
dut.log.info("Setup Complete") dut.log.info("Setup Complete")
dut.log.info("Starting Test") dut.log.info("Starting Test")
await wait_bootcode(dut, adp_driver) await wait_bootcode(dut, adp_driver)
dut.log.info("Bootcode Finished")
await adp_driver.monitorModeEnter()
await adp_driver.write('A 0x10000000\n')
await adp_driver.write('R 4\n')
for i in range(4):
dut.log.info(await adp_driver.readLine())
dut.log.info("ADP Write Test Complete") dut.log.info("ADP Write Test Complete")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment