Functions | Variables
drv_flashfs.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "drv_m25p16.h"
#include "drv_flashfs.h"
Include dependency graph for drv_flashfs.c:

Go to the source code of this file.

Functions

static void flashfsAdvanceTailInBuffer (uint32_t delta)
 
static bool flashfsBufferIsEmpty ()
 
static void flashfsClearBuffer ()
 
void flashfsEraseCompletely ()
 
void flashfsEraseRange (uint32_t start, uint32_t end)
 
bool flashfsFlushAsync ()
 
void flashfsFlushSync ()
 
static void flashfsGetDirtyDataBuffers (uint8_t const *buffers[], uint32_t bufferSizes[])
 
const flashGeometry_tflashfsGetGeometry ()
 
uint32_t flashfsGetOffset ()
 
uint32_t flashfsGetSize ()
 
uint32_t flashfsGetWriteBufferFreeSpace ()
 
uint32_t flashfsGetWriteBufferSize ()
 
int flashfsIdentifyStartOfFreeSpace ()
 
void flashfsInit ()
 
bool flashfsIsEOF ()
 
bool flashfsIsReady ()
 
int flashfsReadAbs (uint32_t address, uint8_t *buffer, unsigned int len)
 
void flashfsSeekAbs (uint32_t offset)
 
void flashfsSeekRel (int32_t offset)
 
static void flashfsSetTailAddress (uint32_t address)
 
static uint32_t flashfsTransmitBufferUsed ()
 
void flashfsWrite (const uint8_t *data, unsigned int len, bool sync)
 
static uint32_t flashfsWriteBuffers (uint8_t const **buffers, uint32_t *bufferSizes, int bufferCount, bool sync)
 
void flashfsWriteByte (uint8_t byte)
 

Variables

static uint8_t bufferHead = 0
 
static uint8_t bufferTail = 0
 
static uint8_t flashWriteBuffer [FLASHFS_WRITE_BUFFER_SIZE]
 
static uint32_t tailAddress = 0
 

Function Documentation

static void flashfsAdvanceTailInBuffer ( uint32_t  delta)
static

Called after bytes have been written from the buffer to advance the position of the tail by the given amount.

Definition at line 290 of file drv_flashfs.c.

static bool flashfsBufferIsEmpty ( )
static

Definition at line 62 of file drv_flashfs.c.

static void flashfsClearBuffer ( )
static

Definition at line 57 of file drv_flashfs.c.

void flashfsEraseCompletely ( )

Definition at line 72 of file drv_flashfs.c.

void flashfsEraseRange ( uint32_t  start,
uint32_t  end 
)

Start and end must lie on sector boundaries, or they will be rounded out to sector boundaries such that all the bytes in the range [start...end) are erased.

Definition at line 85 of file drv_flashfs.c.

bool flashfsFlushAsync ( )

If the flash is ready to accept writes, flush the buffer to it.

Returns true if all data in the buffer has been flushed to the device, or false if there is still data to be written (call flush again later).

Definition at line 310 of file drv_flashfs.c.

void flashfsFlushSync ( )

Wait for the flash to become ready and begin flushing any buffered data to flash.

The flash will still be busy some time after this sync completes, but space will be freed up to accept more writes in the write buffer.

Definition at line 333 of file drv_flashfs.c.

static void flashfsGetDirtyDataBuffers ( uint8_t const *  buffers[],
uint32_t  bufferSizes[] 
)
static

Definition at line 258 of file drv_flashfs.c.

const flashGeometry_t* flashfsGetGeometry ( )

Definition at line 145 of file drv_flashfs.c.

uint32_t flashfsGetOffset ( )

Get the current offset of the file pointer within the volume.

Definition at line 275 of file drv_flashfs.c.

uint32_t flashfsGetSize ( )

Definition at line 116 of file drv_flashfs.c.

uint32_t flashfsGetWriteBufferFreeSpace ( )

Get the number of bytes that can currently be written to flashfs without any blocking or data loss.

Definition at line 140 of file drv_flashfs.c.

uint32_t flashfsGetWriteBufferSize ( )

Get the size of the largest single write that flashfs could ever accept without blocking or data loss.

Definition at line 132 of file drv_flashfs.c.

int flashfsIdentifyStartOfFreeSpace ( )

Find the offset of the start of the free space on the device (or the size of the device if it is full).

Definition at line 489 of file drv_flashfs.c.

void flashfsInit ( )

Call after initializing the flash chip in order to set up the filesystem.

Definition at line 565 of file drv_flashfs.c.

bool flashfsIsEOF ( )

Returns true if the file pointer is at the end of the device.

Definition at line 558 of file drv_flashfs.c.

bool flashfsIsReady ( )

Return true if the flash is not currently occupied with an operation.

Definition at line 111 of file drv_flashfs.c.

int flashfsReadAbs ( uint32_t  address,
uint8_t *  buffer,
unsigned int  len 
)

Read len bytes from the given address into the supplied buffer.

Returns the number of bytes actually read which may be less than that requested.

Definition at line 468 of file drv_flashfs.c.

void flashfsSeekAbs ( uint32_t  offset)

Definition at line 349 of file drv_flashfs.c.

void flashfsSeekRel ( int32_t  offset)

Definition at line 356 of file drv_flashfs.c.

static void flashfsSetTailAddress ( uint32_t  address)
static

Definition at line 67 of file drv_flashfs.c.

static uint32_t flashfsTransmitBufferUsed ( )
static

Definition at line 121 of file drv_flashfs.c.

void flashfsWrite ( const uint8_t *  data,
unsigned int  len,
bool  sync 
)

Write the given buffer to the flash either synchronously or asynchronously depending on the 'sync' parameter.

If writing asynchronously, data will be silently discarded if the buffer overflows. If writing synchronously, the routine will block waiting for the flash to become ready so will never drop data.

Definition at line 385 of file drv_flashfs.c.

static uint32_t flashfsWriteBuffers ( uint8_t const **  buffers,
uint32_t *  bufferSizes,
int  bufferCount,
bool  sync 
)
static

Write the given buffers to flash sequentially at the current tail address, advancing the tail address after each write.

In synchronous mode, waits for the flash to become ready before writing so that every byte requested can be written.

In asynchronous mode, if the flash is busy, then the write is aborted and the routine returns immediately. In this case the returned number of bytes written will be less than the total amount requested.

Modifies the supplied buffer pointers and sizes to reflect how many bytes remain in each of them.

bufferCount: the number of buffers provided buffers: an array of pointers to the beginning of buffers bufferSizes: an array of the sizes of those buffers sync: true if we should wait for the device to be idle before writes, otherwise if the device is busy the write will be aborted and this routine will return immediately.

Returns the number of bytes written

Definition at line 169 of file drv_flashfs.c.

void flashfsWriteByte ( uint8_t  byte)

Write the given byte asynchronously to the flash. If the buffer overflows, data is silently discarded.

Definition at line 366 of file drv_flashfs.c.

Variable Documentation

uint8_t bufferHead = 0
static

Definition at line 52 of file drv_flashfs.c.

uint8_t bufferTail = 0
static

Definition at line 52 of file drv_flashfs.c.

uint8_t flashWriteBuffer[FLASHFS_WRITE_BUFFER_SIZE]
static

This provides a stream interface to a flash chip if one is present.

On statup, call flashfsInit() after initialising the flash chip in order to init the filesystem. This will result in the file pointer being pointed at the first free block found, or at the end of the device if the flash chip is full.

Note that bits can only be set to 0 when writing, not back to 1 from 0. You must erase sectors in order to bring bits back to 1 again.

In future, we can add support for multiple different flash chips by adding a flash device driver vtable and make calls through that, at the moment flashfs just calls m25p16_* routines explicitly.

Definition at line 43 of file drv_flashfs.c.

uint32_t tailAddress = 0
static

Definition at line 55 of file drv_flashfs.c.



rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:20