Abyss Buffer: Sonar Data FIFO Controller

Problem Description
Deep beneath the ocean, the research submarine Abyss Pioneer fires sonar pings at irregular intervals, generating 8-bit intensity readings that must be buffered before the onboard CPU can process them. Your module implements a synchronous FIFO that accepts sonar readings on wr_data when wr_en is asserted (unless full), and delivers them in arrival order on rd_data when rd_en is asserted (unless empty). The almost_full flag must assert whenever 6 or more of the 8 slots are occupied, giving the sonar controller time to throttle new measurements. All state resets synchronously when rst is high on a rising clock edge.
Port | Direction | Width | Description |
|---|---|---|---|
| Input | 1 | System clock; all state updates on posedge |
| Input | 1 | Synchronous reset; clears FIFO, pointers, and count |
| Input | 1 | Write enable; push |
| Input | 8 | Sonar reading to write into the FIFO |
| Input | 1 | Read enable; pop oldest entry to |
| Output | 1 | Asserts when all 8 slots are occupied (count == 8) |
| Output | 1 | Asserts when no entries are present (count == 0) |
| Output | 1 | Asserts when count >= 6 |
| Output | 8 | Oldest sonar reading; holds last valid value when empty |
Write when full:
wr_enasserted butfullis high — write must be silently ignored; existing data must not be corrupted.Read when empty:
rd_enasserted butemptyis high — read must be silently ignored;rd_dataholds its last valid value.Simultaneous read + write when full: one slot is freed by the read and one is filled by the write in the same cycle — count stays the same; both operations proceed.
Simultaneous read + write when empty: write fills one slot, read is blocked (empty overrides) — count becomes 1 after the cycle.
Reset mid-operation:
rstasserted while bothwr_enandrd_enare high — all pointers and count must clear to 0.almost_full boundary: at count=5,
almost_fullmust be LOW; at count=6, it must be HIGH.All Scenarios Table
Scenario | Key State | Result |
|---|---|---|
Write to empty FIFO | count: 0→1 |
|
Write until full | count: 7→8 |
|
Write when full | count stays 8 | Ignored ✗ |
Read from FIFO | count: 3→2 |
|
Read when empty | count stays 0 | Ignored ✗ |
Simul R+W (normal) | count unchanged | Both happen ✓ |
Simul R+W (full) | count stays 8 | Both happen ✓ |
Simul R+W (empty) | count: 0→1 | Write ✓, read ignored ✗ |
count = 5 | count = 5 |
|
count = 6 | count = 6 |
|
Synchronous reset | count → 0 |
|
Verilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
