Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
|
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 (const 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 (const struct stream_flash_ctx *ctx, const char *settings_key) |
Save persistent stream write progress using key settings_key . | |
int | stream_flash_progress_clear (const struct stream_flash_ctx *ctx, const char *settings_key) |
Clear persistent stream write progress stored with key settings_key . | |
Abstraction over stream writes to flash.
#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.
buf | Pointer to the data read. |
len | The length of the data read. |
offset | The offset the data was read from. |
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 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, and flushes buffers to storage device.
ctx | context |
data | data to write |
len | Number of bytes to write |
flush | when true this forces any buffered data to be written to flash |
size_t stream_flash_bytes_written | ( | const struct stream_flash_ctx * | ctx | ) |
#include <zephyr/storage/stream_flash.h>
Read number of bytes written to the flash.
ctx | context |
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).
ctx | context |
off | offset from the base address of the flash device |
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.
ctx | context to be initialized |
fdev | Flash device to operate on |
buf | Write buffer |
buf_len | Length of write buffer. Can not be larger than the page size. Must be multiple of the flash device write-block-size. |
offset | Offset within flash device to start writing to |
size | Number 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. |
cb | Callback to be invoked on completed flash write operations. |
int stream_flash_progress_clear | ( | const 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
.
ctx | context |
settings_key | key previously used for storing the stream write progress |
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.
ctx | context |
settings_key | key to use with the settings module for loading the stream write progress |
off
is out of area designated for stream or negative errno code on fail int stream_flash_progress_save | ( | const struct stream_flash_ctx * | ctx, |
const char * | settings_key ) |
#include <zephyr/storage/stream_flash.h>
Save persistent stream write progress using key settings_key
.
ctx | context |
settings_key | key to use with the settings module for storing the stream write progress |