您好我正在开发简单的DSO,我遇到FT245同步FIFO问题。 当我读取4byte确认时,从FT245读取正常工作,但是当我想要检索采样数据时,它返回零字节(意味着ftdi_read_data返回0,连续读取返回-84然后-32(没有文档这些代码意味着什么))。 / p>
readig的功能:
int Ft245sync::read(unsigned char * buf)
{
int res = ftdi_read_data(ftdic, buf, getReadChunkSize());
std::cerr << "res rd: " << res << std::endl;
return res;
}
阅读发生的代码:
有效的部分(阅读确认):
//send SET TRIGGER
recvbuf[0] = 0;
while(recvbuf[0] != DATA_OK)
{
unsigned char buf3[10] = { SET_TRIGGER, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if(ft245.write(buf3) < 0)
{
std::cerr << "Error writing data3\n";
}
if(ft245.read(recvbuf) < 0)
{
std::cerr << "Error receiving data\n";
}
}
不起作用的部分:
//send START CAPTURE
unsigned char buf5[10] = { START_CAPTURE, 0x05, 0, 0, 0, 0, 0, 0, 0, 0 };
if(ft245.write(buf5) < 0)
{
std::cerr << "Error writing data5\n";
}
usleep(700);
std::cout << "Capture started\n";
for (int i = 0; i < 30; ++i)
{
if(ft245.read(recvbuf) < 0)
{
std::cerr << "Error reading data\n";
}
}
来自工作的chipcope的屏幕阅读:
错误阅读的屏幕截图:
可以看出,在TXE变低后的两个时钟内,WR被置于低电平。
部分VHDL工作代码:
when SEND_ACKNOWLEDGE0 =>
if to_boolean(ft245busy) then
state <= SEND_ACKNOWLEDGE0;
else
state <= SEND_ACKNOWLEDGE1;
end if;
when SEND_ACKNOWLEDGE1 =>
ft245rw <= '1';
responseCounter <= "000";
ft245din <= "10000000";
if (ft245wr = '0') then
state <= SEND_ACKNOWLEDGE2;
ft245strobe <= '0';
else
ft245strobe <= '1';
state <= SEND_ACKNOWLEDGE1;
end if;
when SEND_ACKNOWLEDGE2 =>
if (responseCounter < 1) then
responseCounter <= (responseCounter + 1);
ft245din <= "10000000";
state <= SEND_ACKNOWLEDGE2;
else
ft245dataWaitIn <= '1';
ft245rw <= '0';
responseCounter <= "000";
case command is
when "10101110" =>
state <= INIT0;
when "00010000" =>
state <= SET_VREF0;
when "00010001" =>
state <= SET_VLOG0;
when "00100000" =>
state <= SET_ATTENUATORS;
when "00100001" =>
state <= SET_COUPLINGS;
when "00110000" =>
state <= SET_DECIMATION;
when "00110001" =>
state <= SET_ANALOGTRIGGER;
when "00110010" =>
state <= SET_DIGITALTRIGGER;
when "01000000" =>
state <= START_CAPTURE;
when others =>
state <= IDLE;
end case;
end if;
部分错误阅读:
when DUMP_DATA_PREPFT =>
if to_boolean(ft245busy) then
state <= DUMP_DATA_PREPFT;
else
state <= DUMP_DATA0;
end if;
when DUMP_DATA0 =>
adc1pd <= '1';
adc2pd <= '1';
ft245rw <= '1';
bufferDataDirection <= '0';
answerNumber <= "00";
ft245din <= "01010000";
if ((ft245wr = '0') and to_boolean(bufferReady)) then
state <= DUMP_DATA1;
ft245strobe <= '0';
else
ft245strobe <= '1';
state <= DUMP_DATA0;
end if;
when DUMP_DATA1 =>
ft245din <= "01010000";
ft245dataWaitIn <= '0';
answerNumber <= (answerNumber + 1);
if (answerNumber = 3) then
state <= DUMP_DATA2;
bufferOutputInputReady <= '1';
else
state <= DUMP_DATA1;
end if;
还有我的ft245控制器的代码负责读取(从FPGA的角度来看):
when IDLE =>
if (strobe = '1') then
busy <= '1';
if (rw = '1') then
state <= WRITE_PREP;
else
state <= READ_PREP;
end if;
else
busy <= '0';
state <= IDLE;
end if;
when WRITE_PREP =>
if (txe = '0') then
state <= WRITE;
else
state <= WRITE_PREP;
end if;
when WRITE =>
if ((txe = '0') and (not to_boolean(dataWaitIn))) then
wr_int <= '0';
else
wr_int <= '1';
state <= IDLE;
busy <= '0';
end if;
还有程序输出列表:
res wr: 10
res rd: 4
res wr: 10
Capture started
res rd: 0
res rd: 0
res rd: -84
Error reading data
res rd: -32
Error reading data
res rd: -32
...
从我的角度来看,FPGA中的所有内容都可以(根据chipscope)和程序中的读取也是一样的,所以我不知道它为什么会起作用然后不行(我可以成功做更多(数十次)写/ read循环使用4byte确认,但随后它会在此错误读取时停止... ...
//编辑: 当您设置可笑的大型传入缓冲区(超过16000字节)时,它可以令人惊讶地工作。但我仍然不明白为什么..
答案 0 :(得分:1)
Chipscope只显示内部结构。
你应该检查更多的事情:
您可能会发现失败路径中的逻辑导致某些内容超出规范。
答案 1 :(得分:1)
我通过将输入缓冲区设置为32768字节来解决它,这是我要传输的最大字节数。它现在运行良好,每隔506个字节后只有一些未对齐的字节(关闭一个字节)..但这可能是一些我的FPGA设计中的错误。
//编辑: 只是为了注意,最大的问题不是计时(即使你违反11ns保持计时它将正常工作,例如我只有7ns设置)但让状态机知道输入缓冲区满时的情况蚂蚁TXE变高并正确继续TXE回低时传输。