mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
refactor(parameters): merge Param<> constructor calls to save flash
Every Param<> constructor inlines param_set_used(handle()) followed by
param_get(handle(), &_val), materialising the handle constant twice at
each of the ~2000 instantiation sites. Fold both into a single
out-of-line param_get_mark_used() so each constructor emits one call.
The failsafe_web build stubs the param API itself, so it gets a matching
stub. The smaller constructors let the compiler fully inline the
defaulted FlightTaskDescend constructor on the ITCM boards, so its entry
is dropped from their linker scripts.
Saves 7232 B of .text on px4_fmu-v6x_default.
Co-authored-by: Balduin <balduin@auterion.com>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
(cherry picked from commit d3a2f02758)
Assisted-by: GitHub Copilot:gpt-6-astra
Backport-note: Use the original #28320 PR commit to retain its three ITCM linker cleanups, already supplied by #28321 before the main-branch squash.
This commit is contained in:
1 parent
2916b4f822
commit
759b04f1ee
7 files changed
+34
-13
No files matched your search
@@ -625,7 +625,6 @@
|
||||
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
|
||||
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
|
||||
*(.text._ZN17FlightTaskDescendC1Ev)
|
||||
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
|
||||
*(.text.iob_navail)
|
||||
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
|
||||
|
||||
@@ -625,7 +625,6 @@
|
||||
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
|
||||
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
|
||||
*(.text._ZN17FlightTaskDescendC1Ev)
|
||||
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
|
||||
*(.text.iob_navail)
|
||||
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
|
||||
|
||||
@@ -639,7 +639,6 @@
|
||||
*(.text._ZN36do_not_explicitly_use_this_namespace5ParamIfLN3px46paramsE919EEC1Ev) /* itcm-check-ignore */
|
||||
*(.text._ZN22MavlinkStreamHeartbeat8get_sizeEv)
|
||||
*(.text._ZN6matrix6MatrixIfLj3ELj1EEdVEf)
|
||||
*(.text._ZN17FlightTaskDescendC1Ev)
|
||||
*(.text._ZN26MavlinkStreamCameraTrigger8get_sizeEv)
|
||||
*(.text.iob_navail)
|
||||
*(.text._ZN12FailsafeBase25removeNonActivatedActionsEv)
|
||||
|
||||
@@ -118,8 +118,7 @@ public:
|
||||
|
||||
Param()
|
||||
{
|
||||
param_set_used(handle());
|
||||
update();
|
||||
param_get_mark_used(handle(), &_val);
|
||||
}
|
||||
|
||||
float get() const { return _val; }
|
||||
@@ -170,8 +169,7 @@ public:
|
||||
Param(float &external_val)
|
||||
: _val(external_val)
|
||||
{
|
||||
param_set_used(handle());
|
||||
update();
|
||||
param_get_mark_used(handle(), &_val);
|
||||
}
|
||||
|
||||
float get() const { return _val; }
|
||||
@@ -220,8 +218,7 @@ public:
|
||||
|
||||
Param()
|
||||
{
|
||||
param_set_used(handle());
|
||||
update();
|
||||
param_get_mark_used(handle(), &_val);
|
||||
}
|
||||
|
||||
int32_t get() const { return _val; }
|
||||
@@ -272,8 +269,7 @@ public:
|
||||
Param(int32_t &external_val)
|
||||
: _val(external_val)
|
||||
{
|
||||
param_set_used(handle());
|
||||
update();
|
||||
param_get_mark_used(handle(), &_val);
|
||||
}
|
||||
|
||||
int32_t get() const { return _val; }
|
||||
@@ -322,8 +318,11 @@ public:
|
||||
|
||||
Param()
|
||||
{
|
||||
param_set_used(handle());
|
||||
update();
|
||||
int32_t value_int;
|
||||
|
||||
if (param_get_mark_used(handle(), &value_int) == 0) {
|
||||
_val = value_int != 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool get() const { return _val; }
|
||||
|
||||
@@ -231,6 +231,18 @@ __EXPORT size_t param_size(param_t param);
|
||||
*/
|
||||
__EXPORT int param_get(param_t param, void *val);
|
||||
|
||||
/**
|
||||
* Mark a parameter as used and copy its value.
|
||||
*
|
||||
* Combines param_set_used() and param_get() into a single out-of-line call,
|
||||
* saving flash at the many Param<> constructor call sites.
|
||||
*
|
||||
* @param param A handle returned by param_find or passed by param_foreach.
|
||||
* @param val Where to return the value, assumed to point to suitable storage for the parameter type.
|
||||
* @return Zero if the parameter's value could be returned, nonzero otherwise.
|
||||
*/
|
||||
__EXPORT int param_get_mark_used(param_t param, void *val);
|
||||
|
||||
/**
|
||||
* Copy the (airframe-specific) default value of a parameter.
|
||||
*
|
||||
|
||||
@@ -157,3 +157,10 @@ param_get_system_default_value(param_t param, void *default_val)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
param_get_mark_used(param_t param, void *val)
|
||||
{
|
||||
param_set_used(param);
|
||||
return param_get(param, val);
|
||||
}
|
||||
@@ -102,6 +102,12 @@ void param_set_used(param_t param)
|
||||
used_params[param] = p;
|
||||
}
|
||||
|
||||
int param_get_mark_used(param_t param, void *val)
|
||||
{
|
||||
param_set_used(param);
|
||||
return param_get(param, val);
|
||||
}
|
||||
|
||||
std::vector<std::string> get_used_params()
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
|
||||
Reference in new issue
Block a user