Skip to content

Commit

Permalink
uptime: rework and integrate it in Timer to ease software support.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed May 17, 2020
1 parent d6549ff commit be25500
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
10 changes: 10 additions & 0 deletions litex/soc/cores/timer.py
Expand Up @@ -82,3 +82,13 @@ def __init__(self, width=32):
If(self._update_value.re, self._value.status.eq(value))
]
self.comb += self.ev.zero.trigger.eq(value != 0)

def add_uptime(self, width=64):
self._uptime_latch = CSRStorage(description="Write a ``1`` to latch current Uptime cycles to ``uptime_cycles`` register.")
self._uptime_cycles = CSRStatus(width, description="Latched Uptime since power-up (in ``sys_clk`` cycles).")

# # #

uptime_cycles = Signal(width, reset_less=True)
self.sync += uptime_cycles.eq(uptime_cycles + 1)
self.sync += If(self._uptime_latch.re, self._uptime_cycles.status.eq(uptime_cycles))
13 changes: 1 addition & 12 deletions litex/soc/integration/soc.py
Expand Up @@ -614,8 +614,7 @@ class SoCController(Module, AutoCSR):
def __init__(self,
with_reset = True,
with_scratch = True,
with_errors = True,
with_uptime = False):
with_errors = True):

if with_reset:
self._reset = CSRStorage(1, description="""Write a ``1`` to this register to reset the SoC.""")
Expand All @@ -627,10 +626,6 @@ def __init__(self,
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 ``uptime`` register.")
self._uptime = CSRStatus(64, description="Latched Uptime since power-up (in ``sys_clk`` cycles).")

# # #

# Reset
Expand All @@ -649,12 +644,6 @@ def __init__(self,
]
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 ----------------------------------------------------------------------------------------------

class SoC(Module):
Expand Down
6 changes: 4 additions & 2 deletions litex/soc/integration/soc_core.py
Expand Up @@ -95,9 +95,9 @@ def __init__(self, platform, clk_freq,
uart_fifo_depth = 16,
# Timer parameters
with_timer = True,
timer_uptime = False,
# Controller parameters
with_ctrl = True,
ctrl_uptime = False,
# Others
**kwargs):

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

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

# Add CPU
self.add_cpu(
Expand Down Expand Up @@ -183,6 +183,8 @@ def __init__(self, platform, clk_freq,
# Add Timer
if with_timer:
self.add_timer(name="timer0")
if timer_uptime:
self.timer0.add_uptime()

# Add CSR bridge
self.add_csr_bridge(self.mem_map["csr"])
Expand Down
6 changes: 3 additions & 3 deletions litex/soc/software/bios/commands/cmd_bios.c
Expand Up @@ -76,13 +76,13 @@ define_command(reboot, reboot, "Reboot the system", SYSTEM_CMDS);
* Uptime of the system
*
*/
#ifdef CSR_CTRL_UPTIME_ADDR
#ifdef CSR_TIMER0_UPTIME_CYCLES_ADDR
static void uptime(int nb_params, char **params)
{
unsigned long uptime;

ctrl_uptime_latch_write(1);
uptime = ctrl_uptime_read();
timer0_uptime_latch_write(1);
uptime = timer0_uptime_cycles_read();
printf("Uptime: %ld sys_clk cycles / %ld seconds",
uptime,
uptime/CONFIG_CLOCK_FREQUENCY
Expand Down

0 comments on commit be25500

Please sign in to comment.