Skip to content

andkae/SPI-Flash-Circular-Buffer

Repository files navigation

Test

SPI Flash Circular Buffer

C Library to transform a physical SPI Flash into a logical circular buffer. The interface between SFCB and SPI core is realized as shared memory.

Features

  • Arbitrary SPI Flash support
  • Arbitary number of circular buffers in one SPI flash
  • Interaction between circular buffer and SPI interface is ealized as shared memory

Releases

Version Date Source Change log
latest latest.zip

Integrate

Build

Init

int sfcb_init (t_sfcb *self, void *cb, uint8_t cbLen, void *spi, uint16_t spiLen);

Initializes SFCB common handle and assigns memory.

Arguments:

Arg Description
self SFCB storage element
cb Circular buffer queue memory
cbLen max. number of cb queues
spi SFCB / SPI core exchange buffer
spiLen spi buffer size in bytes

Return:

  • Success: == 0
  • Failure: != 0

Worker

void sfcb_worker (t_sfcb *self);

Services circular buffer layer request as well SPI packet processing. This function should called in a time based matter. The SPI data packet transfer should use an ISR based dataflow.

Arguments:

Arg Description
self SFCB storage element

Flash Size

uint32_t sfcb_flash_size (void);

Get SFCB compiled flash type total size.

Return:

Size in bytes.

Memory organisation

The SFCB supports an arbitrary number of circular buffer queues. Each circular buffer starts at the lowest free SPI Flash address. The Flash architecture requires an dedicated data clear - so called Sector Erase. Through this limitation needs to be at least two sectors allocated. Otherwise would the overwrite of the first written element result in an complete circular buffer queue overwrite without keeping any previous entries. Every new entry is marked with the incremented highest 32bit IdNum and MagicNum. The MagicNum ensures the detection of an occupied circular buffer queue element.

An exemplary memory organisation for 240 bytes payload and 32 elements (= two sectors) shows the figure below:

Example circular buffer queue 0 FLASH memory organization


References