Enhance NVS module with a dedicated background task
- Implemented a dedicated background task to decouple long-running code from the main application task. - Improved the NVS commit code logic, especially for batch writes to minimize flash wear. - Updated NVS functions to support asynchronous writes and synchronous reads. - Added default value parameters to `get` functions for better usability. - Improved error handling and logging in NVS operations. - Refactored related code in multiple source files to accommodate these changes. Refs #1085, #1096 and closes #1098
This commit is contained in:
10
README.md
10
README.md
@@ -31,6 +31,16 @@ Another optional feature is NVS storage, which saves the configuration permanent
|
||||
- Tilt sensitivity
|
||||
- Last tilt position
|
||||
|
||||
### NVS Operation Details
|
||||
When NVS storage is enabled (CONFIG_RELAY_CHN_ENABLE_NVS=y), the component creates a dedicated background task to manage all NVS write operations. This design has important implications for how you use the NVS-related functions:
|
||||
- **Asynchronous Writes:** All `set` operations (e.g., `relay_chn_flip_direction()`, `relay_chn_set_run_limit()`) are asynchronous. They add the write request to a queue and return immediately, preventing the calling task from being blocked.
|
||||
- **Synchronous Reads:** All get operations (e.g., `relay_chn_get_direction()`) are synchronous. They read the value directly from the NVS storage and will block the calling task until the read is complete.
|
||||
- **Batched Commits:** To optimize performance and minimize flash wear, the NVS task uses a batching mechanism for writes. It collects multiple write requests and commits them to the NVS flash in a single operation after a short period of inactivity (typically 200ms).
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Due to the asynchronous and batched nature of write operations, a call to a get function may not immediately reflect a value that was just written by a set function. Your application should account for this small delay.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
Configure the component through menuconfig under "Relay Channel Driver Configuration":
|
||||
|
||||
Reference in New Issue
Block a user