|
| 1 | +.. _lib_storage: |
| 2 | + |
| 3 | +Storage Library |
| 4 | +############### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +Overview |
| 11 | +******** |
| 12 | + |
| 13 | +The Storage library provides abstractions for reading, writing, and erasing non-volatile memory (NVM). |
| 14 | +It supports multiple storage instances, each bound to a specific memory region, and reports operation results through user-defined event handlers. |
| 15 | +Depending on the backend and runtime state, operations may be synchronous or asynchronous. |
| 16 | + |
| 17 | +Configuration |
| 18 | +************* |
| 19 | + |
| 20 | +The library is enabled and configured through Kconfig. |
| 21 | + |
| 22 | +Enable the library with :kconfig:option:`CONFIG_BM_STORAGE`. |
| 23 | + |
| 24 | +Select a backend using :kconfig:option:`CONFIG_BM_STORAGE_BACKEND`: |
| 25 | + |
| 26 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_RRAM` – RRAM backend. The events reported are synchronous. |
| 27 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_SD` – SoftDevice backend. The events reported are asynchronous. |
| 28 | + |
| 29 | +SoftDevice backend options: |
| 30 | + |
| 31 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_SD_QUEUE_SIZE` – Queue size for pending operations. |
| 32 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_SD_MAX_RETRIES` – Maximum retries if the SoftDevice is busy. |
| 33 | + |
| 34 | +Initialization |
| 35 | +============== |
| 36 | + |
| 37 | +Each storage instance is represented by a :c:struct:`bm_storage` structure. |
| 38 | + |
| 39 | +Initialize an instance with :c:func:`bm_storage_init`, providing: |
| 40 | + |
| 41 | +* :c:member:`bm_storage.evt_handler` – Event callback. |
| 42 | +* :c:member:`bm_storage.start_addr` and :c:member:`bm_storage.end_addr` – Accessible address range. |
| 43 | + |
| 44 | +Uninitialize with :c:func:`bm_storage_uninit`. |
| 45 | + |
| 46 | +Usage |
| 47 | +***** |
| 48 | + |
| 49 | +Read |
| 50 | +==== |
| 51 | + |
| 52 | +Use the :c:func:`bm_storage_read` function to copy data from NVM into RAM. |
| 53 | +The data length must be a multiple of the backend’s program unit and within the configured region. |
| 54 | + |
| 55 | +Write |
| 56 | +===== |
| 57 | + |
| 58 | +Use the :c:func:`bm_storage_write` function to write data to NVM. |
| 59 | +Writes are validated against alignment and range, and completion is reported through :c:member:`bm_storage.evt_handler`. |
| 60 | + |
| 61 | +Erase |
| 62 | +===== |
| 63 | + |
| 64 | +Use the :c:func:`bm_storage_erase` function to erase a region in NVM. |
| 65 | +``len`` must be a multiple of the erase unit. If not required by the backend, the call may return ``NRF_ERROR_NOT_SUPPORTED``. |
| 66 | + |
| 67 | +Busy state |
| 68 | +========== |
| 69 | + |
| 70 | +Use the :c:func:`bm_storage_is_busy` function to check whether a backend is executing an operation. |
| 71 | + |
| 72 | +Events |
| 73 | +====== |
| 74 | + |
| 75 | +The following events may be reported to the user callback: |
| 76 | + |
| 77 | +* :c:enum:`BM_STORAGE_EVT_WRITE_RESULT` – Write operation completed. |
| 78 | +* :c:enum:`BM_STORAGE_EVT_ERASE_RESULT` – Erase operation completed. |
| 79 | + |
| 80 | +Each event includes the result code, information about the address range of the associated operation, and if the operation is synchronous or asynchronous. |
| 81 | + |
| 82 | +Dependencies |
| 83 | +************ |
| 84 | + |
| 85 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_RRAM`: |
| 86 | + This backend doesn't have any dependency. |
| 87 | + |
| 88 | +* :kconfig:option:`CONFIG_BM_STORAGE_BACKEND_SD`: |
| 89 | + This backend requires the following Kconfig options to be enabled: |
| 90 | + * :kconfig:option:`CONFIG_SOFTDEVICE` |
| 91 | + * :kconfig:option:`CONFIG_NRF_SDH` |
| 92 | + * :kconfig:option:`CONFIG_RING_BUFFER` |
| 93 | + |
| 94 | +API documentation |
| 95 | +***************** |
| 96 | + |
| 97 | +| Header file: :file:`include/bm_storage.h` |
| 98 | +| Source files: :file:`lib/bm_storage/` |
| 99 | +
|
| 100 | +:ref:`Storage library API reference <api_storage>` |
0 commit comments