uptime: rework and integrate it in Timer to ease software support.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 17 May 2020 09:03:21 +0000 (11:03 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 17 May 2020 09:05:14 +0000 (11:05 +0200)
litex/soc/cores/timer.py
litex/soc/integration/soc.py
litex/soc/integration/soc_core.py
litex/soc/software/bios/commands/cmd_bios.c

index 570bf650d12ac5de73b09967b29e43f2cea191be..72f61a7caa41c93a0b9503c3550901e88bc03aa6 100644 (file)
@@ -82,3 +82,13 @@ class Timer(Module, AutoCSR, ModuleDoc):
             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))
index 8527f64508b44ac4a6e22252eb60411d5cb24466..a31a3a63edd5801112a6ae8ce73bd411f5d8fe42 100644 (file)
@@ -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.""")
@@ -627,10 +626,6 @@ class SoCController(Module, AutoCSR):
         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
@@ -649,12 +644,6 @@ class SoCController(Module, AutoCSR):
             ]
             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):
index dafd3ba3e8c18852a204a8300dfaf728fc6f67de..9567510b2e0f984a1593891d11e0894418427f1a 100644 (file)
@@ -95,9 +95,9 @@ class SoCCore(LiteXSoC):
         uart_fifo_depth          = 16,
         # Timer parameters
         with_timer               = True,
+        timer_uptime             = False,
         # Controller parameters
         with_ctrl                = True,
-        ctrl_uptime              = False,
         # Others
         **kwargs):
 
@@ -147,7 +147,7 @@ class SoCCore(LiteXSoC):
 
         # Add SoCController
         if with_ctrl:
-            self.add_controller("ctrl", with_uptime=ctrl_uptime)
+            self.add_controller("ctrl")
 
         # Add CPU
         self.add_cpu(
@@ -183,6 +183,8 @@ class SoCCore(LiteXSoC):
         # 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"])
index 961e786fe1b8803fc2a12df1d3c222f10611d339..bbca856ce35a33d9fb6d91ecbc6f7f6e7e20bea5 100644 (file)
@@ -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