Search topics...

What is dual-port RAM? Why would it be useful in some embedded systems? What concerns do you need to worry about when using it? Have you ever used it? How?

0 upvotes
Practice with AISoon

Dual-port RAM (DPRAM) is a memory array with two independent access ports — each with its own address, data, and control lines — so two different agents can read/write the same memory simultaneously and asynchronously. (True dual-port has two full read/write ports; there are also simpler dual-port/FIFO variants.)

Why it's useful in embedded systems: it provides a fast shared-memory communication channel between two masters — for example, two CPUs/cores, a CPU and a DSP, or a CPU and a DMA engine / network processor. Each side accesses the shared buffer at full speed on its own port without a bus-arbitration handshake for every access, which is great for inter-processor mailboxes, message passing, frame buffers, and producer/consumer buffers. It decouples the two sides' timing.

Concerns when using it:

  • Simultaneous same-address access (access contention): if both ports access the same cell at the same time and at least one is a write, you can get a data hazard / indeterminate result. You need arbitration. Many DPRAM chips provide hardware BUSY/arbitration logic plus hardware semaphore/mailbox registers and interrupt flags to coordinate; you must honor the BUSY signal or use the semaphores.
  • Coherency / consistency: a reader on one port can see a partially-updated multi-byte structure being written on the other port. Use semaphores/flags, ownership protocols, double-buffering, or write-then-set-a-valid-flag (with proper ordering) so each side only reads complete, committed data.
  • Atomicity & ordering: multi-word updates aren't atomic across ports; define a protocol (e.g., one side owns a region at a time) and be careful about memory ordering, caching (mark shared regions non-cacheable or flush/invalidate), and compiler reordering (volatile).
  • Metastability: flags/interrupts crossing the two asynchronous clock domains must be synchronized to avoid metastable states.
  • Cost/density: DPRAM is more expensive and less dense than single-port RAM.

A typical usage pattern: a mailbox between two processors — a shared DPRAM (sometimes inside an FPGA or a dedicated IDT-style DPRAM chip) divided into a CPU-A→CPU-B message region and a B→A region, each guarded by the chip's hardware semaphores. The writer takes the semaphore, writes the message buffer, sets a "message ready" flag, and triggers the other port's mailbox interrupt; the reader services the interrupt, consumes the message, clears the flag, and releases the semaphore. Shared regions are non-cacheable and declared volatile. The same approach works for a CPU exchanging command/status with a DMA/network engine.