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_writeaddswand returnstrue; when the FIFO is full it drops the word, setswofand returnsfalse.fifo_readtakes the oldest word into*wand returnstrue; when the FIFO is empty it leaves*walone, setsroeand returnsfalse.
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 0A 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 1Learn it first
- Two cores on the RP2350 · Starting core 1, the SIO FIFOs, spin locks and splitting the work.
More Two cores on the RP2350 problems
- The SIO's hardware spin locks · Model the RP2350's 32 spin locks, claimed by reading and freed by writing.