C · Linux + remote VGA
When is an edge frame ready to display?
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-10/part-03/
Physical DE1-SoCYour computer
A lighthouse stays in color even after the FPGA has finished finding its edges. The input reader and the output writer finish at different times. Your job is to find which completion event the program missed, repair the transfer sequence in C and show the result on a remote DE1-SoC.
You need a Linux terminal with a C compiler and Python 3, plus access to the LabsLand DE1-SoC Verilog Online Editor with VGA. The C program runs on your computer. It supplies four commands to a sequencer on the FPGA. The board computes the edges from the color picture each time you change the threshold.
Follow one frame
From the extracted worksheet folder, run the starter and trace its four commands. The trace uses a model of three DMA controllers. A write of 1 to a controller’s buffer register requests a swap. Bit 0 at offset 12 stays set until that swap completes.
cc -std=c11 -O2 starter/transfer.c -o transfer
cc -std=c11 -O2 resources/trace_transfer.c -o trace
./transfer > commands.txt
./trace < commands.txt
The starter reports a rejected presentation and returns status 4. In the trace, find the source at 0xff203100, the sink at 0xff203120 and video at 0xff203020. The color picture begins at 0xc0000000 and the output buffer at 0xc2000000. Which address is on screen at the end? When the input reader first goes idle, what is the writer still doing?
Try the original sequence on the board
On Windows with the Python launcher, use py -3 wherever a command starts with python3.
python3 resources/build_board.py commands.txt resources/beacon80.bmp edge_dma.v
Open the DE1-SoC Verilog Online Editor, choose Change → Media → VGA and audio, and apply the interface. Use New to create edge_dma, paste the contents of edge_dma.v, select that file as the top level, and choose Synthesize → Upload to FPGA. Wait for the lighthouse in the VGA pane. Set SW1 down. Move SW0 up to request the edge view. Record the board identifier, the image and the state of LEDR3. LabsLand DE1-SoC laboratory
Repair the handoff
Reorder the commands in starter/transfer.c. The output bank can be presented only after both transfer controllers have finished. Rebuild the C program, regenerate commands.txt and rerun the trace. Which buffer is now on screen? Run ./trace stall-sink < commands.txt to hold the writer busy. Explain why the original front buffer stays visible after the timeout.
Regenerate edge_dma.v, replace the editor contents, synthesize and upload again. In the board session, make these three observations:
| Switch state | What to record |
|---|---|
| SW0 down | Locate the sun, tower and water on the color image. |
| SW0 up, SW1 down | At threshold 20, identify two outlines. Check LEDR2 for a completed presentation. |
| SW0 up, SW1 up | At threshold 100, find one feature that disappears and one that survives. Return SW1 down and verify the feature comes back. |

At threshold 20, the board’s VGA output shows the lantern window and the small marks on the water.
Each of the 80 × 60 computed samples covers an 8 × 8 tile of the 640 × 480 display. The input reader streams the color samples into the five-stage detector from Part I. The output writer stores the final intensities in FPGA memory. Video starts using the completed frame during vertical blanking. This exercise runs in the programmable logic. The original HPS exercise uses a Linux process, two SDRAM frame buffers and a separate hardware system.
Save and compare the edge map
With Icarus Verilog installed, the following commands run the same detector without a board and save the luminance samples. The testbench measures clock cycles from transfer start to output completion. It excludes the wait for vertical blanking.
iverilog -g2012 -s check_engine -o engine edge_dma.v resources/check_engine.v
vvp engine +THRESHOLD=20 +OUTPUT=low.bin
python3 resources/save_edges.py low.bin low.bmp
Repeat with threshold 100 and a different filename. If you have your Part I C program, run it on resources/beacon80.bmp at both thresholds. Compare decoded pixel intensities, then divide the hardware cycle count by 50 MHz. Record what the C timing includes and where you ran it before drawing a conclusion about speed. Submit the four commands in order, the two final front-buffer addresses (normal and stalled), the two threshold observations and your timing calculation.
FPGAcademy exercise · Exercise notice · LabsLand source license
