Simvik

A FIFO between two cores

Model one direction of the RP2350's inter-core FIFO, 4 words deep, with its sticky error flags. A medium embedded C problem (Two cores on the RP2350), run…

medium · Two cores on the RP2350 · multicore · fifo

Each RP2350 core has a FIFO of 4 32-bit words to the other (an RP2040's holds 8). A zero-initialised fifo_t is empty, with no errors.

  • fifo_write adds w and returns true; when the FIFO is full it drops the word, sets wof and returns false.
  • fifo_read takes the oldest word into *w and returns true; when the FIFO is empty it leaves *w alone, sets roe and returns false.

wof and roe stay set until the program clears them, as the SIO's FIFO_ST bits do.

Starter code

bool fifo_write(fifo_t *f, uint32_t w) {
  return false;
}

bool fifo_read(fifo_t *f, uint32_t *w) {
  return false;
}

Example tests

Words come out in order

fifo_t f = { 0 };
fifo_write(&f, 0x10001); fifo_write(&f, 0x10002);
uint32_t a = 0, b = 0;
fifo_read(&f, &a); fifo_read(&f, &b);
printf("%lx %lx %u\n", (unsigned long)a, (unsigned long)b, f.count);

Expected output:

10001 10002 0

A read of an empty FIFO sets ROE

fifo_t f = { 0 };
uint32_t w = 7;
printf("%d %lu %d\n", fifo_read(&f, &w), (unsigned long)w, f.roe);

Expected output:

0 7 1

Learn it first

More Two cores on the RP2350 problems