|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef RRAM_WEAR_TEST_H_ |
| 8 | +#define RRAM_WEAR_TEST_H_ |
| 9 | + |
| 10 | +#include <stdbool.h> |
| 11 | +#include <stddef.h> |
| 12 | +#include <stdint.h> |
| 13 | + |
| 14 | +#ifdef __cplusplus |
| 15 | +extern "C" { |
| 16 | +#endif |
| 17 | + |
| 18 | +/** |
| 19 | + * @defgroup rram_wear_test RRAM wear test |
| 20 | + * |
| 21 | + * Writes 0x00 then 0xFF over a flash partition (or a forced custom range on the |
| 22 | + * internal flash device) and verifies readback. Intended for bring-up / stress checks. |
| 23 | + * @{ |
| 24 | + */ |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Flash partition (or custom range) parameters for wear test. |
| 28 | + * |
| 29 | + * For @c name @c "custom", @a addr_start and @a addr_end are byte offsets on the internal |
| 30 | + * flash device (@a addr_end exclusive). For any other name, offsets describe the partition |
| 31 | + * span from the flash map (see @ref rram_wear_test_partition_get); the verify path still |
| 32 | + * opens the area by name and ignores @a addr_* for the actual I/O. |
| 33 | + * |
| 34 | + * @a name may be an empty string when the partition has no DTS @c label (unnamed partition); |
| 35 | + * identification then relies on the flash map / node label. |
| 36 | + */ |
| 37 | +struct rram_wear_test_partition { |
| 38 | + const char *name; |
| 39 | + uint64_t addr_start; |
| 40 | + uint64_t addr_end; |
| 41 | +}; |
| 42 | + |
| 43 | +/** |
| 44 | + * @brief Get the number of entries in the partition table. |
| 45 | + */ |
| 46 | +size_t rram_wear_test_partition_count(void); |
| 47 | + |
| 48 | +/** |
| 49 | + * @brief Fill @a out with partition name and device byte range from the flash map. |
| 50 | + * |
| 51 | + * @param index Row index in <tt>[0, rram_wear_test_partition_count())</tt>. |
| 52 | + * @param[out] out Filled on success; @a name points at build-time string storage (possibly @c "" |
| 53 | + * when the partition has no DTS @c label). |
| 54 | + * |
| 55 | + * @retval 0 on success. |
| 56 | + * @retval -EINVAL if @a out is NULL. |
| 57 | + * @retval -ENOENT if @a index is out of range or the flash area cannot be opened. |
| 58 | + */ |
| 59 | +int rram_wear_test_partition_get(size_t index, struct rram_wear_test_partition *out); |
| 60 | + |
| 61 | +/** |
| 62 | + * @brief Run write/readback verify on a named flash region or custom range. |
| 63 | + * |
| 64 | + * Uses the internal partition table (see @a index), or |
| 65 | + * a custom byte range on the internal flash device when @a addr_end is greater than @a addr_start. |
| 66 | + * |
| 67 | + * @param index Partition index from the array to test. |
| 68 | + * @param addr_start Optional start offset for a custom range (used if addr_end > addr_start). |
| 69 | + * @param addr_end Optional end offset (exclusive) for a custom range. |
| 70 | + * @param force Must be true for custom ranges or @c -EPERM is returned. |
| 71 | + * |
| 72 | + * @retval 0 on success, negative errno otherwise (@c -EIO on pattern mismatch). |
| 73 | + */ |
| 74 | +int rram_wear_test(size_t index, uint64_t addr_start, uint64_t addr_end, bool force); |
| 75 | + |
| 76 | + |
| 77 | +/** @} */ |
| 78 | + |
| 79 | +#ifdef __cplusplus |
| 80 | +} |
| 81 | +#endif |
| 82 | + |
| 83 | +#endif /* RRAM_WEAR_TEST_H_ */ |
0 commit comments