Skip to content

Commit 196fc5c

Browse files
de-nordickartben
authored andcommitted
storage/stream_flash: Make write callback optional
The commit adds Kconfig option CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK that allows to turn off support for callback invoked after data is written to storage device. If the feature is not used disabling it allows to save some storage. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 73f55a6 commit 196fc5c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

include/zephyr/storage/stream_flash.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ struct stream_flash_ctx {
6161
size_t bytes_written; /* Number of bytes written to flash */
6262
size_t offset; /* Offset from base of flash device to write area */
6363
size_t available; /* Available bytes in write area */
64+
#ifdef CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK
6465
stream_flash_callback_t callback; /* Callback invoked after write op */
66+
#endif
6567
#ifdef CONFIG_STREAM_FLASH_ERASE
6668
off_t last_erased_page_start_offset; /* Last erased offset */
6769
#endif
@@ -82,6 +84,8 @@ struct stream_flash_ctx {
8284
* If this is '0', the size will be set to the total size
8385
* of the flash device minus the offset.
8486
* @param cb Callback to be invoked on completed flash write operations.
87+
* Callback is supported when CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK
88+
* is enabled.
8589
*
8690
* @return non-negative on success, negative errno code on fail
8791
*/

subsys/storage/stream/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ menuconfig STREAM_FLASH
1212

1313
if STREAM_FLASH
1414

15+
config STREAM_FLASH_POST_WRITE_CALLBACK
16+
bool "Write complete callback"
17+
default y
18+
help
19+
Enable callback that will be invoked once data is synchronized from
20+
stream to device. When callback is not used, disabling the option
21+
allows to save some code storage and RAM.
22+
1523
config STREAM_FLASH_ERASE
1624
bool "Perform erase operations"
1725
depends on FLASH_HAS_EXPLICIT_ERASE

subsys/storage/stream/stream_flash.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ static int flash_sync(struct stream_flash_ctx *ctx)
165165
return rc;
166166
}
167167

168+
#if defined(CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK)
169+
168170
if (ctx->callback) {
169171
/* Invert to ensure that caller is able to discover a faulty
170172
* flash_read() even if no error code is returned.
@@ -187,6 +189,8 @@ static int flash_sync(struct stream_flash_ctx *ctx)
187189
}
188190
}
189191

192+
#endif
193+
190194
ctx->bytes_written += ctx->buf_bytes;
191195
ctx->buf_bytes = 0U;
192196

@@ -317,7 +321,12 @@ int stream_flash_init(struct stream_flash_ctx *ctx, const struct device *fdev,
317321
ctx->offset = offset;
318322
ctx->available = (size == 0 ? inspect_flash_ctx.total_size - offset :
319323
size);
324+
325+
#if !defined(CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK)
326+
ARG_UNUSED(cb);
327+
#else
320328
ctx->callback = cb;
329+
#endif
321330

322331
#ifdef CONFIG_STREAM_FLASH_ERASE
323332
ctx->last_erased_page_start_offset = -1;

tests/subsys/storage/stream/stream_flash/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ CONFIG_SETTINGS=y
1313
CONFIG_STREAM_FLASH=y
1414
CONFIG_STREAM_FLASH_ERASE=y
1515
CONFIG_STREAM_FLASH_PROGRESS=y
16+
# It case if this is no longer y by default in Kconfig as
17+
# the tests are not ready to not test the feature.
18+
CONFIG_STREAM_FLASH_POST_WRITE_CALLBACK=y

0 commit comments

Comments
 (0)