Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Stream to flash interface

Abstraction over stream writes to flash. More...

Data Structures

struct  stream_flash_ctx
 Structure for stream flash context. More...
 

Typedefs

typedef int(* stream_flash_callback_t) (uint8_t *buf, size_t len, size_t offset)
 Signature for callback invoked after flash write completes.
 

Functions

int stream_flash_init (struct stream_flash_ctx *ctx, const struct device *fdev, uint8_t *buf, size_t buf_len, size_t offset, size_t size, stream_flash_callback_t cb)
 Initialize context needed for stream writes to flash.
 
size_t stream_flash_bytes_written (struct stream_flash_ctx *ctx)
 Read number of bytes written to the flash.
 
int stream_flash_buffered_write (struct stream_flash_ctx *ctx, const uint8_t *data, size_t len, bool flush)
 Process input buffers to be written to flash device in single blocks.
 
int stream_flash_erase_page (struct stream_flash_ctx *ctx, off_t off)
 Erase the flash page to which a given offset belongs.
 
int stream_flash_progress_load (struct stream_flash_ctx *ctx, const char *settings_key)
 Load persistent stream write progress stored with key settings_key .
 
int stream_flash_progress_save (struct stream_flash_ctx *ctx, const char *settings_key)
 Save persistent stream write progress using key settings_key .
 
int stream_flash_progress_clear (struct stream_flash_ctx *ctx, const char *settings_key)
 Clear persistent stream write progress stored with key settings_key .
 

Detailed Description

Abstraction over stream writes to flash.

Since
2.3
Version
0.1.0

Typedef Documentation

◆ stream_flash_callback_t

stream_flash_callback_t

#include <zephyr/storage/stream_flash.h>

Signature for callback invoked after flash write completes.

Functions of this type are invoked with a buffer containing data read back from the flash after a flash write has completed. This enables verifying that the data has been correctly stored (for instance by using a SHA function). The write buffer 'buf' provided in stream_flash_init is used as a read buffer for this purpose.

Parameters
bufPointer to the data read.
lenThe length of the data read.
offsetThe offset the data was read from.

Function Documentation

◆ stream_flash_buffered_write()

int stream_flash_buffered_write ( struct stream_flash_ctx ctx,
const uint8_t data,
size_t  len,
bool  flush 
)

#include <zephyr/storage/stream_flash.h>

Process input buffers to be written to flash device in single blocks.

Will store remainder between calls.

A final call to this function with flush set to true will write out the remaining block buffer to flash.

Parameters
ctxcontext
datadata to write
lenNumber of bytes to write
flushwhen true this forces any buffered data to be written to flash A write with the flush set to true has to be issued as the last write request for a given context, as it concludes write of a stream; there must not be issued any more write requests for given context, unless it is re-initialized, and such write attempts may result in the function returning error.
Returns
non-negative on success, negative errno code on fail

◆ stream_flash_bytes_written()

size_t stream_flash_bytes_written ( struct stream_flash_ctx ctx)

#include <zephyr/storage/stream_flash.h>

Read number of bytes written to the flash.

Note
api-tags: pre-kernel-ok isr-ok
Parameters
ctxcontext
Returns
Number of payload bytes written to flash.

◆ stream_flash_erase_page()

int stream_flash_erase_page ( struct stream_flash_ctx ctx,
off_t  off 
)

#include <zephyr/storage/stream_flash.h>

Erase the flash page to which a given offset belongs.

This function erases a flash page to which an offset belongs if this page is not the page previously erased by the provided ctx (ctx->last_erased_page_start_offset).

Parameters
ctxcontext
offoffset from the base address of the flash device
Returns
non-negative on success, negative errno code on fail

◆ stream_flash_init()

int stream_flash_init ( struct stream_flash_ctx ctx,
const struct device fdev,
uint8_t buf,
size_t  buf_len,
size_t  offset,
size_t  size,
stream_flash_callback_t  cb 
)

#include <zephyr/storage/stream_flash.h>

Initialize context needed for stream writes to flash.

Parameters
ctxcontext to be initialized
fdevFlash device to operate on
bufWrite buffer
buf_lenLength of write buffer. Can not be larger than the page size. Must be multiple of the flash device write-block-size.
offsetOffset within flash device to start writing to
sizeNumber of bytes available for performing buffered write. If this is '0', the size will be set to the total size of the flash device minus the offset.
cbCallback to be invoked on completed flash write operations.
Returns
non-negative on success, negative errno code on fail

◆ stream_flash_progress_clear()

int stream_flash_progress_clear ( struct stream_flash_ctx ctx,
const char *  settings_key 
)

#include <zephyr/storage/stream_flash.h>

Clear persistent stream write progress stored with key settings_key .

Parameters
ctxcontext
settings_keykey previously used for storing the stream write progress
Returns
non-negative on success, negative errno code on fail

◆ stream_flash_progress_load()

int stream_flash_progress_load ( struct stream_flash_ctx ctx,
const char *  settings_key 
)

#include <zephyr/storage/stream_flash.h>

Load persistent stream write progress stored with key settings_key .

This function should be called directly after stream_flash_init to load previous stream write progress before writing any data. If the loaded progress has fewer bytes written than ctx then it will be ignored.

Parameters
ctxcontext
settings_keykey to use with the settings module for loading the stream write progress
Returns
non-negative on success, negative errno code on fail

◆ stream_flash_progress_save()

int stream_flash_progress_save ( struct stream_flash_ctx ctx,
const char *  settings_key 
)

#include <zephyr/storage/stream_flash.h>

Save persistent stream write progress using key settings_key .

Parameters
ctxcontext
settings_keykey to use with the settings module for storing the stream write progress
Returns
non-negative on success, negative errno code on fail