spi 成功触发主机发送
This commit is contained in:
@@ -17,7 +17,7 @@ module ShinTopSpiTb(
|
||||
wire spi_miso;
|
||||
reg [4:0] spi_csn;
|
||||
|
||||
|
||||
wire isResp;
|
||||
|
||||
ShinTop s_ShinTop_Mst(
|
||||
.clock(clock),
|
||||
@@ -34,7 +34,7 @@ ShinTop s_ShinTop_Mst(
|
||||
.io_ospi_miso(spi_miso),
|
||||
.io_ospi_csn (spi_csn[0]),
|
||||
|
||||
.io_rsp_valid(),
|
||||
.io_rsp_valid(isResp),
|
||||
.io_rsp_bits_isError(),
|
||||
.io_rsp_bits_length()
|
||||
);
|
||||
@@ -218,11 +218,11 @@ end
|
||||
|
||||
reg [11:0] transCnt;
|
||||
reg [11:0] byteCnt;
|
||||
reg [3:0] bitCnt;
|
||||
reg [2:0] bitCnt;
|
||||
|
||||
|
||||
always @(posedge sck) begin
|
||||
if( isReq ) begin
|
||||
always @(posedge clock) begin
|
||||
if( isReq & sck == 0 ) begin
|
||||
isBusy <= #5 1'b1;
|
||||
transCnt <= #5 0;
|
||||
|
||||
@@ -232,12 +232,17 @@ always @(posedge sck) begin
|
||||
spi_csn[idx] <= #5 1'b0;
|
||||
exChangeReg <= txBuf[0];
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
always @(posedge sck) begin
|
||||
if( isBusy ) begin
|
||||
if( transCnt < length ) begin
|
||||
bitCnt <= bitCnt + 1;
|
||||
|
||||
if( bitCnt == 7 ) begin
|
||||
byteCnt <= byteCnt +1;
|
||||
transCnt <= transCnt + 1;
|
||||
rxBuf[byteCnt] <= exChangeReg;
|
||||
exChangeReg <= txBuf[byteCnt+1];
|
||||
end else begin
|
||||
@@ -355,7 +360,7 @@ task spi_trans( input [15:0] saddress, input [7:0] scmd, input [12:0] slength,in
|
||||
txBuf[1] <= saddress[15:8];
|
||||
txBuf[2] <= scmd;
|
||||
|
||||
length <= slength;
|
||||
length <= slength + 3;
|
||||
idx <= sidx;
|
||||
|
||||
#5
|
||||
@@ -364,8 +369,8 @@ task spi_trans( input [15:0] saddress, input [7:0] scmd, input [12:0] slength,in
|
||||
@(posedge sck) #5
|
||||
isReq <= 0;
|
||||
|
||||
|
||||
|
||||
@( negedge isBusy) #1000
|
||||
begin end
|
||||
end
|
||||
|
||||
endtask
|
||||
@@ -420,6 +425,8 @@ initial begin
|
||||
|
||||
txBuf[0+3] = 8'h01;
|
||||
spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送
|
||||
@(posedge isResp) #5 begin end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -471,7 +478,7 @@ initial begin
|
||||
|
||||
txBuf[0+3] = 8'h01;
|
||||
spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送
|
||||
|
||||
@(posedge isResp) #5 begin end
|
||||
end
|
||||
|
||||
|
||||
@@ -575,7 +582,7 @@ initial begin
|
||||
|
||||
txBuf[0+3] = 8'h01;
|
||||
spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送
|
||||
|
||||
@(posedge isResp) #5 begin end
|
||||
end
|
||||
|
||||
|
||||
@@ -646,7 +653,7 @@ initial begin
|
||||
|
||||
txBuf[0+3] = 8'h01;
|
||||
spi_trans( (16'h20), (`SPI_WRITE), (1), (0) );//发送SM0 接收SM0, 请求发送
|
||||
|
||||
@(posedge isResp) #5 begin end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user