-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move clock generation from bus to test - add parameters to set clocks - add wait timer before/after transaction
- Loading branch information
Showing
8 changed files
with
105 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,18 @@ | |
# SiLab, Institute of Physics, University of Bonn | ||
# ------------------------------------------------------------ | ||
# | ||
# Initial version by Chris Higgs <[email protected]> | ||
# | ||
|
||
# pylint: disable=pointless-statement, expression-not-assigned | ||
|
||
|
||
import cocotb | ||
from cocotb.binary import BinaryValue | ||
from cocotb.triggers import RisingEdge | ||
from cocotb.drivers import BusDriver | ||
from cocotb.clock import Clock | ||
from cocotb.triggers import RisingEdge, ReadOnly | ||
from cocotb_bus.drivers import BusDriver | ||
|
||
|
||
class BasilSbusDriver(BusDriver): | ||
"""Abastract away interactions with the control bus. | ||
""" | ||
"""Abastract away interactions with the control bus.""" | ||
|
||
_signals = ["BUS_CLK", "BUS_RST", "BUS_DATA_IN", "BUS_DATA_OUT", "BUS_ADD", "BUS_RD", "BUS_WR"] | ||
_optional_signals = ["BUS_BYTE_ACCESS"] | ||
|
||
|
@@ -36,9 +32,6 @@ def __init__(self, entity): | |
|
||
self._has_byte_acces = False | ||
|
||
# Kick off a clock generator | ||
cocotb.fork(Clock(self.clock, 5000).start()) | ||
|
||
async def init(self): | ||
# Defaults | ||
self.bus.BUS_RST <= 1 | ||
|
@@ -57,7 +50,7 @@ async def init(self): | |
|
||
# why this does not work? hasattr(self.bus, 'BUS_BYTE_ACCESS'): | ||
try: | ||
getattr(self.bus, 'BUS_BYTE_ACCESS') | ||
getattr(self.bus, "BUS_BYTE_ACCESS") | ||
except Exception: | ||
self._has_byte_acces = False | ||
else: | ||
|
@@ -66,55 +59,52 @@ async def init(self): | |
async def read(self, address, size): | ||
result = [] | ||
|
||
self.bus.BUS_ADD <= self._x | ||
self.bus.BUS_DATA_IN <= self._high_impedance | ||
self.bus.BUS_RD <= 0 | ||
|
||
await RisingEdge(self.clock) | ||
|
||
if size == 0: | ||
return result | ||
|
||
self.bus.BUS_RD <= 1 | ||
self.bus.BUS_ADD <= address | ||
|
||
byte = 0 | ||
while(byte <= size): | ||
if(byte == size): | ||
self.bus.BUS_RD <= 0 | ||
else: | ||
self.bus.BUS_RD <= 1 | ||
|
||
self.bus.BUS_ADD <= address + byte | ||
while byte < size: | ||
|
||
await RisingEdge(self.clock) | ||
|
||
if(byte != 0): | ||
if(self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0): | ||
result.append(self.bus.BUS_DATA_OUT.value.integer & 0x000000ff) | ||
result.append((self.bus.BUS_DATA_OUT.value.integer & 0x0000ff00) >> 8) | ||
result.append((self.bus.BUS_DATA_OUT.value.integer & 0x00ff0000) >> 16) | ||
result.append((self.bus.BUS_DATA_OUT.value.integer & 0xff000000) >> 24) | ||
else: | ||
# result.append(self.bus.BUS_DATA_OUT.value[24:31].integer & 0xff) | ||
if len(self.bus.BUS_DATA_OUT.value) == 8: | ||
result.append(self.bus.BUS_DATA_OUT.value.integer & 0xff) | ||
else: | ||
result.append(self.bus.BUS_DATA_OUT.value[24:31].integer & 0xff) | ||
|
||
if(self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0): | ||
if self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0: | ||
byte += 4 | ||
else: | ||
byte += 1 | ||
|
||
self.bus.BUS_ADD <= self._x | ||
self.bus.BUS_DATA_IN <= self._high_impedance | ||
self.bus.BUS_RD <= 0 | ||
self.bus.BUS_ADD <= address + byte | ||
if byte >= size: | ||
self.bus.BUS_RD <= 0 | ||
|
||
await ReadOnly() | ||
|
||
value = self.bus.BUS_DATA_OUT.value | ||
|
||
if self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0: | ||
result.append(value.integer & 0x000000FF) | ||
result.append((value.integer & 0x0000FF00) >> 8) | ||
result.append((value.integer & 0x00FF0000) >> 16) | ||
result.append((value.integer & 0xFF000000) >> 24) | ||
elif len(value) == 8: | ||
result.append(value.integer & 0xFF) | ||
else: | ||
result.append(value[24:31].integer & 0xFF) | ||
|
||
await RisingEdge(self.clock) | ||
|
||
self.bus.BUS_ADD <= self._x | ||
self.bus.BUS_RD <= 0 | ||
|
||
return result | ||
|
||
async def write(self, address, data): | ||
|
||
self.bus.BUS_ADD <= self._x | ||
self.bus.BUS_DATA_IN <= self._high_impedance | ||
self.bus.BUS_WR <= 0 | ||
|
||
await RisingEdge(self.clock) | ||
|
||
for index, byte in enumerate(data): | ||
|
@@ -124,11 +114,9 @@ async def write(self, address, data): | |
|
||
await RisingEdge(self.clock) | ||
|
||
if(self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0): | ||
if self._has_byte_acces and self.bus.BUS_BYTE_ACCESS.value.integer == 0: | ||
raise NotImplementedError("BUS_BYTE_ACCESS for write to be implemented.") | ||
|
||
self.bus.BUS_ADD <= self._x | ||
self.bus.BUS_DATA_IN <= self._high_impedance | ||
self.bus.BUS_WR <= 0 | ||
|
||
await RisingEdge(self.clock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.