124 Commits

Author SHA1 Message Date
Beat Küng
dffba3e03b param: move variable definitions to the top of the file 2017-04-06 11:49:03 +02:00
Beat Küng
a0e2b0c5a2 param: add param_control_autosave to enable/disable autosave 2017-04-06 11:49:03 +02:00
Beat Küng
f3e9739ab0 param export: use writer lock
to protect against concurrent writes to the same file
2017-04-06 11:49:03 +02:00
Beat Küng
a5cdff06d5 param: implement rate-limited autosave
- add a saving delay of 300ms
- save at most once every 2 seconds
2017-04-06 11:49:03 +02:00
Beat Küng
f6d9d77f60 param_notify_changes: set unsaved to true
This will make sure that commmander will save the params.
2017-03-14 21:43:30 +01:00
Beat Küng
0e650638e4 param: implement RW locking
This allows concurrent read access, which are much more common; reducing
potential lock contention and increasing concurrency.

Taking a lock is expensive, and the reader lock is now even more expensive.
An RCU synchronization scheme would reduce the overhead of the readers to
increasing/decreasing an atomic counter.
Thus this should only be an intermediate step until we move towards RCU.

Tested on SITL & Pixracer.
2017-03-14 21:30:53 +01:00
Beat Küng
b4290b6b52 params: make param_t uint16_t on NuttX
param_t is only used as an offset and we have <1000 params, so an uint16_t
is enough.
This saves roughly 1KB of RAM. We only do that on NuttX because normal
integers have better performance in general.
Previously on amd64, this was even 64bits because it was an uintptr_t.
2017-03-14 21:30:53 +01:00
Julian Oes
0c926106f1 param_shmem.c: comment out locking on Snappy
The param locking doesn't seem to be working on Snapdragon, so let's
just comment it out again.
2017-03-08 15:44:31 +01:00
Beat Küng
cfa84954ea param_get: add null-pointer check
If param_find() returned PARAM_INVALID, and this was directly passed to
param_get(), param_get_value_ptr() returned null and we read garbage data
(or segfaulted on systems with virtual memory).
On px4fmu-v2, this happened for the param ATT_VIBE_THRESH in sensors.
Because of the recently added parameter scoping, this param got pruned, as
it's defined in attitude_estimator_q.

credits for finding this go to Jeyong Shin (jeyong).
2017-02-25 11:02:15 +01:00
Beat Küng
a4050db766 param: comment what the lock is needed for 2017-02-17 11:27:08 +01:00
Beat Küng
df8f0da70c param & param_shmem: enable locking
We need to protect access to the param_values array. This is dynamically
allocated and resized (utarray_reserve() calls realloc). If some thread
was iterating the array while another was resizing the array, the first one
would iterate on a freed array, thus accessing invalid memory.

On NuttX this could lead to hardfaults in rare conditions.

Unfortunately we need to initialize the semaphore on startup, by calling
sem_init(). This adds a param_init() method called by every board/config
that uses the params (at least I think I've found all of them)
2017-02-17 11:27:08 +01:00
Beat Küng
fa3a6b890c param & flashparam param_export: use value directly instead of calling param_get
This call is not needed, and will avoid deadlocks when locking is enabled.
2017-02-17 11:27:08 +01:00
Beat Küng
42967df63f param command: use param_* calls even if flash-based params are enabled
This will ensure proper locking.
2017-02-17 11:27:08 +01:00
Beat Küng
32ed939ea4 param_shmem: readd dropped static to function definition 2017-02-03 13:57:48 +01:00
Beat Küng
a802caca87 param: add param_notify_changes() method
Can be used for example after several calls to
param_set_no_notification() to avoid unnecessary system notifications,
as it is an expensive change.
2017-02-03 13:57:48 +01:00
Stephan Brown
67a484ac34 Make parameter generation also depend on the scripts that run. Address some review comments. 2017-01-06 09:58:58 +01:00
Stephan Brown
92b2395ff6 param: Fix another off by 1 error and a formatting issue. 2017-01-06 09:58:58 +01:00
Stephan Brown
bf57e86dc2 param: Fix an off by 1 issue and some style fixes. 2017-01-06 09:58:58 +01:00
Stephan Brown
99228bdeb1 param: Use utarray_find when looking for changed parameters and use a binary search for finding param handles by name. 2017-01-06 09:58:58 +01:00
Lorenz Meier
2cfcf3402e Systemlib: Header cleanup 2016-12-27 21:00:51 +01:00
David Sidrane
1781801151 Scope irq_state to function using it 2016-12-21 08:34:22 +01:00
Henry Zhang
309c256e9e fix param interface (#5797)
* param: fix bug when param value is changed to 'zero' for the first time, it won't be saved.

* param: revert incorrectly removed code.
2016-11-06 14:45:17 +01:00
Carlo Wood
baf89f4398 Clean up of px4_defines.h (remove math.h)
This patch reorders px4_defines.h to make it more readable (I think)
but more importantly, cleans up the #include <math.h>/<cmath>
and [std::]isfinite stuff.

My main goal was to completely get rid of including math.h/cmath,
because that doesn't really belong in a header that is supposed to
define macro's and is included in almost every source file (if not
all).

I'm not sure what it did before ;) (pun intended), but now it does
the following:

PX4_ISFINITE is only used in C++ code (that was already the case,
but hereby is official; for C code just use 'isfinite()') and is
defined to be std::isfinite, except on __PX4_QURT because that uses
the HEXAGON toolset which (erroneously) defines isfinite as macro.

I would have liked to remove PX4_ISFINITE completely from the code
and just use std::isfinite whereever that is needed, but that would
have required changing the libecl submodule, and at the moment I'm
getting tired of changing submodules... so maybe something for the
future.

Also, all includes of <math.h> or <cmath> have been removed except
for __PX4_NUTTX. Like the HEXAGON toolset NuttX currently defines
isfinite as macro for C++. So, we could have solved this in the
same was as __P4_QURT; but since we can fix NuttX ourselves I chose
to add a kludge to px4_defines.h instead that fixes this problem,
until the time that NuttX can be fixed (again postponing changing
a submodule). The kludge still demands including <cmath>, thus.

After removal of the math header file, it needed to be included
in source files that actually need it, of course.

Finally, I had a look at the math macro's (like M_PI, M_PI_F,
M_DEG_TO_RAD etc). These are sometimes (erroneously) defined in
certain math.h header files (like both, hexagon and nuttx).
This is incorrect: neither the C nor the C++ standard defines
math constants (neither as macro nor otherwise). The "problem"
here was that px4_defines.h defined some of the M_*_F float
constants in terms of the M_* double constant, which are
sometimes not defined either thus. So, I cleaned this up by
defining the M_*_F math constants as float literals in px4_defines.h,
except when they are defined in math.h for that platform.
This means that math.h has to be always included when using those
constants, but well; not much difference there as those files
usually also need/use the macro NAN (which *is* a standard macro
defined by math.h).

Finally finally, DEFAULT_PARAM_FILE was removed as it isn't
used anymore.

All in all I think the resulting px4_defines.h is nice, giving me
much less the feeling of a nearly unmaintainable and over time
slowly growing collection of kludges and hacks.
2016-10-28 08:41:30 +02:00
Julian Oes
623b99327d param: lock the bus as short as possible (#5187)
Since the FRAM and the baro are on the same bus on the Pixracer, we
currently need to lock down everything (instead of just this SPI bus)
for the time when the params are written.
Therefore, we need to keep this locking as short as possible.

This change makes the locking even shorter by moving all param_get and
param_name and param_size calls out of the lock.
2016-08-01 02:15:21 -07:00
David Sidrane
5e8d6375c9 Back Port nuttx_v3 FLASH based parameter hooks 2016-07-13 20:42:05 +02:00
Daniel Agar
b8b855f2aa param.c fix style 2016-06-26 17:36:45 -04:00
Lorenz Meier
3c2bd4f6dd Param interface: Only mark as changed if value changed 2016-06-26 22:29:14 +02:00
jwilson
a73ac821ab Fixes shared memory locking bug and eliminates the need for an AppsProm driver to reserve a shared memory region. 2016-06-22 08:57:06 +02:00
Julian Oes
11cc17b63a param_shmem: be less verbose 2016-06-07 22:10:56 +02:00
Julian Oes
93ada40bf9 param_shmem: removed a printf 2016-06-07 22:10:56 +02:00
Lorenz Meier
7398164fcc Updated PX4 use / API of low level GPIO and other hardware-centric system facilities 2016-05-28 14:56:17 +02:00
Daniel Agar
2487dbfc92 remove Wpacked and cleanup unused warning flags 2016-05-19 21:49:34 +02:00
Daniel Agar
9c32792017 param_test link libmsg_gen 2016-05-14 11:27:07 +02:00
Daniel Agar
76387b1693 uorb autogeneration 2016-05-14 11:27:07 +02:00
Daniel Agar
d85e7732b4 fix param_test 2016-05-13 13:01:42 +02:00
Lorenz Meier
192510ee1c FMUv4 compile fix 2016-05-05 14:09:03 +02:00
Julian Oes
e3c9135ac2 param_shmem: fix bug where params didn't stick
There was the case where a param was changed on the Linux side but the
change did not get saved on the DSP side because the param was not in
the local list of changed params on the DSP side. On save, the param
index is now refreshed, and param_get is called on all params that have
changed. This is a hacky workaround but resolves the problem for now.
2016-04-26 10:21:01 +02:00
Julian Oes
a302e79bb6 param_shmem: be less chatty, printf cleanup 2016-04-24 20:03:10 +02:00
Julian Oes
22847e49e7 param_shmem: fix style 2016-04-12 13:15:50 +02:00
Julian Oes
9cfffc9747 param_shmem: do fsync after param write 2016-04-12 13:15:50 +02:00
Julian Oes
60d66dc23f param_shmem: before saving update the param 2016-04-05 13:02:53 +02:00
Julian Oes
4a1e9d610b param_shmem: fix the "unknown param id" bug
The recent workaround to flag all params as used did not include
param_for_used_index(). However, this function got used in the case if
one param had not been received by QGC and was requested by its index.
2016-03-22 20:38:11 +01:00
Julian Oes
61baef4b65 param_shmem: fix format 2016-03-18 11:26:29 +00:00
Julian Oes
06d7a9c491 param_shmem: fixes for params on Snapdragon
On Snapdragon we can't yet use the "used" mask for parameters and
therefore need to send all of them down to the ground station. All
params were set to used in an earlier commit but the count and index
function didn't reflect this change. This is fixed now, therefore we can
successfully receive all params in QGC.
2016-03-18 11:26:29 +00:00
Julian Oes
881a2a5860 param_shmem: make all params used
This is a workaround for the fact that the used information is not
shared between the ADSP and the Linux side on the Snapdragon. By
flagging all params used, we can at least receive them on QGC.
2016-03-10 22:26:31 +01:00
jwilson
75fad09263 Fixed problem causing a failure to obtain the shared memory lock on the AppsProc. 2016-02-19 16:59:49 +01:00
jwilson
4adfea7fa9 Resolved shared memory parameter problems and removed additional debug code. 2016-02-19 16:59:49 +01:00
Julian Oes
4b2be9c9d4 param_shmem: remove debug noise 2016-02-19 16:59:46 +01:00
Mark Charlebois
791ec37f43 Code formatter fixes
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2016-02-19 16:59:46 +01:00
Mark Charlebois
caa94d58a6 Manually integrated Jim's changes from integrate2_jim branch
Signed-off-by: Jim Wilson <jywilson99@hotmail.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2016-02-19 16:59:46 +01:00