soc: merge with misoc 3fcc4f116c3292020cb811d179e45ae45990101b
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 10 Nov 2015 15:43:38 +0000 (16:43 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 10 Nov 2015 15:51:51 +0000 (16:51 +0100)
changes:
-software/bios: remove dataflow
-cores/identifier: replace with user-defined string
-interconnect/CSRBankArray: support read-only mappings
-targets: Added Numato Mimas V2 target
-Our libunwind changes were merged upstream.
-wishbone: update TODO
-replace Counter in Converters
-Fix CSRBankArray
-flterm: properly exit on ^C.

12 files changed:
litex/soc/cores/identifier.py
litex/soc/integration/soc_core.py
litex/soc/integration/soc_sdram.py
litex/soc/interconnect/csr_bus.py
litex/soc/interconnect/wishbone.py
litex/soc/software/bios/boot.c
litex/soc/software/bios/main.c
litex/soc/software/include/base/id.h
litex/soc/software/libbase/id.c
litex/soc/software/libbase/time.c
litex/soc/software/libnet/microudp.c
litex/soc/tools/flterm.py

index 2ed151f858e6214ffe8c27cbd623da875a355985..5baedca15e02e4f6e246be2652433c035da2afbd 100644 (file)
@@ -1,16 +1,14 @@
 from litex.gen import *
 
-from litex.soc.interconnect.csr import *
 
-
-class Identifier(Module, AutoCSR):
-    def __init__(self, sysid, frequency, revision=None):
-        self._sysid = CSRStatus(16)
-        self._frequency = CSRStatus(32)
-
-        ###
-
-        self.comb += [
-            self._sysid.status.eq(sysid),
-            self._frequency.status.eq(frequency)
-        ]
+class Identifier(Module):
+    def __init__(self, ident):
+        contents = list(ident.encode())
+        l = len(contents)
+        if l > 255:
+            raise ValueError("Identifier string must be 255 characters or less")
+        contents.insert(0, l)
+        self.mem = Memory(8, len(contents), init=contents)
+
+    def get_memories(self):
+        return [(True, self.mem)]
index 315af0700afd9c08d52360555a84a08e15e7b5e3..4f55e9c0cf7940df3b2fae7f14850b2b4da9da52 100644 (file)
@@ -16,13 +16,13 @@ def mem_decoder(address, start=26, end=29):
 
 class SoCCore(Module):
     csr_map = {
-        "crg":        0,  # user
-        "uart_phy":   1,  # provided by default (optional)
-        "uart":       2,  # provided by default (optional)
-        "identifier": 3,  # provided by default (optional)
-        "timer0":     4,  # provided by default (optional)
-        "buttons":    5,  # user
-        "leds":       6,  # user
+        "crg":            0,  # user
+        "uart_phy":       1,  # provided by default (optional)
+        "uart":           2,  # provided by default (optional)
+        "identifier_mem": 3,  # provided by default (optional)
+        "timer0":         4,  # provided by default (optional)
+        "buttons":        5,  # user
+        "leds":           6,  # user
     }
     interrupt_map = {
         "uart":   0,
@@ -42,7 +42,7 @@ class SoCCore(Module):
                 shadow_base=0x80000000,
                 csr_data_width=8, csr_address_width=14,
                 with_uart=True, uart_baudrate=115200,
-                with_identifier=True,
+                ident="",
                 with_timer=True):
         self.platform = platform
         self.clk_freq = clk_freq
@@ -59,8 +59,6 @@ class SoCCore(Module):
         self.with_uart = with_uart
         self.uart_baudrate = uart_baudrate
 
-        self.with_identifier = with_identifier
-
         self.shadow_base = shadow_base
 
         self.csr_data_width = csr_data_width
@@ -103,9 +101,9 @@ class SoCCore(Module):
             self.submodules.uart_phy = uart.RS232PHY(platform.request("serial"), clk_freq, uart_baudrate)
             self.submodules.uart = uart.UART(self.uart_phy)
 
-        if with_identifier:
-            platform_id = 0x554E if not hasattr(platform, "identifier") else platform.identifier
-            self.submodules.identifier = identifier.Identifier(platform_id, int(clk_freq))
+        if ident:
+            self.submodules.identifier = identifier.Identifier(ident)
+        self.add_constant("SYSTEM_CLOCK_FREQUENCY", int(clk_freq))
 
         if with_timer:
             self.submodules.timer0 = timer.Timer()
index 8ad630099c8e4eaebdcf65645e42550a62a89007..3c3a3e836107d44b0e76e6941c90de47c9c9d9b7 100644 (file)
@@ -43,7 +43,7 @@ class SoCSDRAM(SoCCore):
     def __init__(self, platform, clk_freq, l2_size=8192, **kwargs):
         SoCCore.__init__(self, platform, clk_freq, **kwargs)
         self.l2_size = l2_size
-
+        
         self._sdram_phy = []
         self._wb_sdram_ifs = []
         self._wb_sdram = wishbone.Interface()
index b27c256fdf667901ebda76dabb5362bf8a6984f9..1281992753eba3395989c39caecbee259932060b 100644 (file)
@@ -152,11 +152,16 @@ class CSRBankArray(Module):
             if hasattr(obj, "get_memories"):
                 memories = obj.get_memories()
                 for memory in memories:
+                    if isinstance(memory, tuple):
+                        read_only, memory = memory
+                    else:
+                        read_only = False
                     mapaddr = self.address_map(name, memory)
                     if mapaddr is None:
                         continue
                     sram_bus = Interface(*ifargs, **ifkwargs)
-                    mmap = csr.SRAM(memory, mapaddr, bus=sram_bus)
+                    mmap = SRAM(memory, mapaddr, read_only=read_only,
+                                bus=sram_bus)
                     self.submodules += mmap
                     csrs += mmap.get_csrs()
                     self.srams.append((name, memory, mapaddr, mmap))
index a2070fa4acfb93aa405546cf5577dd25580b4099..c10cda4eec868e244303aaa5b13ffa4e8943eae9 100644 (file)
@@ -175,15 +175,22 @@ class DownConverter(Module):
         read = Signal()
         write = Signal()
 
-        counter = Counter(max=ratio)
-        self.submodules += counter
+        counter = Signal(max=ratio)
+        counter_reset = Signal()
+        counter_ce = Signal()
+        self.sync += \
+            If(counter_reset,
+                counter.eq(0)
+            ).Elif(counter_ce,
+                counter.eq(counter + 1)
+            )
         counter_done = Signal()
-        self.comb += counter_done.eq(counter.value == ratio-1)
+        self.comb += counter_done.eq(counter == ratio-1)
 
         # Main FSM
         self.submodules.fsm = fsm = FSM(reset_state="IDLE")
         fsm.act("IDLE",
-            counter.reset.eq(1),
+            counter_reset.eq(1),
             If(master.stb & master.cyc,
                 If(master.we,
                     NextState("WRITE")
@@ -199,7 +206,7 @@ class DownConverter(Module):
             If(master.stb & master.cyc,
                 slave.stb.eq(1),
                 If(slave.ack,
-                    counter.ce.eq(1),
+                    counter_ce.eq(1),
                     If(counter_done,
                         master.ack.eq(1),
                         NextState("IDLE")
@@ -215,7 +222,7 @@ class DownConverter(Module):
             If(master.stb & master.cyc,
                 slave.stb.eq(1),
                 If(slave.ack,
-                    counter.ce.eq(1),
+                    counter_ce.eq(1),
                     If(counter_done,
                         master.ack.eq(1),
                         NextState("IDLE")
@@ -233,7 +240,7 @@ class DownConverter(Module):
             ).Else(
                 slave.cti.eq(2)
             ),
-            slave.adr.eq(Cat(counter.value, master.adr))
+            slave.adr.eq(Cat(counter, master.adr))
         ]
 
         # Datapath
@@ -243,13 +250,13 @@ class DownConverter(Module):
                 slave.sel.eq(master.sel[i*dw_to//8:(i+1)*dw_to]),
                 slave.dat_w.eq(master.dat_w[i*dw_to:(i+1)*dw_to])
             ]
-        self.comb += Case(counter.value, cases)
+        self.comb += Case(counter, cases)
 
 
         cached_data = Signal(dw_from)
         self.comb += master.dat_r.eq(Cat(cached_data[dw_to:], slave.dat_r))
         self.sync += \
-            If(read & counter.ce,
+            If(read & counter_ce,
                 cached_data.eq(master.dat_r)
             )
 
@@ -287,13 +294,20 @@ class UpConverter(Module):
         self.submodules += address
         self.comb += address.d.eq(master.adr)
 
-        counter = Counter(max=ratio)
-        self.submodules += counter
+        counter = Signal(max=ratio)
+        counter_ce = Signal()
+        counter_reset = Signal()
+        self.sync += \
+            If(counter_reset,
+                counter.eq(0)
+            ).Elif(counter_ce,
+                counter.eq(counter + 1)
+            )
         counter_offset = Signal(max=ratio)
         counter_done = Signal()
         self.comb += [
             counter_offset.eq(address.q),
-            counter_done.eq((counter.value + counter_offset) == ratio-1)
+            counter_done.eq((counter + counter_offset) == ratio-1)
         ]
 
         cached_data = Signal(dw_to)
@@ -314,7 +328,7 @@ class UpConverter(Module):
         # Main FSM
         self.submodules.fsm = fsm = FSM()
         fsm.act("IDLE",
-            counter.reset.eq(1),
+            counter_reset.eq(1),
             If(master.stb & master.cyc,
                 address.ce.eq(1),
                 If(master.we,
@@ -331,7 +345,7 @@ class UpConverter(Module):
         fsm.act("WRITE",
             If(master.stb & master.cyc,
                 write.eq(1),
-                counter.ce.eq(1),
+                counter_ce.eq(1),
                 master.ack.eq(1),
                 If(counter_done,
                     NextState("EVICT")
@@ -384,7 +398,7 @@ class UpConverter(Module):
             write_sel = Signal()
             cases[i] = write_sel.eq(1)
             self.comb += [
-                cached_sels[i].reset.eq(counter.reset),
+                cached_sels[i].reset.eq(counter_reset),
                 If(write,
                     cached_datas[i].d.eq(master.dat_w),
                 ).Else(
@@ -396,7 +410,7 @@ class UpConverter(Module):
                     cached_sels[i].ce.eq(1)
                 )
             ]
-        self.comb += Case(counter.value + counter_offset, cases)
+        self.comb += Case(counter + counter_offset, cases)
 
         cases = {}
         for i in range(ratio):
index 0430aca7dd1058c0d3b185774daf6d105c28eb4f..635bd649304e651d5f99a6e0c404eccc23bea86a 100644 (file)
@@ -34,7 +34,7 @@ static int check_ack(void)
 
        timer0_en_write(0);
        timer0_reload_write(0);
-       timer0_load_write(identifier_frequency_read()/4);
+       timer0_load_write(SYSTEM_CLOCK_FREQUENCY/4);
        timer0_en_write(1);
        timer0_update_value_write(1);
        recognized = 0;
index 0deb9e9011998693f07dac5494137770a8205a50..bda64db47bfef7e5d15f2479d05a88f9641db9be 100644 (file)
@@ -13,7 +13,6 @@
 #include <net/microudp.h>
 
 #include "sdram.h"
-#include "dataflow.h"
 #include "boot.h"
 
 /* General address space functions */
@@ -176,6 +175,14 @@ static void crc(char *startaddr, char *len)
        printf("CRC32: %08x\n", crc32((unsigned char *)addr, length));
 }
 
+static void ident(void)
+{
+       char buffer[IDENT_SIZE];
+
+       get_ident(buffer);
+       printf("Ident: %s\n", buffer);
+}
+
 #ifdef __lm32__
 enum {
        CSR_IE = 1, CSR_IM, CSR_IP, CSR_ICC, CSR_DCC, CSR_CC, CSR_CFG, CSR_EBA,
@@ -288,23 +295,6 @@ static void wcsr(char *csr, char *value)
 
 #endif /* __lm32__ */
 
-static void dfs(char *baseaddr)
-{
-       char *c;
-       unsigned int addr;
-
-       if(*baseaddr == 0) {
-               printf("dfs <address>\n");
-               return;
-       }
-       addr = strtoul(baseaddr, &c, 0);
-       if(*c != 0) {
-               printf("incorrect address\n");
-               return;
-       }
-       print_isd_info(addr);
-}
-
 /* Init + command line */
 
 static void help(void)
@@ -361,6 +351,7 @@ static void do_command(char *c)
        else if(strcmp(token, "mw") == 0) mw(get_token(&c), get_token(&c), get_token(&c));
        else if(strcmp(token, "mc") == 0) mc(get_token(&c), get_token(&c), get_token(&c));
        else if(strcmp(token, "crc") == 0) crc(get_token(&c), get_token(&c));
+       else if(strcmp(token, "ident") == 0) ident();
 
 #ifdef L2_SIZE
        else if(strcmp(token, "flushl2") == 0) flush_l2_cache();
@@ -401,8 +392,6 @@ static void do_command(char *c)
        else if(strcmp(token, "sdrinit") == 0) sdrinit();
 #endif
 
-       else if(strcmp(token, "dfs") == 0) dfs(get_token(&c));
-
        else if(strcmp(token, "") != 0)
                printf("Command not found\n");
 }
@@ -479,7 +468,7 @@ static int test_user_abort(void)
 #endif
        timer0_en_write(0);
        timer0_reload_write(0);
-       timer0_load_write(identifier_frequency_read()*2);
+       timer0_load_write(SYSTEM_CLOCK_FREQUENCY*2);
        timer0_en_write(1);
        timer0_update_value_write(1);
        while(timer0_value_read()) {
@@ -538,7 +527,6 @@ int main(int i, char **c)
        "(c) Copyright 2007-2015 M-Labs Limited\n"
        "Built "__DATE__" "__TIME__"\n");
        crcbios();
-       id_print();
 #ifdef CSR_ETHMAC_BASE
        eth_init();
 #endif
index 89b540f6d9b07391213fd9ffc81ce0320241037f..bccbd55878899cbdd429c71fd6f47822a9ff3dd9 100644 (file)
@@ -5,8 +5,8 @@
 extern "C" {
 #endif
 
-void get_sysid_formatted(char *sysid);
-void id_print(void);
+#define IDENT_SIZE 256
+void get_ident(char *ident);
 
 #ifdef __cplusplus
 }
index 863912ab2e43921c70b01cc0aead5e5bc164f47e..093b99399b59532c8a55d58ea6ce76464dbc14b4 100644 (file)
@@ -4,17 +4,17 @@
 #include <string.h>
 #include <id.h>
 
-void get_sysid_formatted(char *sysid)
-{
-       sysid[0] = identifier_sysid_read() >> 8;
-       sysid[1] = identifier_sysid_read();
-       sysid[2] = 0;
-}
 
-void id_print(void)
+void get_ident(char *ident)
 {
-       char sysid[3];
-
-       get_sysid_formatted(sysid);
-       printf("Running on LiteX SoC (sysid:%s) at %dMHz\n", sysid, identifier_frequency_read()/1000000);
+#ifdef CSR_IDENTIFIER_MEM_BASE
+    int len, i;
+    
+    len = MMPTR(CSR_IDENTIFIER_MEM_BASE);
+    for(i=0;i<len;i++)
+        ident[i] = MMPTR(CSR_IDENTIFIER_MEM_BASE + 4 + i*4);
+    ident[i] = 0;
+#else
+    ident[0] = 0;
+#endif
 }
index 4bf95479a9ea7da163d09f9b1683f66961513b8c..9f7f1dbf20d934b02ba462152fffe5041518da7d 100644 (file)
@@ -6,7 +6,7 @@ void time_init(void)
        int t;
 
        timer0_en_write(0);
-       t = 2*identifier_frequency_read();
+       t = 2*SYSTEM_CLOCK_FREQUENCY;
        timer0_reload_write(t);
        timer0_load_write(t);
        timer0_en_write(1);
index c92e4453f1e6c1ff1bac1d9dc71c80507e87d1a7..1f0191fb731b3c56db0620485acb1b08b4edde71 100644 (file)
@@ -427,7 +427,7 @@ static void busy_wait(unsigned int ds)
 {
        timer0_en_write(0);
        timer0_reload_write(0);
-       timer0_load_write(identifier_frequency_read()/10*ds);
+       timer0_load_write(SYSTEM_CLOCK_FREQUENCY/10*ds);
        timer0_en_write(1);
        timer0_update_value_write(1);
        while(timer0_value_read()) timer0_update_value_write(1);
index c7b7fff835583c5d8684b1d3dc8b808bb34726a1..e29a7402d4d52a4f12e9fbdefb028d36b27f8f84 100644 (file)
@@ -299,7 +299,6 @@ def main():
         flterm.join(True)
     except KeyboardInterrupt:
         pass
-    flterm.join()
 
 
 if __name__ == "__main__":