Skip to content

Commit

Permalink
soc/SoCController: add uptime since start (disabled by default) and a…
Browse files Browse the repository at this point in the history
…llow features to be enabled/disabled.
  • Loading branch information
enjoy-digital committed May 15, 2020
1 parent 3391398 commit 82364de
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
71 changes: 47 additions & 24 deletions litex/soc/integration/soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,30 +611,49 @@ def __str__(self):
# SoCController ------------------------------------------------------------------------------------

class SoCController(Module, AutoCSR):
def __init__(self):
self._reset = CSRStorage(1, description="""
Write a ``1`` to this register to reset the SoC.""")
self._scratch = CSRStorage(32, reset=0x12345678, description="""
Use this register as a scratch space to verify that software read/write accesses
to the Wishbone/CSR bus are working correctly. The initial reset value of 0x1234578
can be used to verify endianness.""")
self._bus_errors = CSRStatus(32, description="""
Total number of Wishbone bus errors (timeouts) since last reset.""")
def __init__(self,
with_reset = True,
with_scratch = True,
with_errors = True,
with_uptime = False):

if with_reset:
self._reset = CSRStorage(1, description="""Write a ``1`` to this register to reset the SoC.""")
if with_scratch:
self._scratch = CSRStorage(32, reset=0x12345678, description="""
Use this register as a scratch space to verify that software read/write accesses
to the Wishbone/CSR bus are working correctly. The initial reset value of 0x1234578
can be used to verify endianness.""")
if with_errors:
self._bus_errors = CSRStatus(32, description="Total number of Wishbone bus errors (timeouts) since start.")

if with_uptime:
self._uptime_latch = CSRStorage(description="Write a ``1`` to latch current uptime to ``time`` register.")
self._uptime = CSRStatus(64, description="Latched uptime since start (in ``sys_clk`` cycles).")

# # #

# Reset
self.reset = Signal()
self.comb += self.reset.eq(self._reset.re)

# Bus errors
self.bus_error = Signal()
bus_errors = Signal(32)
self.sync += \
If(bus_errors != (2**len(bus_errors)-1),
If(self.bus_error, bus_errors.eq(bus_errors + 1))
)
self.comb += self._bus_errors.status.eq(bus_errors)
if with_reset:
self.reset = Signal()
self.comb += self.reset.eq(self._reset.re)

# Errors
if with_errors:
self.bus_error = Signal()
bus_errors = Signal(32)
self.sync += [
If(bus_errors != (2**len(bus_errors)-1),
If(self.bus_error, bus_errors.eq(bus_errors + 1))
)
]
self.comb += self._bus_errors.status.eq(bus_errors)

# Uptime
if with_uptime:
uptime = Signal(64, reset_less=True)
self.sync += uptime.eq(uptime + 1)
self.sync += If(self._uptime_latch.re, self._uptime.status.eq(uptime))

# SoC ----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -736,9 +755,9 @@ def add_config(self, name, value=None):
self.add_constant(name, value)

# SoC Main Components --------------------------------------------------------------------------
def add_controller(self, name="ctrl"):
def add_controller(self, name="ctrl", **kwargs):
self.check_if_exists(name)
setattr(self.submodules, name, SoCController())
setattr(self.submodules, name, SoCController(**kwargs))
self.csr.add(name, use_loc_if_exists=True)

def add_ram(self, name, origin, size, contents=[], mode="rw"):
Expand Down Expand Up @@ -794,8 +813,11 @@ def add_cpu(self, name="vexriscv", variant="standard", cls=None, reset_address=N
for name, loc in self.cpu.interrupts.items():
self.irq.add(name, loc)
self.add_config("CPU_HAS_INTERRUPT")


if hasattr(self, "ctrl"):
self.comb += self.cpu.reset.eq(self.ctrl.reset)
if hasattr(self.ctrl, "reset"):
self.comb += self.cpu.reset.eq(self.ctrl.reset)
self.add_config("CPU_RESET_ADDR", reset_address)
# Add constants
self.add_config("CPU_TYPE", str(name))
Expand Down Expand Up @@ -838,7 +860,8 @@ def do_finalize(self):
register = True,
timeout_cycles = self.bus.timeout)
if hasattr(self, "ctrl") and self.bus.timeout is not None:
self.comb += self.ctrl.bus_error.eq(self.bus_interconnect.timeout.error)
if hasattr(self.ctrl, "bus_error"):
self.comb += self.ctrl.bus_error.eq(self.bus_interconnect.timeout.error)
self.bus.logger.info("Interconnect: {} ({} <-> {}).".format(
colorer(self.bus_interconnect.__class__.__name__),
colorer(len(self.bus.masters)),
Expand Down
3 changes: 2 additions & 1 deletion litex/soc/integration/soc_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, platform, clk_freq,
with_timer = True,
# Controller parameters
with_ctrl = True,
ctrl_uptime = False,
# Others
**kwargs):

Expand Down Expand Up @@ -146,7 +147,7 @@ def __init__(self, platform, clk_freq,

# Add SoCController
if with_ctrl:
self.add_controller("ctrl")
self.add_controller("ctrl", with_uptime=ctrl_uptime)

# Add CPU
self.add_cpu(
Expand Down
2 changes: 1 addition & 1 deletion litex/soc/software/bios/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int serialboot(void)
break;
}
case SFL_CMD_REBOOT:
#ifdef CSR_CTRL_BASE
#ifdef CSR_CTRL_RESET_ADDR
uart_write(SFL_ACK_SUCCESS);
ctrl_reset_write(1);
#endif
Expand Down
2 changes: 1 addition & 1 deletion litex/soc/software/bios/commands/cmd_bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define_command(ident, ident_helper, "Display identifier", SYSTEM_CMDS);
* Reboot the system
*
*/
#ifdef CSR_CTRL_BASE
#ifdef CSR_CTRL_RESET_ADDR
static void reboot(int nb_params, char **params)
{
ctrl_reset_write(1);
Expand Down

0 comments on commit 82364de

Please sign in to comment.