|
| 1 | +.. zephyr:code-sample:: zms |
| 2 | + :name: Zephyr Memory Storage (ZMS) |
| 3 | + :relevant-api: zms_high_level_api |
| 4 | + |
| 5 | + Store and retrieve data from storage using the ZMS API. |
| 6 | + |
| 7 | +Overview |
| 8 | +******** |
| 9 | + The sample shows how to use ZMS to store ID/VALUE pairs and reads them back. |
| 10 | + Deleting an ID/VALE pair is also shown in this sample. |
| 11 | + |
| 12 | + The sample stores the following items: |
| 13 | + 1- A string representing an IP-address: stored at id=1, data="192.168.1.1" |
| 14 | + 2- A binary blob representing a key/value pair: stored at id=0xbeefdead, |
| 15 | + data={0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF} |
| 16 | + 3- A variable (32bit): stored at id=2, data=cnt |
| 17 | + 4- A long set of data (128 bytes) |
| 18 | + A loop is executed where we mount the storage system, and then write all set |
| 19 | + of data. |
| 20 | + Each DELETE_ITERATION period, we delete all set of data and verify that it has been deleted. |
| 21 | + We generate as well incremented ID/value pairs, we store them until storage is full, then we |
| 22 | + delete them and verify that storage is empty. |
| 23 | + |
| 24 | +Requirements |
| 25 | +************ |
| 26 | + |
| 27 | +* A board with flash support or native_sim target |
| 28 | + |
| 29 | +Building and Running |
| 30 | +******************** |
| 31 | + |
| 32 | +This sample can be found under :zephyr_file:`samples/subsys/fs/zms` in the Zephyr tree. |
| 33 | + |
| 34 | +The sample can be built for several platforms, but for the moment it has been tested only |
| 35 | +on native_sim target |
| 36 | + |
| 37 | +.. zephyr-app-commands:: |
| 38 | + :zephyr-app: samples/subsys/fs/zms |
| 39 | + :goals: build |
| 40 | + :compact: |
| 41 | + |
| 42 | +After running the generated image on a native_sim target, the output on the console shows the |
| 43 | +multiple Iterations of read/write/delete exectuted. |
| 44 | + |
| 45 | +Sample Output |
| 46 | +============= |
| 47 | + |
| 48 | +.. code-block:: console |
| 49 | +
|
| 50 | + *** Booting Zephyr OS build v3.7.0-2383-g624f75400242 *** |
| 51 | + [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes |
| 52 | + [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, fc0 |
| 53 | + [00:00:00.000,000] <inf> fs_zms: data wra: 0, 0 |
| 54 | + ITERATION: 0 |
| 55 | + Adding IP_ADDRESS 172.16.254.1 at id 1 |
| 56 | + Adding key/value at id beefdead |
| 57 | + Adding counter at id 2 |
| 58 | + Adding Longarray at id 3 |
| 59 | + [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes |
| 60 | + [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f80 |
| 61 | + [00:00:00.000,000] <inf> fs_zms: data wra: 0, 8c |
| 62 | + ITERATION: 1 |
| 63 | + ID: 1, IP Address: 172.16.254.1 |
| 64 | + Adding IP_ADDRESS 172.16.254.1 at id 1 |
| 65 | + Id: beefdead, Key: de ad be ef de ad be ef |
| 66 | + Adding key/value at id beefdead |
| 67 | + Id: 2, loop_cnt: 0 |
| 68 | + Adding counter at id 2 |
| 69 | + Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5 |
| 70 | + 4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |
| 71 | + Adding Longarray at id 3 |
| 72 | + . |
| 73 | + . |
| 74 | + . |
| 75 | + . |
| 76 | + . |
| 77 | + . |
| 78 | + [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes |
| 79 | + [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f40 |
| 80 | + [00:00:00.000,000] <inf> fs_zms: data wra: 0, 80 |
| 81 | + ITERATION: 299 |
| 82 | + ID: 1, IP Address: 172.16.254.1 |
| 83 | + Adding IP_ADDRESS 172.16.254.1 at id 1 |
| 84 | + Id: beefdead, Key: de ad be ef de ad be ef |
| 85 | + Adding key/value at id beefdead |
| 86 | + Id: 2, loop_cnt: 298 |
| 87 | + Adding counter at id 2 |
| 88 | + Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5 |
| 89 | + 4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |
| 90 | + Adding Longarray at id 3 |
| 91 | + Memory is full let's delete all items |
| 92 | + Free space in storage is 8064 bytes |
| 93 | + Sample code finished Successfully |
0 commit comments