依照状态机的编程思路。
部分Verilog代码如下:
ST_CFGREAD: begin
enable <= EN_RD;
if (~irdy || trdy) begin
case (address)
0: data <= { DEVICE_ID,VENDOR_ID };
1: data <= { 5'b0,DEVSEL_TIMING, 9'b0, 14'b0, memen,1'b0};
2: data <= {DEVICE_CLASS, DEVICE_REV };
4: data <= { 12'b0,baseaddr, 8'b0, 4'b0010 }; // baseaddr + request mem < 1Mbyte
11: data <={SUBSYSTEM_ID, SUBSYSTEM_VENDOR_ID };
16: data <= { 24'b0,baseaddr };
default: data <='h00000000;
endcase
address <= address + 1'b1;
end
if (frame && ~irdy && ~trdy) begin
devsel <= 1;
state <= ST_IDLE;
enable <= EN_TR;
end
end