windowsでiverilog その156

# 概要　
windowsでiverilogやってみた。
RP2040な、verilog見つけたので、テストベンチ書いてみた。

# 投入したpioasm

```
.program uart_tx
.side_set 1 opt
    pull block    side 1
    set x 7       side 0 [7]
again:
    out pins 1
    jmp x-- again        [6]

```

# サンプルコード

```
`timescale 1ns/100ps
module test();
	localparam NONE = 0;
	localparam INSTR = 1;
	localparam PEND = 2;
	localparam PULL = 3;
	localparam PUSH = 4;
	localparam GRPS = 5;
	localparam EN = 6;
	localparam DIV = 7;
	localparam SIDES = 8;
	localparam IMM = 9;
	localparam SHIFT = 10;
	reg clk;
	reg reset;
	reg [31:0] din;
	reg [4:0] index;
	reg [3:0] action;
	reg [1:0] mindex;
	reg [31:0] gpio_in = 0;
	reg [15:0] program [0:31];
	wire [31:0] gpio_out;
	wire [31:0] gpio_dir;
	wire [31:0] dout;
	wire [3:0] tx_full;
	wire [3:0] rx_empty;
	wire [4:0] offset = 4;
	wire [5:0] plen = 4;
	wire [23:0] div = 24'h0200;
	wire [31:0] pin_grps = 32'h40100000;
	wire [31:0] exec_ctrl = 32'h40003000;
	integer i;
	task act (input [3:0] a, input [31:0] d);
		begin
			@(negedge clk);
			action = a;
			din = d;
			@(posedge clk);
		end
	endtask
	pio pio_1 (.clk(clk), .reset(reset), .action(action), .index(index), .mindex(mindex), .din(din), .dout(dout), .gpio_in(gpio_in), .gpio_out(gpio_out), .gpio_dir(gpio_dir), .tx_full(tx_full), .rx_empty(rx_empty));
	initial
		$readmemh("uart_tx.mem", program);
	initial
	begin
		clk = 1'b0;
	end
	always
	begin
		#20
			clk = !clk;
	end
	initial
	begin
		reset = 1'b1;
		repeat(2) @(posedge clk);
		reset = 1'b0;
		for (i = 0; i < plen; i++)
		begin
			index = offset + i;
			act(INSTR, program[i][15:13] == 0 ? program[i] + offset : program[i]);
		end
		mindex = 0;
		act(PEND, exec_ctrl + (offset << 12) + (offset << 7));
		act(DIV, div);
		act(GRPS, pin_grps);
		act(SHIFT, 32'h00080000);
		if (offset > 0)
		begin
			act(IMM, offset);
		end
		act(EN, 1);
		act(NONE, 0);
		repeat(2) @(posedge clk);
		for (i = 0; i < 10; i++)
		begin
			act(PUSH, 32'h30 + i);
			action = 0;
			repeat(180) @(posedge clk);
		end
		$finish;
	end
	initial
	begin
		$dumpfile("test.vcd");
		$dumpvars(0, test);
		$display(" ac   din   out ");
		$monitor(" %h   %h   %h ", action, din, gpio_out);
	end
endmodule





```

# 実行結果

```
>vvp a.out
WARNING: pio2.v:871: $readmemh(uart_tx.mem): Not enough words in the file for the requested range [0:31].
VCD info: dumpfile test.vcd opened for output.
 ac   din   out
 x   xxxxxxxx   xxxxxxxx
 x   xxxxxxxx   00000000
 1   000098a0   00000000
 1   0000f727   00000000
 1   00006001   00000000
 1   00000646   00000000
 2   40007200   00000000
 7   00000200   00000000
 5   40100000   00000000
 a   00080000   00000000
 9   00000004   00000000
 6   00000001   00000000
 0   00000000   00000000
 4   00000030   00000000
 0   00000030   00000000
 0   00000030   00000001
 0   00000030   00000000
 0   00000030   00000001
 0   00000030   00000000
 0   00000030   00000001
 4   00000031   00000001
 0   00000031   00000001
 0   00000031   00000000
 0   00000031   00000001
 0   00000031   00000000
 0   00000031   00000001
 0   00000031   00000000
 0   00000031   00000001
 4   00000032   00000001
 0   00000032   00000001
 0   00000032   00000000
 0   00000032   00000001
 0   00000032   00000000
 0   00000032   00000001
 0   00000032   00000000
 0   00000032   00000001
 4   00000033   00000001
 0   00000033   00000001
 0   00000033   00000000
 0   00000033   00000001
 0   00000033   00000000
 0   00000033   00000001
 0   00000033   00000000
 0   00000033   00000001
 4   00000034   00000001
 0   00000034   00000001
 0   00000034   00000000
 0   00000034   00000001
 0   00000034   00000000
 0   00000034   00000001
 0   00000034   00000000
 0   00000034   00000001
 4   00000035   00000001
 0   00000035   00000001
 0   00000035   00000000
 0   00000035   00000001
 0   00000035   00000000
 0   00000035   00000001
 0   00000035   00000000
 0   00000035   00000001
 0   00000035   00000000
 0   00000035   00000001
 4   00000036   00000001
 0   00000036   00000001
 0   00000036   00000000
 0   00000036   00000001
 0   00000036   00000000
 0   00000036   00000001
 0   00000036   00000000
 0   00000036   00000001
 4   00000037   00000001
 0   00000037   00000001
 0   00000037   00000000
 0   00000037   00000001
 0   00000037   00000000
 0   00000037   00000001
 0   00000037   00000000
 0   00000037   00000001
 4   00000038   00000001
 0   00000038   00000001
 0   00000038   00000000
 0   00000038   00000001
 0   00000038   00000000
 0   00000038   00000001
 4   00000039   00000001
 0   00000039   00000001
 0   00000039   00000000
 0   00000039   00000001
 0   00000039   00000000
 0   00000039   00000001
 0   00000039   00000000
 0   00000039   00000001
pio2.v:909: $finish called at 729800 (100ps)

```

以上。