92 Commits

Author SHA1 Message Date
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
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
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
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
Nate Weibley
0419a99f00 New param hashing spec
- When listing all params, lead with _HASH_CHECK value for cache load
 - When set value on _HASH_CHECK is rx'd, stop any ongoing listing req
2016-02-18 18:51:17 +01:00
Lorenz Meier
f52ce2001d Param lib: fix code style 2016-01-23 14:29:15 +01:00
Lorenz Meier
4b893053a0 param: Lock read operation 2016-01-23 13:32:52 +01:00
Lorenz Meier
c18d31ce41 Param write: Support locking the bus 2016-01-23 13:23:53 +01:00
Lorenz Meier
f460e95554 Param: Increase robustness of default save command 2016-01-22 14:21:09 +01:00
Lorenz Meier
3a43038583 Params: Provide set and save API 2016-01-22 11:35:56 +01:00
Nate Weibley
8a4699c656 Fix style 2015-10-12 15:26:11 -04:00
Nate Weibley
d7274ac5f0 Enable hash check of used parameters to verify integrity of GCS local copy 2015-10-12 13:40:14 -04:00
Daniel Agar
2529f07d44 restore format check 2015-10-06 18:28:30 -04:00
Lorenz Meier
b3a8ba4e92 param: Move to POSIX semaphore abstraction 2015-09-20 00:29:22 +02:00
Mark Charlebois
fc3acdb2c1 cmake: param refactoring
Use a struct to contain all the parameters so the ordering in
memory is not machine dependent.

Add number of parameters to the param struct. The struct actually
allows direct accessing by the member name if desired.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-09-11 12:41:00 -07:00
Mark Charlebois
b9ef1ee6ed param: Build param without linker script
Changed to enable the posix_sitl_simple target to build and run

param show *

without using a linker script

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-09-11 02:33:42 -07:00
Lorenz Meier
3bad91dd3b systemlib: Fix param access for used params 2015-06-25 09:28:04 +02:00
Mark Charlebois
872a26e6da Fixed passed ot open() for O_CREAT
In nuttx the mode parameter to open is not required but in Linux,
and per the POSIX spec, mode is required if the O_CREAT flag is
passed.

The mode flags are different for NuttX and Linux so a new set of
PX4 defines was added:

PX4_O_MODE_777 - read, write, execute for user, group and other
PX4_O_MODE_666 - read, and write for user, group and other
PX4_O_MODE_600 - read, and write for user

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-06-14 11:26:40 +02:00
Mark Charlebois
4d1ae6269b POSIX: Added PX4_ROOTFSDIR to file paths
Set a default path relative to current dir for the posix target.

Running make posixrun will create the required directoroes and then run
mainapp from its build location.

PX4_ROOTFSDIR is set to nothing for nuttx.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-06-11 21:36:13 -07:00
Lorenz Meier
3dbd48fbad param style fix 2015-06-03 22:51:02 +02:00
David Sidrane
03bdf1e5f2 Allow allocation of changed paramaters to fail, then all param functions will return PARAM_INVALID or a count of 0 2015-06-03 22:49:57 +02:00
David Sidrane
7950167bc5 Added assertion on allocation failure for parameter change storage, removed magic numbers 2015-06-03 22:49:57 +02:00
Mark Charlebois
1ca05aaa64 orb_advert_t changed to void * and checks changed to nullptr
The existing orb_advert_t use thoughout the code sometimes tries
to treat it as a file descriptor and there are checks for < 0
and ::close calls on orb_advert_t types which is an invalid use
of an object pointer, which is what orb_advert_t really is.

Initially I had changed the -1 initializations to 0 but it was
suggested that this should be nullptr. That was a good recommendation
but the definition of orb_advert_t had to change to void * because
you cannot initialize a uintptr_t as nullptr.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-05-27 14:42:49 -07:00
Mark Charlebois
a734fc96d1 extensive orb_advert_t fixes
The calls to orb_advertise were being mishandled throughout the code.
There were ::close() calls on memory pointers, there were checks
against < 0 when it is a pointer to a object and values larger than
0x7ffffffff are valid. Some places orb_advert_t variables were
being initialized as 0 other places as -1.

The orb_advert_t type was changed to uintptr_t so the pointer value
would not be wrapped as a negative number. This was causing a failure
on ARM.

Tests for < 0 were changed to == 0 since a null pointer is the valid
representation for error, or uninitialized.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-05-27 14:41:33 -07:00
Mark Charlebois
7301b59d14 Unit tests: Fixed unit test build
Unit tests now work. The linux build was failing saving params
because it was using the changes for QuRT that fake out the
filesystem.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
2015-05-19 13:36:13 -07:00
Lorenz Meier
e5fad077df Merge master into linux 2015-05-18 23:28:57 +02:00