Browse Source

usb: enable four ACM devices

Finally! Enable multiple ACM device channels (four for now, but it is
perfectly configurable.)
H. Peter Anvin 3 years ago
parent
commit
af2600349c
17 changed files with 1328 additions and 1104 deletions
  1. 2 2
      Makefile
  2. 45 41
      fpga/iodevs.vh
  3. 2 2
      fpga/max80.qpf
  4. 1 1
      fpga/max80.sv
  5. BIN
      fpga/output/v1.jic
  6. BIN
      fpga/output/v1.sof
  7. BIN
      fpga/output/v2.jic
  8. BIN
      fpga/output/v2.sof
  9. 1 1
      fpga/usb/usb.sv
  10. 8 5
      fpga/usb/usb_desc.conf
  11. 419 221
      fpga/usb/usb_desc.v
  12. 9 5
      iodevs.conf
  13. 9 5
      rv32/abcio.h
  14. 811 811
      rv32/boot.mif
  15. 6 6
      rv32/irq.h
  16. 3 3
      rv32/spurious_irq.c
  17. 12 1
      tools/iodevs.pl

+ 2 - 2
Makefile

@@ -14,9 +14,9 @@ $(REVISIONS): prefpga
 $(SUBDIRS):
 	$(MAKE) -C $@ $(goal)
 
-rv32: tools
+rv32: | tools
 
-fpga: rv32
+fpga: | rv32
 
 local.all:
 

+ 45 - 41
fpga/iodevs.vh

@@ -1,3 +1,4 @@
+	localparam CONSOLE_CHANNELS        = 'h00000004; // 4
 	localparam IODEV_ADDR_BITS         = 'h00000004; // 4
 	localparam IODEV_ADDR_SHIFT        = 'h00000007; // 7
 	localparam SDRAM_ADDR              = 'h40000000; // 1073741824
@@ -20,49 +21,49 @@
 	wire [ 0:0] iodev_valid_sys = iodev_valid[0:0];
 	tri1 [ 0:0] iodev_wait_n_sys;
 
+	wire [31:0] iodev_rdata_abc;
+	wire [ 0:0] iodev_irq_abc;
+	wire [ 0:0] iodev_valid_abc = iodev_valid[1:1];
+	tri1 [ 0:0] iodev_wait_n_abc;
+
+	wire [31:0] iodev_rdata_abcmemmap;
+	wire [ 0:0] iodev_valid_abcmemmap = xdev_valid[0:0];
+	tri1 [ 0:0] iodev_wait_n_abcmemmap;
+
 	wire [31:0] iodev_rdata_sysclock;
 	wire [ 0:0] iodev_irq_sysclock;
-	wire [ 0:0] iodev_valid_sysclock = iodev_valid[1:1];
+	wire [ 0:0] iodev_valid_sysclock = iodev_valid[2:2];
 	tri1 [ 0:0] iodev_wait_n_sysclock;
 
 	wire [31:0] iodev_rdata_console;
-	wire [ 0:0] iodev_irq_console;
-	wire [ 0:0] iodev_valid_console = iodev_valid[2:2];
+	wire [ 3:0] iodev_irq_console;
+	wire [ 0:0] iodev_valid_console = iodev_valid[3:3];
 	tri1 [ 0:0] iodev_wait_n_console;
 
+	wire [31:0] iodev_rdata_usbdesc;
+	wire [ 0:0] iodev_valid_usbdesc = xdev_valid[1:1];
+	tri1 [ 0:0] iodev_wait_n_usbdesc;
+
 	wire [31:0] iodev_rdata_romcopy;
 	wire [ 0:0] iodev_irq_romcopy;
-	wire [ 0:0] iodev_valid_romcopy = iodev_valid[3:3];
+	wire [ 0:0] iodev_valid_romcopy = iodev_valid[4:4];
 	tri1 [ 0:0] iodev_wait_n_romcopy;
 
 	wire [31:0] iodev_rdata_sdcard;
 	wire [ 0:0] iodev_irq_sdcard;
-	wire [ 0:0] iodev_valid_sdcard = iodev_valid[4:4];
+	wire [ 0:0] iodev_valid_sdcard = iodev_valid[5:5];
 	tri1 [ 0:0] iodev_wait_n_sdcard;
 
 	wire [31:0] iodev_rdata_i2c;
 	wire [ 0:0] iodev_irq_i2c;
-	wire [ 0:0] iodev_valid_i2c = iodev_valid[5:5];
+	wire [ 0:0] iodev_valid_i2c = iodev_valid[6:6];
 	tri1 [ 0:0] iodev_wait_n_i2c;
 
 	wire [31:0] iodev_rdata_esp;
 	wire [ 0:0] iodev_irq_esp;
-	wire [ 0:0] iodev_valid_esp = iodev_valid[6:6];
+	wire [ 0:0] iodev_valid_esp = iodev_valid[7:7];
 	tri1 [ 0:0] iodev_wait_n_esp;
 
-	wire [31:0] iodev_rdata_abc;
-	wire [ 0:0] iodev_irq_abc;
-	wire [ 0:0] iodev_valid_abc = iodev_valid[7:7];
-	tri1 [ 0:0] iodev_wait_n_abc;
-
-	wire [31:0] iodev_rdata_abcmemmap;
-	wire [ 0:0] iodev_valid_abcmemmap = xdev_valid[0:0];
-	tri1 [ 0:0] iodev_wait_n_abcmemmap;
-
-	wire [31:0] iodev_rdata_usbdesc;
-	wire [ 0:0] iodev_valid_usbdesc = xdev_valid[1:1];
-	tri1 [ 0:0] iodev_wait_n_usbdesc;
-
 	wire [31:0] iodev_rdata_random;
 	wire [ 0:0] iodev_irq_random;
 	wire [ 0:0] iodev_valid_random = iodev_valid[8:8];
@@ -76,13 +77,13 @@
 			2'd3:
 			case (cpu_mem_addr[10:7])
 				4'd0:	 iodev_rdata = iodev_rdata_sys;
-				4'd1:	 iodev_rdata = iodev_rdata_sysclock;
-				4'd2:	 iodev_rdata = iodev_rdata_console;
-				4'd3:	 iodev_rdata = iodev_rdata_romcopy;
-				4'd4:	 iodev_rdata = iodev_rdata_sdcard;
-				4'd5:	 iodev_rdata = iodev_rdata_i2c;
-				4'd6:	 iodev_rdata = iodev_rdata_esp;
-				4'd7:	 iodev_rdata = iodev_rdata_abc;
+				4'd1:	 iodev_rdata = iodev_rdata_abc;
+				4'd2:	 iodev_rdata = iodev_rdata_sysclock;
+				4'd3:	 iodev_rdata = iodev_rdata_console;
+				4'd4:	 iodev_rdata = iodev_rdata_romcopy;
+				4'd5:	 iodev_rdata = iodev_rdata_sdcard;
+				4'd6:	 iodev_rdata = iodev_rdata_i2c;
+				4'd7:	 iodev_rdata = iodev_rdata_esp;
 				4'd8:	 iodev_rdata = iodev_rdata_random;
 				default: iodev_rdata = 32'hxxxxxxxx;
 			endcase
@@ -90,26 +91,29 @@
 		endcase
 
 	tri0 [31:0] sys_irq;
-	assign sys_irq[ 3] = iodev_irq_sysclock[0];
-	assign sys_irq[ 4] = iodev_irq_console[0];
-	assign sys_irq[ 5] = iodev_irq_romcopy[0];
-	assign sys_irq[ 6] = iodev_irq_sdcard[0];
-	assign sys_irq[ 7] = iodev_irq_i2c[0];
-	assign sys_irq[ 8] = iodev_irq_esp[0];
-	assign sys_irq[ 9] = iodev_irq_abc[0];
-	assign sys_irq[10] = iodev_irq_random[0];
-
-	localparam [31:0] irq_edge_mask =  32'h00000008;
-	localparam [31:0] irq_masked    = ~32'h000007ff;
+	assign sys_irq[ 3] = iodev_irq_abc[0];
+	assign sys_irq[ 4] = iodev_irq_sysclock[0];
+	assign sys_irq[ 5] = iodev_irq_console[0];
+	assign sys_irq[ 6] = iodev_irq_console[1];
+	assign sys_irq[ 7] = iodev_irq_console[2];
+	assign sys_irq[ 8] = iodev_irq_console[3];
+	assign sys_irq[ 9] = iodev_irq_romcopy[0];
+	assign sys_irq[10] = iodev_irq_sdcard[0];
+	assign sys_irq[11] = iodev_irq_i2c[0];
+	assign sys_irq[12] = iodev_irq_esp[0];
+	assign sys_irq[13] = iodev_irq_random[0];
+
+	localparam [31:0] irq_edge_mask =  32'h00000010;
+	localparam [31:0] irq_masked    = ~32'h00003fff;
 
 	wire iodev_wait_n = (&iodev_wait_n_sys) & 
+		(&iodev_wait_n_abc) & 
+		(&iodev_wait_n_abcmemmap) & 
 		(&iodev_wait_n_sysclock) & 
 		(&iodev_wait_n_console) & 
+		(&iodev_wait_n_usbdesc) & 
 		(&iodev_wait_n_romcopy) & 
 		(&iodev_wait_n_sdcard) & 
 		(&iodev_wait_n_i2c) & 
 		(&iodev_wait_n_esp) & 
-		(&iodev_wait_n_abc) & 
-		(&iodev_wait_n_abcmemmap) & 
-		(&iodev_wait_n_usbdesc) & 
 		(&iodev_wait_n_random);

+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition
-# Date created = 20:03:37  January 08, 2022
+# Date created = 20:04:26  January 09, 2022
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "21.1"
-DATE = "20:03:37  January 08, 2022"
+DATE = "20:04:26  January 09, 2022"
 
 # Revisions
 

+ 1 - 1
fpga/max80.sv

@@ -709,7 +709,7 @@ module max80
 	    .tty_txd ( tty_data_out ) // DTE -> DCE
 	    );
 
-   max80_usb usb (
+   max80_usb #( .channels( CONSOLE_CHANNELS ) ) usb (
 		  .hard_rst_n         ( hard_rst_n ),
 		  .clock48            ( usb_clk ),
 

BIN
fpga/output/v1.jic


BIN
fpga/output/v1.sof


BIN
fpga/output/v2.jic


BIN
fpga/output/v2.sof


+ 1 - 1
fpga/usb/usb.sv

@@ -6,7 +6,7 @@
 //
 
 module max80_usb
-  #( parameter [2:0] channels = 3'd1 )
+  #( parameter [2:0] channels = 3'd4 )
    (
     input		  hard_rst_n,
     input		  clock48,

+ 8 - 5
fpga/usb/usb_desc.conf

@@ -3,13 +3,15 @@
 # Invoked from usbdescgen.pl
 #
 
+require '../../iodevs.conf';
+
 usb_languages('en_US', 'sv_SE');
 
 my $vendor_id    = word(0x1d50);
 my $device_id    = word(0x6149);
 my $version_id   = word(0x0100);
 
-my $serial       = usb_serial('_serial_str_');
+my $serial       = usb_serial('_Serial_???_');
 my $manufacturer = usb_string(''   => 'Peter & Per');
 my $product      = usb_string(''   => 'MAX80 I/O card for ABC');
 
@@ -21,7 +23,8 @@ sub acm_channels($$) {
 	my $ep_data = $ep_base + ($c << 1);
 	my $ep_intr = $ep_data + 1;
 
-	my $mgmt_if, $data_if;
+	my $mgmt_if;
+	my $data_if;
 
 	push(@d,
 		# Interface association descriptor
@@ -111,14 +114,14 @@ usb_device {
 		     byte(0xc0),	 # Self or bus powered
 		     byte(500 >> 1)),	 # Up to 500 mA
 
-		# Descriptors for each ACM channel
-		acm_channels(1,1)	# 1 channel starting at EP 1
+		# Descriptors for each ACM channel, starting at endpoint 1
+		acm_channels($consts{'CONSOLE_CHANNELS'},1)
     },
 };
 
 usb_additional_data {
     # Line state structure
-    dword(115200),		# Baud rate
+    dword(38400),		# Baud rate (largest POSIX required value)
 	byte(0),		# 1 stop bit
 	byte(0),		# No parity
 	byte(8)			# 8 data bits

+ 419 - 221
fpga/usb/usb_desc.v

@@ -5,223 +5,421 @@
 module usb_desc_rom (
 	input clk,
 
-	input [7:0] usb_addr,
+	input [8:0] usb_addr,
 	output [7:0] usb_rdata,
 
 	input cpu_clk,
-	input [7:0] cpu_addr,
+	input [8:0] cpu_addr,
 	output [7:0] cpu_rdata,
 	input [7:0] cpu_wdata,
 	input cpu_wren
 );
 
-	reg [7:0] rom [0:255];
+	reg [7:0] rom [0:511];
 
 	initial begin
-		rom[8'h00] = 8'h1a;
-		rom[8'h01] = 8'h03;
-		rom[8'h02] = 8'h5f;
-		rom[8'h03] = 8'h00;
-		rom[8'h04] = 8'h73;
-		rom[8'h05] = 8'h00;
-		rom[8'h06] = 8'h65;
-		rom[8'h07] = 8'h00;
-		rom[8'h08] = 8'h72;
-		rom[8'h09] = 8'h00;
-		rom[8'h0a] = 8'h69;
-		rom[8'h0b] = 8'h00;
-		rom[8'h0c] = 8'h61;
-		rom[8'h0d] = 8'h00;
-		rom[8'h0e] = 8'h6c;
-		rom[8'h0f] = 8'h00;
-		rom[8'h10] = 8'h5f;
-		rom[8'h11] = 8'h00;
-		rom[8'h12] = 8'h73;
-		rom[8'h13] = 8'h00;
-		rom[8'h14] = 8'h74;
-		rom[8'h15] = 8'h00;
-		rom[8'h16] = 8'h72;
-		rom[8'h17] = 8'h00;
-		rom[8'h18] = 8'h5f;
-		rom[8'h19] = 8'h00;
-		rom[8'h1a] = 8'h12;
-		rom[8'h1b] = 8'h01;
-		rom[8'h1c] = 8'h01;
-		rom[8'h1d] = 8'h01;
-		rom[8'h1e] = 8'h00;
-		rom[8'h1f] = 8'h00;
-		rom[8'h20] = 8'h00;
-		rom[8'h21] = 8'h08;
-		rom[8'h22] = 8'h50;
-		rom[8'h23] = 8'h1d;
-		rom[8'h24] = 8'h49;
-		rom[8'h25] = 8'h61;
-		rom[8'h26] = 8'h00;
-		rom[8'h27] = 8'h01;
-		rom[8'h28] = 8'h02;
-		rom[8'h29] = 8'h03;
-		rom[8'h2a] = 8'h01;
-		rom[8'h2b] = 8'h01;
-		rom[8'h2c] = 8'h09;
-		rom[8'h2d] = 8'h02;
-		rom[8'h2e] = 8'h4b;
-		rom[8'h2f] = 8'h00;
-		rom[8'h30] = 8'h02;
-		rom[8'h31] = 8'h01;
-		rom[8'h32] = 8'h04;
-		rom[8'h33] = 8'hc0;
-		rom[8'h34] = 8'hfa;
-		rom[8'h35] = 8'h08;
-		rom[8'h36] = 8'h0b;
-		rom[8'h37] = 8'h00;
-		rom[8'h38] = 8'h02;
-		rom[8'h39] = 8'h02;
-		rom[8'h3a] = 8'h02;
-		rom[8'h3b] = 8'h01;
-		rom[8'h3c] = 8'h04;
-		rom[8'h3d] = 8'h09;
-		rom[8'h3e] = 8'h04;
-		rom[8'h3f] = 8'h00;
-		rom[8'h40] = 8'h00;
-		rom[8'h41] = 8'h01;
-		rom[8'h42] = 8'h02;
-		rom[8'h43] = 8'h02;
-		rom[8'h44] = 8'h01;
-		rom[8'h45] = 8'h04;
-		rom[8'h46] = 8'h05;
-		rom[8'h47] = 8'h24;
-		rom[8'h48] = 8'h00;
-		rom[8'h49] = 8'h20;
-		rom[8'h4a] = 8'h01;
-		rom[8'h4b] = 8'h05;
-		rom[8'h4c] = 8'h24;
-		rom[8'h4d] = 8'h01;
-		rom[8'h4e] = 8'h03;
-		rom[8'h4f] = 8'h01;
-		rom[8'h50] = 8'h04;
-		rom[8'h51] = 8'h24;
-		rom[8'h52] = 8'h02;
-		rom[8'h53] = 8'h04;
-		rom[8'h54] = 8'h05;
-		rom[8'h55] = 8'h24;
-		rom[8'h56] = 8'h06;
-		rom[8'h57] = 8'h00;
-		rom[8'h58] = 8'h01;
-		rom[8'h59] = 8'h07;
-		rom[8'h5a] = 8'h05;
-		rom[8'h5b] = 8'h82;
-		rom[8'h5c] = 8'h03;
-		rom[8'h5d] = 8'h40;
-		rom[8'h5e] = 8'h00;
-		rom[8'h5f] = 8'h02;
-		rom[8'h60] = 8'h09;
-		rom[8'h61] = 8'h04;
-		rom[8'h62] = 8'h01;
-		rom[8'h63] = 8'h00;
-		rom[8'h64] = 8'h02;
-		rom[8'h65] = 8'h0a;
-		rom[8'h66] = 8'h00;
-		rom[8'h67] = 8'h00;
-		rom[8'h68] = 8'h04;
-		rom[8'h69] = 8'h07;
-		rom[8'h6a] = 8'h05;
-		rom[8'h6b] = 8'h81;
-		rom[8'h6c] = 8'h02;
-		rom[8'h6d] = 8'h40;
-		rom[8'h6e] = 8'h00;
-		rom[8'h6f] = 8'h00;
-		rom[8'h70] = 8'h07;
-		rom[8'h71] = 8'h05;
-		rom[8'h72] = 8'h01;
-		rom[8'h73] = 8'h02;
-		rom[8'h74] = 8'h40;
-		rom[8'h75] = 8'h00;
-		rom[8'h76] = 8'h00;
-		rom[8'h77] = 8'h06;
-		rom[8'h78] = 8'h03;
-		rom[8'h79] = 8'h09;
-		rom[8'h7a] = 8'h04;
-		rom[8'h7b] = 8'h1d;
-		rom[8'h7c] = 8'h04;
-		rom[8'h7d] = 8'h18;
-		rom[8'h7e] = 8'h03;
-		rom[8'h7f] = 8'h50;
-		rom[8'h80] = 8'h00;
-		rom[8'h81] = 8'h65;
-		rom[8'h82] = 8'h00;
-		rom[8'h83] = 8'h74;
-		rom[8'h84] = 8'h00;
-		rom[8'h85] = 8'h65;
-		rom[8'h86] = 8'h00;
-		rom[8'h87] = 8'h72;
-		rom[8'h88] = 8'h00;
-		rom[8'h89] = 8'h20;
-		rom[8'h8a] = 8'h00;
-		rom[8'h8b] = 8'h26;
-		rom[8'h8c] = 8'h00;
-		rom[8'h8d] = 8'h20;
-		rom[8'h8e] = 8'h00;
-		rom[8'h8f] = 8'h50;
-		rom[8'h90] = 8'h00;
-		rom[8'h91] = 8'h65;
-		rom[8'h92] = 8'h00;
-		rom[8'h93] = 8'h72;
-		rom[8'h94] = 8'h00;
-		rom[8'h95] = 8'h2e;
-		rom[8'h96] = 8'h03;
-		rom[8'h97] = 8'h4d;
-		rom[8'h98] = 8'h00;
-		rom[8'h99] = 8'h41;
-		rom[8'h9a] = 8'h00;
-		rom[8'h9b] = 8'h58;
-		rom[8'h9c] = 8'h00;
-		rom[8'h9d] = 8'h38;
-		rom[8'h9e] = 8'h00;
-		rom[8'h9f] = 8'h30;
-		rom[8'ha0] = 8'h00;
-		rom[8'ha1] = 8'h20;
-		rom[8'ha2] = 8'h00;
-		rom[8'ha3] = 8'h49;
-		rom[8'ha4] = 8'h00;
-		rom[8'ha5] = 8'h2f;
-		rom[8'ha6] = 8'h00;
-		rom[8'ha7] = 8'h4f;
-		rom[8'ha8] = 8'h00;
-		rom[8'ha9] = 8'h20;
-		rom[8'haa] = 8'h00;
-		rom[8'hab] = 8'h63;
-		rom[8'hac] = 8'h00;
-		rom[8'had] = 8'h61;
-		rom[8'hae] = 8'h00;
-		rom[8'haf] = 8'h72;
-		rom[8'hb0] = 8'h00;
-		rom[8'hb1] = 8'h64;
-		rom[8'hb2] = 8'h00;
-		rom[8'hb3] = 8'h20;
-		rom[8'hb4] = 8'h00;
-		rom[8'hb5] = 8'h66;
-		rom[8'hb6] = 8'h00;
-		rom[8'hb7] = 8'h6f;
-		rom[8'hb8] = 8'h00;
-		rom[8'hb9] = 8'h72;
-		rom[8'hba] = 8'h00;
-		rom[8'hbb] = 8'h20;
-		rom[8'hbc] = 8'h00;
-		rom[8'hbd] = 8'h41;
-		rom[8'hbe] = 8'h00;
-		rom[8'hbf] = 8'h42;
-		rom[8'hc0] = 8'h00;
-		rom[8'hc1] = 8'h43;
-		rom[8'hc2] = 8'h00;
-		rom[8'hc3] = 8'h02;
-		rom[8'hc4] = 8'h03;
-		rom[8'hc5] = 8'h00;
-		rom[8'hc6] = 8'hc2;
-		rom[8'hc7] = 8'h01;
-		rom[8'hc8] = 8'h00;
-		rom[8'hc9] = 8'h00;
-		rom[8'hca] = 8'h00;
-		rom[8'hcb] = 8'h08;
+		rom[9'h000] = 8'h1a;
+		rom[9'h001] = 8'h03;
+		rom[9'h002] = 8'h5f;
+		rom[9'h003] = 8'h00;
+		rom[9'h004] = 8'h53;
+		rom[9'h005] = 8'h00;
+		rom[9'h006] = 8'h65;
+		rom[9'h007] = 8'h00;
+		rom[9'h008] = 8'h72;
+		rom[9'h009] = 8'h00;
+		rom[9'h00a] = 8'h69;
+		rom[9'h00b] = 8'h00;
+		rom[9'h00c] = 8'h61;
+		rom[9'h00d] = 8'h00;
+		rom[9'h00e] = 8'h6c;
+		rom[9'h00f] = 8'h00;
+		rom[9'h010] = 8'h5f;
+		rom[9'h011] = 8'h00;
+		rom[9'h012] = 8'h3f;
+		rom[9'h013] = 8'h00;
+		rom[9'h014] = 8'h3f;
+		rom[9'h015] = 8'h00;
+		rom[9'h016] = 8'h3f;
+		rom[9'h017] = 8'h00;
+		rom[9'h018] = 8'h5f;
+		rom[9'h019] = 8'h00;
+		rom[9'h01a] = 8'h12;
+		rom[9'h01b] = 8'h01;
+		rom[9'h01c] = 8'h01;
+		rom[9'h01d] = 8'h01;
+		rom[9'h01e] = 8'h00;
+		rom[9'h01f] = 8'h00;
+		rom[9'h020] = 8'h00;
+		rom[9'h021] = 8'h08;
+		rom[9'h022] = 8'h50;
+		rom[9'h023] = 8'h1d;
+		rom[9'h024] = 8'h49;
+		rom[9'h025] = 8'h61;
+		rom[9'h026] = 8'h00;
+		rom[9'h027] = 8'h01;
+		rom[9'h028] = 8'h02;
+		rom[9'h029] = 8'h03;
+		rom[9'h02a] = 8'h01;
+		rom[9'h02b] = 8'h01;
+		rom[9'h02c] = 8'h09;
+		rom[9'h02d] = 8'h02;
+		rom[9'h02e] = 8'h11;
+		rom[9'h02f] = 8'h01;
+		rom[9'h030] = 8'h08;
+		rom[9'h031] = 8'h01;
+		rom[9'h032] = 8'h04;
+		rom[9'h033] = 8'hc0;
+		rom[9'h034] = 8'hfa;
+		rom[9'h035] = 8'h08;
+		rom[9'h036] = 8'h0b;
+		rom[9'h037] = 8'h00;
+		rom[9'h038] = 8'h02;
+		rom[9'h039] = 8'h02;
+		rom[9'h03a] = 8'h02;
+		rom[9'h03b] = 8'h01;
+		rom[9'h03c] = 8'h04;
+		rom[9'h03d] = 8'h09;
+		rom[9'h03e] = 8'h04;
+		rom[9'h03f] = 8'h00;
+		rom[9'h040] = 8'h00;
+		rom[9'h041] = 8'h01;
+		rom[9'h042] = 8'h02;
+		rom[9'h043] = 8'h02;
+		rom[9'h044] = 8'h01;
+		rom[9'h045] = 8'h04;
+		rom[9'h046] = 8'h05;
+		rom[9'h047] = 8'h24;
+		rom[9'h048] = 8'h00;
+		rom[9'h049] = 8'h20;
+		rom[9'h04a] = 8'h01;
+		rom[9'h04b] = 8'h05;
+		rom[9'h04c] = 8'h24;
+		rom[9'h04d] = 8'h01;
+		rom[9'h04e] = 8'h03;
+		rom[9'h04f] = 8'h01;
+		rom[9'h050] = 8'h04;
+		rom[9'h051] = 8'h24;
+		rom[9'h052] = 8'h02;
+		rom[9'h053] = 8'h04;
+		rom[9'h054] = 8'h05;
+		rom[9'h055] = 8'h24;
+		rom[9'h056] = 8'h06;
+		rom[9'h057] = 8'h00;
+		rom[9'h058] = 8'h01;
+		rom[9'h059] = 8'h07;
+		rom[9'h05a] = 8'h05;
+		rom[9'h05b] = 8'h82;
+		rom[9'h05c] = 8'h03;
+		rom[9'h05d] = 8'h40;
+		rom[9'h05e] = 8'h00;
+		rom[9'h05f] = 8'h02;
+		rom[9'h060] = 8'h09;
+		rom[9'h061] = 8'h04;
+		rom[9'h062] = 8'h01;
+		rom[9'h063] = 8'h00;
+		rom[9'h064] = 8'h02;
+		rom[9'h065] = 8'h0a;
+		rom[9'h066] = 8'h00;
+		rom[9'h067] = 8'h00;
+		rom[9'h068] = 8'h04;
+		rom[9'h069] = 8'h07;
+		rom[9'h06a] = 8'h05;
+		rom[9'h06b] = 8'h81;
+		rom[9'h06c] = 8'h02;
+		rom[9'h06d] = 8'h40;
+		rom[9'h06e] = 8'h00;
+		rom[9'h06f] = 8'h00;
+		rom[9'h070] = 8'h07;
+		rom[9'h071] = 8'h05;
+		rom[9'h072] = 8'h01;
+		rom[9'h073] = 8'h02;
+		rom[9'h074] = 8'h40;
+		rom[9'h075] = 8'h00;
+		rom[9'h076] = 8'h00;
+		rom[9'h077] = 8'h08;
+		rom[9'h078] = 8'h0b;
+		rom[9'h079] = 8'h02;
+		rom[9'h07a] = 8'h02;
+		rom[9'h07b] = 8'h02;
+		rom[9'h07c] = 8'h02;
+		rom[9'h07d] = 8'h01;
+		rom[9'h07e] = 8'h04;
+		rom[9'h07f] = 8'h09;
+		rom[9'h080] = 8'h04;
+		rom[9'h081] = 8'h02;
+		rom[9'h082] = 8'h00;
+		rom[9'h083] = 8'h01;
+		rom[9'h084] = 8'h02;
+		rom[9'h085] = 8'h02;
+		rom[9'h086] = 8'h01;
+		rom[9'h087] = 8'h04;
+		rom[9'h088] = 8'h05;
+		rom[9'h089] = 8'h24;
+		rom[9'h08a] = 8'h00;
+		rom[9'h08b] = 8'h20;
+		rom[9'h08c] = 8'h01;
+		rom[9'h08d] = 8'h05;
+		rom[9'h08e] = 8'h24;
+		rom[9'h08f] = 8'h01;
+		rom[9'h090] = 8'h03;
+		rom[9'h091] = 8'h03;
+		rom[9'h092] = 8'h04;
+		rom[9'h093] = 8'h24;
+		rom[9'h094] = 8'h02;
+		rom[9'h095] = 8'h04;
+		rom[9'h096] = 8'h05;
+		rom[9'h097] = 8'h24;
+		rom[9'h098] = 8'h06;
+		rom[9'h099] = 8'h02;
+		rom[9'h09a] = 8'h03;
+		rom[9'h09b] = 8'h07;
+		rom[9'h09c] = 8'h05;
+		rom[9'h09d] = 8'h84;
+		rom[9'h09e] = 8'h03;
+		rom[9'h09f] = 8'h40;
+		rom[9'h0a0] = 8'h00;
+		rom[9'h0a1] = 8'h02;
+		rom[9'h0a2] = 8'h09;
+		rom[9'h0a3] = 8'h04;
+		rom[9'h0a4] = 8'h03;
+		rom[9'h0a5] = 8'h00;
+		rom[9'h0a6] = 8'h02;
+		rom[9'h0a7] = 8'h0a;
+		rom[9'h0a8] = 8'h00;
+		rom[9'h0a9] = 8'h00;
+		rom[9'h0aa] = 8'h04;
+		rom[9'h0ab] = 8'h07;
+		rom[9'h0ac] = 8'h05;
+		rom[9'h0ad] = 8'h83;
+		rom[9'h0ae] = 8'h02;
+		rom[9'h0af] = 8'h40;
+		rom[9'h0b0] = 8'h00;
+		rom[9'h0b1] = 8'h00;
+		rom[9'h0b2] = 8'h07;
+		rom[9'h0b3] = 8'h05;
+		rom[9'h0b4] = 8'h03;
+		rom[9'h0b5] = 8'h02;
+		rom[9'h0b6] = 8'h40;
+		rom[9'h0b7] = 8'h00;
+		rom[9'h0b8] = 8'h00;
+		rom[9'h0b9] = 8'h08;
+		rom[9'h0ba] = 8'h0b;
+		rom[9'h0bb] = 8'h04;
+		rom[9'h0bc] = 8'h02;
+		rom[9'h0bd] = 8'h02;
+		rom[9'h0be] = 8'h02;
+		rom[9'h0bf] = 8'h01;
+		rom[9'h0c0] = 8'h04;
+		rom[9'h0c1] = 8'h09;
+		rom[9'h0c2] = 8'h04;
+		rom[9'h0c3] = 8'h04;
+		rom[9'h0c4] = 8'h00;
+		rom[9'h0c5] = 8'h01;
+		rom[9'h0c6] = 8'h02;
+		rom[9'h0c7] = 8'h02;
+		rom[9'h0c8] = 8'h01;
+		rom[9'h0c9] = 8'h04;
+		rom[9'h0ca] = 8'h05;
+		rom[9'h0cb] = 8'h24;
+		rom[9'h0cc] = 8'h00;
+		rom[9'h0cd] = 8'h20;
+		rom[9'h0ce] = 8'h01;
+		rom[9'h0cf] = 8'h05;
+		rom[9'h0d0] = 8'h24;
+		rom[9'h0d1] = 8'h01;
+		rom[9'h0d2] = 8'h03;
+		rom[9'h0d3] = 8'h05;
+		rom[9'h0d4] = 8'h04;
+		rom[9'h0d5] = 8'h24;
+		rom[9'h0d6] = 8'h02;
+		rom[9'h0d7] = 8'h04;
+		rom[9'h0d8] = 8'h05;
+		rom[9'h0d9] = 8'h24;
+		rom[9'h0da] = 8'h06;
+		rom[9'h0db] = 8'h04;
+		rom[9'h0dc] = 8'h05;
+		rom[9'h0dd] = 8'h07;
+		rom[9'h0de] = 8'h05;
+		rom[9'h0df] = 8'h86;
+		rom[9'h0e0] = 8'h03;
+		rom[9'h0e1] = 8'h40;
+		rom[9'h0e2] = 8'h00;
+		rom[9'h0e3] = 8'h02;
+		rom[9'h0e4] = 8'h09;
+		rom[9'h0e5] = 8'h04;
+		rom[9'h0e6] = 8'h05;
+		rom[9'h0e7] = 8'h00;
+		rom[9'h0e8] = 8'h02;
+		rom[9'h0e9] = 8'h0a;
+		rom[9'h0ea] = 8'h00;
+		rom[9'h0eb] = 8'h00;
+		rom[9'h0ec] = 8'h04;
+		rom[9'h0ed] = 8'h07;
+		rom[9'h0ee] = 8'h05;
+		rom[9'h0ef] = 8'h85;
+		rom[9'h0f0] = 8'h02;
+		rom[9'h0f1] = 8'h40;
+		rom[9'h0f2] = 8'h00;
+		rom[9'h0f3] = 8'h00;
+		rom[9'h0f4] = 8'h07;
+		rom[9'h0f5] = 8'h05;
+		rom[9'h0f6] = 8'h05;
+		rom[9'h0f7] = 8'h02;
+		rom[9'h0f8] = 8'h40;
+		rom[9'h0f9] = 8'h00;
+		rom[9'h0fa] = 8'h00;
+		rom[9'h0fb] = 8'h08;
+		rom[9'h0fc] = 8'h0b;
+		rom[9'h0fd] = 8'h06;
+		rom[9'h0fe] = 8'h02;
+		rom[9'h0ff] = 8'h02;
+		rom[9'h100] = 8'h02;
+		rom[9'h101] = 8'h01;
+		rom[9'h102] = 8'h04;
+		rom[9'h103] = 8'h09;
+		rom[9'h104] = 8'h04;
+		rom[9'h105] = 8'h06;
+		rom[9'h106] = 8'h00;
+		rom[9'h107] = 8'h01;
+		rom[9'h108] = 8'h02;
+		rom[9'h109] = 8'h02;
+		rom[9'h10a] = 8'h01;
+		rom[9'h10b] = 8'h04;
+		rom[9'h10c] = 8'h05;
+		rom[9'h10d] = 8'h24;
+		rom[9'h10e] = 8'h00;
+		rom[9'h10f] = 8'h20;
+		rom[9'h110] = 8'h01;
+		rom[9'h111] = 8'h05;
+		rom[9'h112] = 8'h24;
+		rom[9'h113] = 8'h01;
+		rom[9'h114] = 8'h03;
+		rom[9'h115] = 8'h07;
+		rom[9'h116] = 8'h04;
+		rom[9'h117] = 8'h24;
+		rom[9'h118] = 8'h02;
+		rom[9'h119] = 8'h04;
+		rom[9'h11a] = 8'h05;
+		rom[9'h11b] = 8'h24;
+		rom[9'h11c] = 8'h06;
+		rom[9'h11d] = 8'h06;
+		rom[9'h11e] = 8'h07;
+		rom[9'h11f] = 8'h07;
+		rom[9'h120] = 8'h05;
+		rom[9'h121] = 8'h88;
+		rom[9'h122] = 8'h03;
+		rom[9'h123] = 8'h40;
+		rom[9'h124] = 8'h00;
+		rom[9'h125] = 8'h02;
+		rom[9'h126] = 8'h09;
+		rom[9'h127] = 8'h04;
+		rom[9'h128] = 8'h07;
+		rom[9'h129] = 8'h00;
+		rom[9'h12a] = 8'h02;
+		rom[9'h12b] = 8'h0a;
+		rom[9'h12c] = 8'h00;
+		rom[9'h12d] = 8'h00;
+		rom[9'h12e] = 8'h04;
+		rom[9'h12f] = 8'h07;
+		rom[9'h130] = 8'h05;
+		rom[9'h131] = 8'h87;
+		rom[9'h132] = 8'h02;
+		rom[9'h133] = 8'h40;
+		rom[9'h134] = 8'h00;
+		rom[9'h135] = 8'h00;
+		rom[9'h136] = 8'h07;
+		rom[9'h137] = 8'h05;
+		rom[9'h138] = 8'h07;
+		rom[9'h139] = 8'h02;
+		rom[9'h13a] = 8'h40;
+		rom[9'h13b] = 8'h00;
+		rom[9'h13c] = 8'h00;
+		rom[9'h13d] = 8'h06;
+		rom[9'h13e] = 8'h03;
+		rom[9'h13f] = 8'h09;
+		rom[9'h140] = 8'h04;
+		rom[9'h141] = 8'h1d;
+		rom[9'h142] = 8'h04;
+		rom[9'h143] = 8'h18;
+		rom[9'h144] = 8'h03;
+		rom[9'h145] = 8'h50;
+		rom[9'h146] = 8'h00;
+		rom[9'h147] = 8'h65;
+		rom[9'h148] = 8'h00;
+		rom[9'h149] = 8'h74;
+		rom[9'h14a] = 8'h00;
+		rom[9'h14b] = 8'h65;
+		rom[9'h14c] = 8'h00;
+		rom[9'h14d] = 8'h72;
+		rom[9'h14e] = 8'h00;
+		rom[9'h14f] = 8'h20;
+		rom[9'h150] = 8'h00;
+		rom[9'h151] = 8'h26;
+		rom[9'h152] = 8'h00;
+		rom[9'h153] = 8'h20;
+		rom[9'h154] = 8'h00;
+		rom[9'h155] = 8'h50;
+		rom[9'h156] = 8'h00;
+		rom[9'h157] = 8'h65;
+		rom[9'h158] = 8'h00;
+		rom[9'h159] = 8'h72;
+		rom[9'h15a] = 8'h00;
+		rom[9'h15b] = 8'h2e;
+		rom[9'h15c] = 8'h03;
+		rom[9'h15d] = 8'h4d;
+		rom[9'h15e] = 8'h00;
+		rom[9'h15f] = 8'h41;
+		rom[9'h160] = 8'h00;
+		rom[9'h161] = 8'h58;
+		rom[9'h162] = 8'h00;
+		rom[9'h163] = 8'h38;
+		rom[9'h164] = 8'h00;
+		rom[9'h165] = 8'h30;
+		rom[9'h166] = 8'h00;
+		rom[9'h167] = 8'h20;
+		rom[9'h168] = 8'h00;
+		rom[9'h169] = 8'h49;
+		rom[9'h16a] = 8'h00;
+		rom[9'h16b] = 8'h2f;
+		rom[9'h16c] = 8'h00;
+		rom[9'h16d] = 8'h4f;
+		rom[9'h16e] = 8'h00;
+		rom[9'h16f] = 8'h20;
+		rom[9'h170] = 8'h00;
+		rom[9'h171] = 8'h63;
+		rom[9'h172] = 8'h00;
+		rom[9'h173] = 8'h61;
+		rom[9'h174] = 8'h00;
+		rom[9'h175] = 8'h72;
+		rom[9'h176] = 8'h00;
+		rom[9'h177] = 8'h64;
+		rom[9'h178] = 8'h00;
+		rom[9'h179] = 8'h20;
+		rom[9'h17a] = 8'h00;
+		rom[9'h17b] = 8'h66;
+		rom[9'h17c] = 8'h00;
+		rom[9'h17d] = 8'h6f;
+		rom[9'h17e] = 8'h00;
+		rom[9'h17f] = 8'h72;
+		rom[9'h180] = 8'h00;
+		rom[9'h181] = 8'h20;
+		rom[9'h182] = 8'h00;
+		rom[9'h183] = 8'h41;
+		rom[9'h184] = 8'h00;
+		rom[9'h185] = 8'h42;
+		rom[9'h186] = 8'h00;
+		rom[9'h187] = 8'h43;
+		rom[9'h188] = 8'h00;
+		rom[9'h189] = 8'h02;
+		rom[9'h18a] = 8'h03;
+		rom[9'h18b] = 8'h00;
+		rom[9'h18c] = 8'h96;
+		rom[9'h18d] = 8'h00;
+		rom[9'h18e] = 8'h00;
+		rom[9'h18f] = 8'h00;
+		rom[9'h190] = 8'h00;
+		rom[9'h191] = 8'h08;
 	end
 
 	always @(posedge clk) begin
@@ -241,24 +439,24 @@ module usb_desc_index (
 	input [15:0] windex,
 	input 	     additional,
 
-	output reg [7:0] addr,
-	output reg [7:0] len
+	output reg [8:0] addr,
+	output reg [8:0] len
 );
 
 	always @(*)
        	if (additional)
-		{addr,len} = {8'hc5,8'h07};
+		{addr,len} = {9'h18b,9'h007};
 	else priority casez ({windex,dindex,dtype})
-		32'b??????00_00011101_00000010_00000011: {addr,len} = {8'h7d,8'h18};
-		32'b??????00_00011101_00000011_00000011: {addr,len} = {8'h95,8'h2e};
-		32'b??????00_00011101_00000100_00000011: {addr,len} = {8'hc3,8'h02};
-		32'b????????_????????_00000000_00000010: {addr,len} = {8'h2c,8'h4b};
-		32'b????????_????????_00000000_00000011: {addr,len} = {8'h77,8'h06};
-		32'b????????_????????_00000001_00000011: {addr,len} = {8'h00,8'h1a};
-		32'b????????_????????_00000010_00000011: {addr,len} = {8'h7d,8'h18};
-		32'b????????_????????_00000011_00000011: {addr,len} = {8'h95,8'h2e};
-		32'b????????_????????_00000100_00000011: {addr,len} = {8'hc3,8'h02};
-		32'b????????_????????_????????_00000001: {addr,len} = {8'h1a,8'h12};
-		32'b????????_????????_????????_????????: {addr,len} = {8'hxx,8'h00};
+		32'b??????00_00011101_00000010_00000011: {addr,len} = {9'h143,9'h018};
+		32'b??????00_00011101_00000011_00000011: {addr,len} = {9'h15b,9'h02e};
+		32'b??????00_00011101_00000100_00000011: {addr,len} = {9'h189,9'h002};
+		32'b????????_????????_00000000_00000010: {addr,len} = {9'h02c,9'h111};
+		32'b????????_????????_00000000_00000011: {addr,len} = {9'h13d,9'h006};
+		32'b????????_????????_00000001_00000011: {addr,len} = {9'h000,9'h01a};
+		32'b????????_????????_00000010_00000011: {addr,len} = {9'h143,9'h018};
+		32'b????????_????????_00000011_00000011: {addr,len} = {9'h15b,9'h02e};
+		32'b????????_????????_00000100_00000011: {addr,len} = {9'h189,9'h002};
+		32'b????????_????????_????????_00000001: {addr,len} = {9'h01a,9'h012};
+		32'b????????_????????_????????_????????: {addr,len} = {9'hxxx,9'h000};
 	endcase
 endmodule

+ 9 - 5
iodevs.conf

@@ -12,7 +12,8 @@ our %consts = (
     'SDRAM_ADDR' => 0x40000000,
     'SDRAM_BITS' => 25,
     'SYS_MAGIC_MAX80' => unpack('V', 'MAX8'),
-    'TIMER_SHIFT' => 5		# 32 Hz
+    'TIMER_SHIFT' => 5,		# 32 Hz
+    'CONSOLE_CHANNELS' => 4
     );
 
 # I/O address definitions
@@ -28,14 +29,17 @@ our @sysirqs = ('timer', 'ebreak', 'buserr');
 # for a corresponding number of IRQs.
 our @iodevs = (
     { -name => 'sys' },
+
+    { -name => 'abc',       -irq => 'l' },
+    { -name => 'abcmemmap', -xdev => 1 },
+
     { -name => 'sysclock',  -irq => 'e' },
-    { -name => 'console',   -irq => 'l' },
+    { -name => 'console',   -irq => 'l' x $consts{'CONSOLE_CHANNELS'} },
+    { -name => 'usbdesc',   -xdev => 1 },
+
     { -name => 'romcopy',   -irq => 'l' },
     { -name => 'sdcard',    -irq => 'l' },
     { -name => 'i2c',       -irq => 'l' },
     { -name => 'esp',       -irq => 'l' },
-    { -name => 'abc',       -irq => 'l' },
-    { -name => 'abcmemmap', -xdev => 1 },
-    { -name => 'usbdesc',   -xdev => 1 },
     { -name => 'random',    -irq => 'l' }
 );

+ 9 - 5
rv32/abcio.h

@@ -9,11 +9,15 @@
 struct abc_dev;
 
 /* Called from an interrupt handler, so hot */
-#define ABC_CALLBACK(func)						\
-    void __hot func(struct abc_dev *dev __attribute__((unused)),	\
-		    uint8_t data __attribute__((unused)),		\
-		    uint8_t addr __attribute__((unused)))
-typedef ABC_CALLBACK((*abc_callback_t));
+#define ABC_CALLBACK_DECL(func)						\
+    void func(struct abc_dev *dev __unused,				\
+	      uint8_t data __unused,					\
+	      uint8_t addr __unused)
+
+#define ABC_CALLBACK(func)			\
+    __hot ABC_CALLBACK_DECL(func)
+
+typedef ABC_CALLBACK_DECL((*abc_callback_t));
 
 struct abc_dev {
     uint8_t *out_buf;

File diff suppressed because it is too large
+ 811 - 811
rv32/boot.mif


+ 6 - 6
rv32/irq.h

@@ -7,12 +7,12 @@
 typedef void (*irqhandler_t)(unsigned int vector, size_t pc);
 extern irqhandler_t __irq_handler_table[];
 
-#define IRQHANDLER_DECL(x) \
-  void __hot __text_hot irqhandler_ ##x (unsigned int vector __unused,	\
-					 size_t pc __unused)
-#define IRQHANDLER(x)	\
-  IRQHANDLER_DECL(x);	\
-  IRQHANDLER_DECL(x)
+#define IRQHANDLER_DECL(x)						\
+    void irqhandler_ ##x (unsigned int vector __unused,			\
+			  size_t pc __unused)
+#define IRQHANDLER(x)				\
+    IRQHANDLER_DECL(x);				\
+    __hot __text_hot IRQHANDLER_DECL(x)
 
 typedef unsigned int irqmask_t;
 

+ 3 - 3
rv32/spurious_irq.c

@@ -9,8 +9,8 @@ IRQHANDLER(spurious)
     mask_irq(vector);
 }
 
-#define IRQENTRY(name,irqn,irqbase,irqcount)	\
-  IRQHANDLER_DECL(name) \
-    __attribute__((weak,alias("irqhandler_spurious")));
+#define IRQENTRIES(name,irqbase,irqcount)			\
+    IRQHANDLER_DECL(name)					\
+	__attribute__((weak,alias("irqhandler_spurious")));
 
 #include "irqtable.h"

+ 12 - 1
tools/iodevs.pl

@@ -87,6 +87,14 @@ sub generate_irqtbl($)
 
     print $out "/* This is a generated file */\n\n";
 
+    print $out "#ifndef IRQENTRIES\n";
+    print $out "#define IRQENTRIES(name,irqbase,irqcount)\n";
+    print $out "#endif\n\n";
+
+    print $out "#ifndef IRQENTRY\n";
+    print $out "#define IRQENTRY(name,irqbase,irqn,irqcount)\n";
+    print $out "#endif\n\n";
+
     foreach my $sysirq (@sysirqs) {
 	push(@irqtbl, [$sysirq, 1]);
 	$nirq++;
@@ -108,10 +116,13 @@ sub generate_irqtbl($)
 
     my $dirq = 0;
     foreach my $irq (@irqtbl) {
+	printf $out "IRQENTRIES(%s,%d,%d)\n",
+	    $irq->[0], $dirq, $irq->[1];
 	for (my $i = 0; $i < $irq->[1]; $i++) {
 	    printf $out "IRQENTRY(%s,%d,%d,%d)\n",
-		$irq->[0], $dirq++, $i, $irq->[1];
+		$irq->[0], $dirq, $i, $irq->[1];
 	}
+	$dirq += $irq->[1];
     }
 }
 

Some files were not shown because too many files changed in this diff