Abyss Buffer: Sonar Data FIFO Controller

Qualcomm

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

clk

Input

1

System clock; all state updates on posedge

rst

Input

1

Synchronous reset; clears FIFO, pointers, and count

wr_en

Input

1

Write enable; push wr_data into FIFO when not full

wr_data

Input

8

Sonar reading to write into the FIFO

rd_en

Input

1

Read enable; pop oldest entry to rd_data when not empty

full

Output

1

Asserts when all 8 slots are occupied (count == 8)

empty

Output

1

Asserts when no entries are present (count == 0)

almost_full

Output

1

Asserts when count >= 6

rd_data

Output

8

Oldest sonar reading; holds last valid value when empty

  • Write when full: wr_en asserted but full is high — write must be silently ignored; existing data must not be corrupted.

  • Read when empty: rd_en asserted but empty is high — read must be silently ignored; rd_data holds 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: rst asserted while both wr_en and rd_en are high — all pointers and count must clear to 0.

  • almost_full boundary: at count=5, almost_full must be LOW; at count=6, it must be HIGH.

    All Scenarios Table

Scenario

Key State

Result

Write to empty FIFO

count: 0→1

empty deasserts ✓

Write until full

count: 7→8

full asserts ✓

Write when full

count stays 8

Ignored ✗

Read from FIFO

count: 3→2

rd_data valid ✓

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

almost_full LOW ✗

count = 6

count = 6

almost_full HIGH ✓

Synchronous reset

count → 0

empty asserts ✓

Verilog

Code Editor Access

Log in to write, run and submit your solution to this interview question. It's free.

Output

Output goes here...