Commit graph

40 commits

Author SHA1 Message Date
Yong Cong Sin e993e994ea sensors: add new channel SENSOR_CHAN_POS_DXYZ
Add new channel: `SENSOR_CHAN_POS_DXYZ`, so that it is
consistent with other 3-axis channels.

Updated pytest, `sensor_shell` & `fake_sensor` accordingly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin 4e7168028b sensors: shell: use SENSOR_CHANNEL_3_AXIS whenever possible
Instead of specifying 3 axis channels manually, use
`SENSOR_CHANNEL_3_AXIS` instead.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin eb37b8620b sensor_shell: fix hang when device is not a sensor
If `CONFIG_SENSOR_INFO` is enabled, use the `sensor_info`
section to validate that the argument is a sensor before using,
otherwise the shell command will hang the application.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin e879cd0502 sensor_shell: fix assertion due to NULL pointer deref
The `SENSOR_CHAN_VSHUNT` was added in #60717 but was never
added to the `sensor_channel_name[SENSOR_CHAN_COMMON_COUNT]`
table. Since the length of `sensor_channel_name` is fixed to
`SENSOR_CHAN_COMMON_COUNT`, this means that the index at
`SENSOR_CHAN_VSHUNT` points to `NULL`. When we use the
`sensor get` command for anything bigger than
`SENSOR_CHAN_VSHUNT`, we will deref that `NULL` pointer
when we do `strcmp` in the for-loop of `parse_named_int`.

Fix this by defining `SENSOR_CHAN_VSHUNT` in the table.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin 1e196f0f75 sensor: sensor_shell: print something when trig command succeeds
Print something to the shell when the `trig` command
completed successfully.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-20 22:56:11 +03:00
Yong Cong Sin 5f1e1c7b34 drivers: sensor: sensor_shell: fix infinite loop when doing sensor get
Should increment `ch.chan_idx` instead of `channel_idx`,
otherwise we will be stucked in the loop forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-17 14:34:09 +02:00
Tom Burdick b249535093 sensors: Add channel specifier
Use a structured channel specifier rather than a single enum when
specifying channels to read in the new read/decoder API.

Replaces usages of a seperate channel and channel_index parameter
where previously used with a struct sensor_chan_spec.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-05-17 09:30:18 +02:00
Jeppe Odgaard 29cc0e6aed sensor: add SENSOR_CHAN_O2 enum value
Add an enum value to support O2 sensors.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2024-03-26 10:46:30 -04:00
Mike J. Chen e56c89eb0c sensor_shell: add CONFIG to support trigger for more than one sensor device
Before, only one sensor device was supported. It
was possible to set a trigger on a second sensor
device, but the filtering of the channel data
would cause no channels from the new sensor
device to be read.

Also in trigger handler log of sampled data, print
the sensor name and channe name (instead of channel
number).

Signed-off-by: Mike J. Chen <mjchen@google.com>
2024-01-19 13:51:48 +01:00
Yuval Peress 3c6e66e5b5 sensors: convert fifo_wm to batch_dur
Having a % FIFO watermark isn't very useful as it doesn't convey how long
the SoC can sleep (or do other work) while batching sensor data. Convert
the attribute to a batch duration using ticks. Currently the ticks are
in system ticks, but eventually when an external clock is attached to
the sensor it will be in the external clock's ticks.

Signed-off-by: Yuval Peress <peress@google.com>
2023-11-10 12:16:46 -06:00
Yuval Peress 94dc05b3f2 sensors: Add streaming APIs
Introduce a streaming API that uses the same data path as the async API.

This includes features to the decoder:
* Checking if triggers are present

Adding streaming features built ontop of existing triggers:
* Adding 3 operations to be done on a trigger
  * include - include the data with the trigger information
  * nop - do nothing
  * drop - drop the data (flush)
* Add a new sensor_stream() API to mirror sensor_read() but add an
optional handler to be able to cancel the stream.

Signed-off-by: Yuval Peress <peress@google.com>
topic#sensor_stream
2023-11-10 12:16:46 -06:00
Yuval Peress 5e14088a3f sensors: vertically decode raw data
Update the decoder APIs to vertically decode the raw sensor data. This
means that instead of getting each channel on a frame by frame basis,
the API takes a channel specifier and returns as many frames of that
given channel as there's room.

The goal of this is to make the end decoded result the most useful and
usable for the Zephyr application. See #60944 for details.

Signed-off-by: Yuval Peress <peress@google.com>
2023-09-25 09:47:26 +02:00
Fabio Baltieri 13dfa0ac27 sensors: shell: implement rounding for q31_t
Since the sensor shell command was converted to use qt31_t, all the
integer values started to show up as rounded up by a fractional unit
when displayed, due to the conversion always rounding down.

Fix that by using the recently introduced DIV_ROUND_CLOSEST and handling
rounding up to next integer explicitly.

Before:

channel idx=44 gauge_state_of_charge value=83.999999

after:

channel idx=44 gauge_state_of_charge value=84.000000

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-07 11:26:02 +02:00
Marco Argiolas 5fc1777055 drivers: sensor: add mutex to cmd_get_sensor()
Add a mutex to protect shared data-structures, since shell can have
multiple backends.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-07-26 09:35:57 -05:00
Tristan Honscheid dc9bd3afe3 sensors: Create sensor trig subcommand
This PR relocates the sensor trigger sample application from the
`sensor_shell` sample to a subcommand in the actual sensor shell. The
subcommand has a UI for enabling a given trigger on a given sensor.
A built-in handler for the data_ready trigger is included that prints
the latest data to the log. Currently, only `SENSOR_TRIG_DATA_READY` is
supported but the groundwork is there to add others. Tested on a
`tdk_robokit1` board.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2023-05-27 05:33:11 -04:00
Yuval Peress ca5bf10143 sensor_shell: Update to new sensor_read API
Update the sensor shell logic to use the new sensor_read() APIs and
make triggers an option of the sensor_shell sample (this avoids the
trigger stealing the interrupt status from one-shot reads).

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-26 11:04:54 -05:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Yuval Peress ad4cb88494 sensor_shell: add attribute support
Add 2 new sub-commands to the sensor command (attr_get and attr_set).
These commands can be used to access the driver's attr_set and attr_get
functions.

Signed-off-by: Yuval Peress <peress@google.com>
2023-01-25 09:48:05 -06:00
Yuval Peress 3f4c568f71 sensor_shell: run clang-format
Run clang-format on the sensor_shell.c to make diffs easier for the
next commit.

Signed-off-by: Yuval Peress <peress@google.com>
2023-01-25 09:48:05 -06:00
Marco Argiolas be4ee1edef drivers: sensor: sensor_shell: fix channel name collision
Channel SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY was returned in place of
SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY, due to their matching names.
Ensuring that the channel names are unique fixes the issue.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2022-11-09 09:44:27 -06:00
Maureen Helm 0ddc2a9b65 drivers: sensor: Remove brackets from sensor info shell command output
Brackets were originally used in the sensor info shell command output to
make it obvious when a field is a null string, however they incorrectly
suggest that a field is an array. Remove the brackets and conditionally
print "(null)" instead.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-11-02 15:40:24 +09:00
Maureen Helm 97defe7095 drivers: sensor: Add shell command to get sensor info iterable section
Adds a new conditional shell command to the sensor shell to get data
from the sensor info iterable section, such as vendor and model name,
for all sensors.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-10-31 11:21:37 +01:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Bartosz Bilas fd316a5452 drivers: sensor_shell: add missing power sensor channel
There is no power channel within the name array that
is used by e.g INA23X so let's add it to have support
in sensor shell commands.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2021-10-19 07:15:55 -04:00
Christopher Friedt 5c7f395f8f Revert "include: driver: sensor: add tank level channel in units of percent"
This reverts commit f51aec4307.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-08-10 09:44:48 -05:00
Nick Ward f51aec4307 include: driver: sensor: add tank level channel in units of percent
Provides an enum for tank level sensor drivers.

Signed-off-by: Nick Ward <nick.ward@setec.com.au>
2021-08-09 16:24:50 -04:00
Stephane D'Alu 61b0009bdf sensor_shell: added missing sensor channel.
Synchronized with list of channel defined in sensor.h

Signed-off-by: Stephane D'Alu <sdalu@sdalu.com>
2020-11-02 09:52:54 -06:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Simon Glass 9b8c04401d sensor: shell: Show the error code when reading fails
The error code may give a clue as to what is wrong. Add it to the error
message.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-23 12:12:09 -04:00
Simon Glass 122d8fa6a9 sensor: shell: Allow output for fuel-gauge channels
Add names for more channels so that they can be shown, e.g.:

$ sensor get MAX17055
channel idx=38 gauge_voltage =   4.313906
channel idx=39 gauge_avg_current = 558.000000
channel idx=42 gauge_temp =  23.558558
channel idx=43 gauge_state_of_charge = 100.000003
channel idx=44 gauge_full_cap = 6766.000000
channel idx=45 gauge_remaining_cap = 6766.000000
channel idx=46 gauge_nominal_cap = 6910.000000
channel idx=50 gauge_time_to_empty =   0.000000
channel idx=51 gauge_time_to_full =   0.000000
channel idx=52 gauge_cycle_count =   0.100000
channel idx=53 gauge_design_voltage =   3.860000
channel idx=55 gauge_desired_charging_current = 2000.000000

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-23 12:12:09 -04:00
Tomasz Bursztyka 8260736268 drivers: Remove useless device start/end pointers
Commit id a538dcd8f8 got rid of the usage of these pointers so they are
useless now and can be removed in this drivers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-26 11:09:28 -05:00
Peter Bigot a538dcd8f8 shell: refactor device_name_get implementation
Several shell modules use cloned code to iterate over all devices and
identify the nth instance that meets some criteria.  The code was
repetitive and included various errors.  Abstract to a helper function
that performs the check consistently.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-23 13:27:14 +02:00
Henrik Brix Andersen 05da68c7cb drivers: sensor: shell: allow passing channel as number
Allow passing the channel as a number instead of a string in order to
support sensor-specific channels (channel SENSOR_CHAN_PRIV_START and
up).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-06-15 12:59:20 -05:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Tomasz Bursztyka 8d7bb8ffd8 device: Refactor device structures
When the device driver model got introduced, there were no concept of
SYS_INIT() which can be seen as software service. These were introduced
afterwards and reusing the device infrastructure for simplicity.
However, it meant to allocate a bit too much for something that only
required an initialization function to be called at right time.

Thus refactoring the devices structures relevantly:
- introducing struct init_entry which is a generic init end-point
- struct deviceconfig is removed and struct device owns everything now.
- SYS_INIT() generates only a struct init_entry via calling
  INIT_ENTRY_DEFINE()
- DEVICE_AND_API_INIT() generates a struct device and calls
  INIT_ENTRY_DEFINE()
- init objects sections are in ROM
- device objects sections are in RAM (but will end up in ROM once they
  will be 'constified')

It also generate a tiny memory gain on both ROM and RAM, which is nice.

Perhaps kernel/device.c could be renamed to something more relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Anas Nashif ab6179c6fe sensor: shell: return -ENODEV on binding errors
If we can't bind to a device, return -ENODEV and do not continue.

Fixes #22429
Coverity-ID: 207989

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-10 19:05:03 -04:00
Peter Bigot 165fe48229 treewide: use full path to sensor.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Krzysztof Chruscinski 95b4d37230 drivers: sensor: shell: Improved shell support for sensors
Added autocompletion to 'sensor get' command. After this change
device and channels are autocompleted. It is possible to provide
multiple channels for reading.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-01-08 12:59:46 -05:00
Diego Sueiro 93e1560faa subsys/shell: Introduce the Sensor Shell Module
Adds a Shell Module for retrieving Sensor data. The following commands
were added:

sensor - Device commands
Options:
  -h, --help  :Show command help.
Subcommands:
  get            :<device_name> [chanel_idx]
  list           :List configured sensors
  list_channels  :<device_name>

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2019-12-19 15:54:04 -05:00