Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDRAM data trapping #13

Open
matwey opened this issue Aug 5, 2018 · 6 comments
Open

SDRAM data trapping #13

matwey opened this issue Aug 5, 2018 · 6 comments

Comments

@matwey
Copy link

matwey commented Aug 5, 2018

I am working on pure-C implementation for OpenVizsla host software: https://github.com/matwey/libopenvizsla
I've faced the following issue with FPGA firmware last summer.
I have been not able to make FPGA reliable restart sniffed data transmission.

The issue itself is the following.
The protocol has two encapsulation levels.
The upper level is packets come from SDRAM buffering module.
The packets consists of 0x0D magic header, length byte, and the data.
On practice this packets are of the same length.
The nested data is a stream consisted of packets from captured data.
They are consisted of 0xA0 magic header, length and USB data.
This packets are not aligned with each other.
One 0x0D-packet may consisted many 0xA0-packets, and 0xA0-packet may be split between two consecutive 0x0D-packets.

When I stop capturing and streaming and start it again then the first data byte of the first 0x0D-packet is not 0xA0 which it should be.
This is an issue because there is no other reliable way to sync 0xA0-packet stream. We cannot just scan for first 0xA0 because 0xA0 byte may be consisted inside data itself (compare with SLIP protocol).

My stop sequence is the following:

  • write 0 to SDRAM_HOST_READ_GO (0xC28)

  • write 0 to SDRAM_SINK_GO (0xE11)

  • write 0 to CSTREAM_CFG (0x800)

My start sequence is the following (given I assured that the stream is stopped):

  • write 32-bit 0 to SDRAM_SINK_RING_BASE (0xE09)

  • write 32-bit 0x01000000 to SDRAM_SINK_RING_END (0xE0D)

  • write 32-bit 0 to SDRAM_HOST_READ_RING_BASE (0xC1C)

  • write 32-bit 0x01000000 to SDRAM_HOST_READ_RING_END (0xC20)

  • write 0 to SDRAM_SINK_PTR_READ (0xE00)

  • write 1 to CSTREAM_CFG (0x800)

  • write 1 to SDRAM_SINK_GO (0xE11)

  • write 1 to SDRAM_HOST_READ_GO (0xC28)

I've tried to add Reset for sdram_fifo in SDRAM_Sink and SDRAM_Host_Read to reset fifoes on SDRAM_SINK_GO/SDRAM_HOST_READ_GO switch but this didn't help.

The issue is still present in the latest firmware from new_migen branch.

@tmbinc
Copy link
Collaborator

tmbinc commented Aug 5, 2018 via email

@matwey
Copy link
Author

matwey commented Aug 19, 2018

Hello,

The motivation is simple. Any application can crash unexpectedly, so we cannot guarantee graceful exit. So the most reliable on-start behavior for us is to force stop streaming, and reinit all the things as they expected to be (full reset), and the start streaming from the scratch.

I've followed your advice and reordered starting procedure, but there is still no success. Even CSTREAM and SINK are OFF (and SDRAM pointers are reset to 0), then the unexpected data are transmitted to host after I trigger SDRAM_HOST_READ.

Could you please also review the following:
matwey@0ffe58f
Does it makes sense?

@matwey
Copy link
Author

matwey commented Aug 19, 2018

The most reliable setup is the following:

        // dev.regs.SDRAM_SINK_GO.wr(1)
        // dev.regs.SDRAM_HOST_READ_GO.wr(1)
        // dev.regs.CSTREAM_CFG.wr(1)

Using matwey@0ffe58f

@matwey
Copy link
Author

matwey commented Aug 19, 2018

I still see that there is extra byte between d0 and a0:

        0x0000:  3260 d01f 27a0 1000 0000 7df6 69a0 0000
        0x0010:  0300 3d43 7169 8498 a000 0001 00a5 4971
        0x0020:  5aa0 0000 0300 6596 7869 8498 a000 0001
        0x0030:  00cd 9c78 5aa0 0000 0300 8de9 7f69 8498
        0x0040:  a000 0001

Here 1f is size byte, and then a0 should follows in theory.

matwey added a commit to matwey/libopenvizsla that referenced this issue Aug 19, 2018
@matwey
Copy link
Author

matwey commented Aug 19, 2018

Now I see that self.fifo_fsm from SDRAM_sink needs to be force reset to READ_LOW at every sink restart. Otherwise, it may cache the last odd byte from previous run.

@somehdlguy
Copy link
Collaborator

Patches to fix this kind of thing are welcome! (I haven't been able to find my board to do anything that requires HW-in-the-loop testing).

desowin pushed a commit to desowin/ov_ftdi that referenced this issue Jan 22, 2023
Add convenience scripts for PyInstaller and update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants