Commit Graph

144 Commits

Author SHA1 Message Date
Henrik Brix Andersen
9783ed56d9 dts: bindings: can: deprecate the sjw and sjw-data properties
Update the descriptions for the various CAN devicetree timing properties
specified in Time Quanta (TQ) to make it clear that these, if present, are
only used for the initial timing parameters.

Deprecate the (Re-)Synchronization Jump Width (SJW) devicetree properties
for both arbitration and data phase timing as these are now only used in
combination with the other TQ-based CAN timing properties, which are all
deprecated.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-28 16:28:56 +02:00
Henrik Brix Andersen
a9d3935fa0 drivers: can: solely use sjw from devicetree for initial timing
Update the CAN controller drivers to solely use the sjw and sjw-data
devicetree properties for setting the initial timing when devicetree timing
parameters are specified in Time Quanta (TQ).

Any timing set via the CAN timing APIs will contain either user-provided or
automatically calculated SJW values. This includes any timing parameters
calculated from bus-speed and bus-speed-data devicetree properties.

Update the CAN controller driver tests accordingly and remove the
CAN_SJW_NO_CHANGE definition as it has lost its meaning.

Fixes: #63033

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-09-28 16:28:56 +02:00
Lucas Tamborrino
acb04612ac tests: drivers: can: api: add esp32 wrover board
Add esp32_devkitc_wrover boards to supported platforms

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
2023-08-16 10:25:49 +02:00
Marek Matej
3776402f40 boards: xtensa: esp32 board split
Remove virtual esp32 board and replace it with the
real word boards:

- esp32_devkitc_wroom
- esp32_devkitc_wrover (with PSRAM option)

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-25 18:12:33 +02:00
Lucas Tamborrino
b3fbdc158a tests: drivers: can: add esp32 and esp32s2
Add esp32 and esp32s2_saola boards to platform allow list

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
2023-07-24 13:25:11 +00:00
Eric Holmberg
4f88b831e7 boards: xiao_esp32s3: update CAN support
Add CAN to supported list and update documentation.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
2023-07-10 15:13:52 +02:00
Eric Holmberg
e408d0ea06 boards: esp32s3_devkitm: update CAN support
Add CAN to supported list and update documentation.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
2023-07-10 15:13:52 +02:00
Eric Holmberg
1b919bbc28 tests: drivers: can: api: add virtual CAN TX <-> RX Jumper
Remove the need for the can_transceiver fixture by assigning the CAN TX
and CAN RX lines to the same GPIO pin to allow for testing without a
transceiver or physical jumper.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
2023-07-10 15:13:52 +02:00
Henrik Brix Andersen
f3cafe7559 tests: drivers: can: api: do not quote overlay file name
Remove quotes from DTC_OVERLAY_FILE as they break the build.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-07-04 11:10:35 +00:00
Henrik Brix Andersen
98ba1175fd tests: drivers: can: api: fix test_set_timing_data_while_started test
Change the test_set_timing_data_while_started test to actually attempt to
set the data phase timing parameters instead of attempting to set the
nominal/arbitration timing parameters.

Update test descriptions to explicitly mention data phase timing.

Fixes: #59046

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-06-08 06:50:14 -04:00
Gerard Marull-Paretas
93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Henrik Brix Andersen
ef3d01d16f test: drivers: can: move build-only tests to proper location
Move the build-only test for the MCP2515 CAN controller driver to the
tests/drivers/build_all/can/ folder.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-05-01 09:30:42 -05:00
Henrik Brix Andersen
bd2651537c tests: drivers: can: api: test filters between CAN-FD/classic CAN modes
Test that filters are preserved when changing between CAN-FD mode and
classic CAN mode and vice versa.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-04-13 10:00:03 +02:00
Henrik Brix Andersen
702bc0d954 tests: drivers: can: api: fix comment
Fix comment describing CAN-FD format frame number 2.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-04-13 10:00:03 +02:00
Henrik Brix Andersen
719ebb6a27 tests: drivers: can: timing: use recommended sample point
Use the recommended sample point of 75.0% for the data phase bitrate test @
1Mbit/s. This matches the default sample point calculated in
can_common.c:sample_point_for_bitrate().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-11 19:45:00 +01:00
Henrik Brix Andersen
332f326ab1 tests: drivers: can: timing: remove superfluous timing test
Remove test for attempting to set an arbitration bitrate of
8000001 bit/s. This test belongs in the data phase timing test, where
it already present as well.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-11 08:47:34 +02:00
Henrik Brix Andersen
79c8d0e6aa tests: drivers: can: api: add tests for can_frame_matches_filter()
Add CAN API tests for the can_frame_matches_filter() utility function.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:12 +01:00
Henrik Brix Andersen
4e67546321 tests: drivers: can: api: adjust CAN IDs used for testing
Adjust the CAN IDs used for testing in order for them to match the various
can_*_filter_2 as documented in common.h.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:12 +01:00
Henrik Brix Andersen
9b39c43714 tests: drivers: can: api: use correct CAN ID in test_ext_masked_filter_2
Use the correct CAN ID in struct can_filter test_ext_masked_filter_2.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:12 +01:00
Henrik Brix Andersen
8875c3b2e9 tests: drivers: can: move CAN utility function tests to API tests
Move the CAN utility functions tests to a separate test suite under the CAN
API tests.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-23 09:00:12 +01:00
Henrik Brix Andersen
486b96eea8 tests: drivers: can: api: move test data to common files
Move the test definitions, frames, and filters to common.h/common.c and
reuse them between the classic CAN and CAN-FD API tests.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-21 18:02:37 -05:00
Henrik Brix Andersen
f312ab2d61 tests: drivers: can: fold the CAN-FD tests into the main API tests
Fold the CAN-FD specific tests into the main CAN API tests and stop
treating the CAN-FD API functionality as an add-on to CAN API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-02-21 18:02:37 -05:00
Kumar Gala
b582e5df99 tests: drivers: can: shell: increase test stack size
The test fails with a stack overflow on qemu_x86 when we build with
llvm.  Bump the test stack a little addresses the issue.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-02-11 08:14:39 +09:00
Henrik Brix Andersen
55d0ffa874 drivers: can: remove CAN_HAS_CANFD Kconfig helper
Remove the CAN_HAS_CANFD Kconfig helper symbol in order to allow enabling
CAN-FD support in the API regardless of driver support.

Change default to CAN-FD support being disabled and have samples and tests
that require CAN-FD support turn it on. This aligns the default
configuration across CAN controller drivers regardless of their
capabilities.

The rationale behind this is that we are starting to see MCUs with multiple
CAN controllers, some CAN-FD compatible, some not (e.g. NXP i.MX RT1060 and
FPGAs). Automatically enabling CAN-FD support based on the presence of a
CAN-FD capable CAN controller leads to different application default
settings based on the CAN controller(s) in use.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-25 15:00:39 +00:00
Henrik Brix Andersen
c6db73e93d tests: drivers: can: timing: use capabilities to skip tests
Use the CAN controller driver capabilities to determine if the CAN-FD
timing tests should be skipped or not. There is no need for special
handling of CONFIG_CAN_FD_MODE.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-25 15:00:39 +00:00
Cong Nguyen Huu
dd468fc261 tests: drivers: can: canfd: add support filter type frame
Add new filter to configure correctly FD frame.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-01-04 08:18:13 -06:00
Henrik Brix Andersen
f30a5969d0 drivers: can: make the fake CAN driver generally available
Make the fake CAN controller driver available for use in tests outside of
the CAN shell test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 08:19:33 -07:00
Henrik Brix Andersen
836f582664 drivers: can: skip all CAN loopback mode tests for kvaser,pcican
Skip all CAN controller tests utilizing CAN loopback mode for the
kvaser,pcican CAN controller card as emulated in QEMU.

QEMU emulation of the SJA1000 CAN controller backend does not yet support
the SJA1000 Self Reception Request command which is required for proper
loopback operation.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Henrik Brix Andersen
c49011442a tests: drivers: can: api: test sending CAN-FD frame in non-FD mode
Add test case for verifying that CAN-FD format frames cannot be sent in
non-FD mode.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-25 16:32:10 +02:00
Henrik Brix Andersen
f8a88cdb27 drivers: can: use flags fields for can_frame and can_filter structs
The can_frame and can_filter structs support a number of different flags
(standard/extended CAN ID type, Remote Transmission Request, CAN-FD format,
Bit Rate Switch, ...). Each of these flags is represented as a discrete bit
in the given structure.

This design pattern requires every user of these structs to initialize all
of these flags to either 0 or 1, which does not scale well for future flag
additions.

Some of these flags have associated enumerations to be used for assignment,
some do not. CAN drivers and protocols tend to rely on the logical value of
the flag instead of using the enumeration, leading to a very fragile
API. The enumerations are used inconsistently between the can_frame and
can_filter structures, which further complicates the API.

Instead, convert these flags to bitfields with separate flag definitions
for the can_frame and can_filter structures. This API allows for future
extensions without having to revisit existing users of the two
structures. Furthermore, this allows driver to easily check for unsupported
flags in the respective API calls.

As this change leads to the "id_mask" field of the can_filter to be the
only mask present in that structure, rename it to "mask" for simplicity.

Fixes: #50776

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-25 16:32:10 +02:00
Martin Jäger
2fd5cbdaf4 tests: drivers: can: api: add twai build-test for esp32c3
The TWAI peripheral needs a connected CAN transceiver also for testing
in loopback mode.

As there is no board available with this configuration, at least make
sure the CAN API test is built in CI for esp32c3_devkitm.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 09:55:09 +02:00
Martin Jäger
9cec058e8e boards: posix: native_posix: enable can_loopback0 by default
The .yaml file states that CAN is supported, but the basic sample
application samples/drivers/can/counter cannot be compiled without
additional configuration.

The loopback driver does not require any additional steps like the
linux SocketCAN driver, so it is safe to enable it by default and
get rid of the many overlay files in the tests.

ISO-TP tests and the counter sample are excluded via .yaml from
twister tests because of timing issues.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-03 10:17:12 +02:00
Henrik Brix Andersen
707fa6a1f6 tests: drivers: can: api: skip RTR tests if not supported
Skip the Remote Transmission Request (RTR) frame tests if the CAN
controller driver does not support RTR filters.

Fixes: #50218

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-21 08:50:47 +00:00
Henrik Brix Andersen
b4af14600a tests: drivers: can: shell: add tests for start/stop shell commands
Add tests for the CAN controller start/stop shell commands.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-13 16:06:50 +00:00
Henrik Brix Andersen
6cdb418e5d tests: drivers: can: fd: test returned error codes when started/stopped
Add tests for the required error return codes when the CAN controller is
started/stopped.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-13 16:06:50 +00:00
Henrik Brix Andersen
94d37023c6 tests: drivers: can: api: test returned error codes when started/stopped
Add tests for the required error return codes when the CAN controller is
started/stopped.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-13 16:06:50 +00:00
Henrik Brix Andersen
180cdc105e drivers: can: add start and stop CAN controller API functions
Up until now, the Zephyr CAN controller drivers set a default bitrate (or
timing) specified via devicetree and start the CAN controller in their
respective driver initialization functions.

This is fine for CAN nodes using only one fixed bitrate, but if the bitrate
is set by the user (e.g. via a DIP-switch or other HMI which is very
common), the CAN driver will still initialise with the default
bitrate/timing at boot and use this until the application has determined
the requested bitrate/timing and set it using
can_set_bitrate()/can_set_timing().

During this period, the CAN node will potentially destroy valid CAN frames
on the CAN bus (which is using the soon-to-be-set-by-the-application
bitrate) by sending error frames. This causes interruptions to the ongoing
CAN bus traffic when a Zephyr-based CAN node connected to the bus is
(re-)booted.

Instead, require all configuration (setting bitrate, timing, or mode) to
take place when the CAN controller is stopped. This maps nicely to entering
"reset mode" (called "configuration mode" or "freeze mode" for some CAN
controller implementations) when stopping and exiting this mode when
starting the CAN controller.

Fixes: #45304

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-13 16:06:50 +00:00
Henrik Brix Andersen
6d094d0ad5 tests: drivers: can: api: add missing test case documentation
Add missing CAN controller API test case documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-13 16:06:50 +00:00
Henrik Brix Andersen
2f925b47a7 tests: drivers: can: shell: poll for the dummy shell to be ready
Poll for the dummy shell to become ready and fail the tests if not.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-09-06 14:12:33 +00:00
Fabio Baltieri
e9e7ad388d tests: drivers: can: add a delay for the shell backend to initialize
The CAN shell test is flaky on some qemu platform (qemu_riscv64_smp in
particular), where the first test command occasionally fails as it tries
to run with the backend not initialized.

The tests for subsys/shell/shell/src/main.c have a setup delay, copying
it to the CAN shell test seems to make it work reliably.

Tested with:
  ./scripts/twister -v -n -M -p qemu_riscv64_smp -T tests/drivers/can/shell

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-09-05 19:00:18 +00:00
Henrik Brix Andersen
11ed7d62b7 tests: drivers: can: add test for the CAN shell module
Add test for the CAN shell module.

The tests execute a set of CAN shell module commands against a CAN
controller driver mock, verifies that the expected CAN controller driver
API functions are called, and that their arguments are as expected.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-31 10:45:35 +02:00
Gerard Marull-Paretas
a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Gerard Marull-Paretas
e0125d04af devices: constify statically initialized device pointers
It is frequent to find variable definitions like this:

```c
static const struct device *dev = DEVICE_DT_GET(...)
```

That is, module level variables that are statically initialized with a
device reference. Such value is, in most cases, never changed meaning
the variable can also be declared as const (immutable). This patch
constifies all such cases.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-19 11:51:26 +02:00
Henrik Brix Andersen
13c75417ba drivers: can: remove z prefix from public CAN API types
Remove the "z" prefix from the public CAN controller API types as this
makes them appear as internal APIs.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
6099e180b1 tests: move the SocketCAN tests to tests/net/socket/can
Move the SocketCAN tests from tests/drivers/can/utilities to
tests/net/socket/can to match the location of the code under test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
fe80c1676d drivers: can: move socketcan types and functions to socketcan header
Move the SocketCAN data types and helper functions from
zephyr/drivers/can.h to zephyr/net/socket_can.h as these are not used by
the low-level CAN controller driver API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 10:19:29 +02:00
Henrik Brix Andersen
f04741da75 tests: drivers: can: utilities: convert to new ztest API
Convert the CAN utilities test suite to use the new ztest API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-12 13:23:00 +02:00
Henrik Brix Andersen
b4033d25f6 tests: drivers: can: timing: convert to new ztest API
Convert the CAN controller timing test suite to use the new ztest API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-12 13:23:00 +02:00
Henrik Brix Andersen
d6c211ef79 tests: drivers: can: canfd: convert to new ztest API
Convert the CAN-FD controller driver API test suite to use the new ztest
API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-12 13:23:00 +02:00
Henrik Brix Andersen
d9a1aab22a tests: drivers: can: api: convert to new ztest API
Convert the CAN controller driver API test suite to use the new ztest API.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-12 13:23:00 +02:00