概要
ラズパイpicoのpioは、小さいcpuです。
verilogが手に入ったのでやってみた。
Lチカ、やってみた。
テストベンチを書いた。
`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 [5:0] plen = 2;
wire [23:0] div = 24'h0280;
wire [31:0] pin_grps = 32'h04000000;
wire [31:0] exec_ctrl = 32'h00001000;
wire out;
assign out = gpio_out[0];
task act(input [3:0] a, input [31:0] d);
begin
@(negedge clk);
action = a;
din = d;
@(posedge clk);
end
endtask
pio u(.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));
integer i;
initial
begin
clk = 1'b0;
end
initial
begin
program[0] <= 16'he1_01;
program[1] <= 16'he1_00;
end
initial
begin
reset = 1'b1;
repeat(2) @(posedge clk);
reset = 1'b0;
for (i = 0; i < plen; i++)
begin
index = i;
act(INSTR, program[i]);
end
mindex = 0;
act(PEND, exec_ctrl);
act(DIV, div);
act(GRPS, pin_grps);
act(EN, 1);
act(NONE, 0);
repeat(100) @(posedge clk);
$finish;
end
always
begin
#20
clk = !clk;
end
initial
begin
$dumpfile("test.vcd");
$dumpvars(0, test);
$display(" time action din out ");
$monitor("%t %h %h %h ", $time, action, din, out);
end
endmodule
実行結果
>vvp a.out
VCD info: dumpfile test.vcd opened for output.
time action din out
0 x xxxxxxxx x
200 x xxxxxxxx 0
800 1 0000e101 0
1200 1 0000e100 0
1600 2 00001000 0
2000 7 00000280 0
2400 5 04000000 0
2800 6 00000001 0
3200 0 00000000 0
4600 0 00000000 1
6600 0 00000000 0
8600 0 00000000 1
10600 0 00000000 0
12600 0 00000000 1
14600 0 00000000 0
16600 0 00000000 1
18600 0 00000000 0
20600 0 00000000 1
22600 0 00000000 0
24600 0 00000000 1
26600 0 00000000 0
28600 0 00000000 1
30600 0 00000000 0
32600 0 00000000 1
34600 0 00000000 0
36600 0 00000000 1
38600 0 00000000 0
40600 0 00000000 1
42600 0 00000000 0
pio4.v:916: $finish called at 43400 (100ps)
uart_rxは、こちら
uart_txは、こちら
spiは、こちら
以上