며칠 동안 Verilog 코드를 디버깅하고 있는데, 특히 FX2LP (Cypress CY7C68016A) USB 컨트롤러에서 바이트를 보내고받는 것이 중요합니다. 많은 세부 사항을 고려하지 않고도 데이터가 전송되어 각주기마다 바이트 단위로 전송됩니다. 내 테스트를 위해 필자가 먼저 채운 16 바이트 버퍼를 사용하여 다시 송신한다 (에코 테스트). 이 코드는 시뮬레이션 (iVerilog)에서 완벽하게 작동순차 블록에서 비트 시프트가 실패합니다. 왜?
reg [127:0] dataBuf; // 16 byte buffer for USB data
reg [7:0] cntByte; // counter for number of bytes
reg [7:0] nextCntByte;
reg shiftBufRx, shiftBufTx; // flags whether buffer should be shifted
reg [7:0] currentByte; // current read byte
// in transmit cycle, byte is read from USB_DATAOUT
assign USB_DATAOUT = dataBuf[7:0];
always @(posedge FIFO_CLK) begin
// update state variables
CurrentState <= NextState;
cntByte <= nextCntByte;
if(shiftBufRx) begin // cycle was a receive
dataBuf <= { currentByte , dataBuf[127:8] };
end
if(shiftBufTx) begin // cycle was a transmit
dataBuf <= { dataBuf[127-8:0] , 8'h00 };
end
end
always @(*) begin
// avoid race conditions
NextState = CurrentState;
nextCntByte = cntByte;
nextDataBuf = dataBuf;
currentByte = 0;
shiftBufRx = 0;
shiftBufTx = 0;
case(CurrentState)
[...]
STATE_USBRX: begin
if(cntByte < 16) begin
nextCntByte = cntByte + 1;
currentByte = USB_DATAIN; // contains received byte in receive cycle
shiftBufRx = 1; // shift buffer after this cycle
end
[...]
end
STATE_USBTX: begin
if(cntByte < 15) begin
shiftBufTx = 1; // shift buffer after this cycle
nextCntByte = cntByte + 1;
end
[...]
end
[...]
endcase
end
: 같은
내 코드의 상당 부분이 보인다. 그러나 Altera Cyclone에서 합성 및 실행하면 매우 이상한 오류가 발생합니다. 예를 들어, FPGA로 전송 된 첫 번째 바이트는 대부분 각 바이트마다 읽혀집니다. 예를 들어 11 22 33 44 55 66 ...
을 보내면 11 11 11 11 11 11 ...
이 표시됩니다.
reg [127:0] nextDataBuf;
와 함께 순차적 always @(posedge FIFO_CLK)
블록에 부품을 교체 :
if(shiftBufRx) begin
dataBuf <= nextDataBuf;
end
if(shiftBufTx) begin
dataBuf <= nextDataBuf;
end
과 조합 부분 :
STATE_USBRX: begin
if(cntByte < 16) begin
nextCntByte = cntByte + 1;
//currentByte = FIFO_DATAIN;
nextDataBuf = { dataBuf[127-8:0] , FIFO_DATAIN };
shiftBufRx = 1;
end
[...]
end
STATE_USBTX: begin
if(cntByte < 15) begin
shiftBufTx = 1;
nextCntByte = cntByte + 1;
nextDataBuf = { 8'h00 , dataBuf[127:8] };
end
[...]
end
내가 대신 새 변수를 소개 이제
그러면 작동합니다!
의미 : 순차적 블록에서 조합 블록으로의 레지스터 이동을 이동하는 것입니다.
내 코드와 시뮬레이션 (iVerilog)에서 어떤 경쟁 조건도 보이지 않지만 두 버전이 동일합니다.
어떤 이유가있을 수 있습니까?
Tx/Rx 플래그 간의 관계를 확인하십시오. 두 가지가 동시에 일어난다면 이상한 노래가 일어날 수 있습니다. – Serge
데이터 구조가 일치하지 않습니다. '{dataBuf [127-8 : 0], 8'h00}'! ='{8'h00, dataBuf [127 : 8]}' – Greg