mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-26 05:36:37 +08:00
params: Overhaul param system to use a layered approach without locking
- Instead we disable interrups on Nuttx where needed - No lock is held during param export. Params can be changed concurrently and we rely on the fact that another export will be triggered in that case.
This commit is contained in:
committed by
Beat Küng
parent
70178b66d8
commit
bc872822bc
@@ -42,7 +42,7 @@ add_library(flashparams
|
||||
flashparams.cpp
|
||||
)
|
||||
|
||||
add_dependencies(flashparams prebuild_targets)
|
||||
add_dependencies(flashparams prebuild_targets parameters_header)
|
||||
target_compile_definitions(flashparams PRIVATE -DMODULE_NAME="flashparams")
|
||||
target_compile_options(flashparams
|
||||
PRIVATE
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include <px4_platform_common/shutdown.h>
|
||||
#include <parameters/px4_parameters.hpp>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
@@ -54,7 +55,6 @@
|
||||
|
||||
#include <parameters/param.h>
|
||||
|
||||
#include "../uthash/utarray.h"
|
||||
#include <lib/tinybson/tinybson.h>
|
||||
#include "flashparams.h"
|
||||
#include "flashfs.h"
|
||||
@@ -78,7 +78,6 @@ struct param_wbuf_s {
|
||||
static int
|
||||
param_export_internal(param_filter_func filter)
|
||||
{
|
||||
struct param_wbuf_s *s = nullptr;
|
||||
bson_encoder_s encoder{};
|
||||
int result = -1;
|
||||
|
||||
@@ -86,28 +85,22 @@ param_export_internal(param_filter_func filter)
|
||||
|
||||
bson_encoder_init_buf(&encoder, nullptr, 0);
|
||||
|
||||
/* no modified parameters -> we are done */
|
||||
if (param_values == nullptr) {
|
||||
result = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((s = (struct param_wbuf_s *)utarray_next(param_values, s)) != nullptr) {
|
||||
for (param_t param = 0; param < user_config.PARAM_COUNT; param++) {
|
||||
|
||||
int32_t i;
|
||||
float f;
|
||||
|
||||
if (filter && !filter(s->param)) {
|
||||
if (filter && !filter(param)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* append the appropriate BSON type object */
|
||||
|
||||
switch (param_type(s->param)) {
|
||||
switch (param_type(param)) {
|
||||
case PARAM_TYPE_INT32:
|
||||
i = s->val.i;
|
||||
i = user_config.get(param).i;
|
||||
|
||||
if (bson_encoder_append_int32(&encoder, param_name(s->param), i)) {
|
||||
if (bson_encoder_append_int32(&encoder, param_name(param), i)) {
|
||||
debug("BSON append failed for '%s'", param_name(s->param));
|
||||
goto out;
|
||||
}
|
||||
@@ -115,9 +108,9 @@ param_export_internal(param_filter_func filter)
|
||||
break;
|
||||
|
||||
case PARAM_TYPE_FLOAT:
|
||||
f = s->val.f;
|
||||
f = user_config.get(param).f;
|
||||
|
||||
if (bson_encoder_append_double(&encoder, param_name(s->param), f)) {
|
||||
if (bson_encoder_append_double(&encoder, param_name(param), (double)f)) {
|
||||
debug("BSON append failed for '%s'", param_name(s->param));
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include "../DynamicSparseLayer.h"
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -57,9 +58,9 @@ __BEGIN_DECLS
|
||||
* the param_values and 2 functions to be global
|
||||
*/
|
||||
|
||||
__EXPORT extern UT_array *param_values;
|
||||
__EXPORT extern DynamicSparseLayer user_config;
|
||||
__EXPORT int param_set_external(param_t param, const void *val, bool mark_saved, bool notify_changes);
|
||||
__EXPORT const void *param_get_value_ptr_external(param_t param);
|
||||
__EXPORT void param_get_external(param_t param, void *val);
|
||||
|
||||
/* The interface hooks to the Flash based storage. The caller is responsible for locking */
|
||||
__EXPORT int flash_param_save(param_filter_func filter);
|
||||
|
||||
Reference in New Issue
Block a user