Commit graph

501 commits

Author SHA1 Message Date
Henrik Brix Andersen
f1a7ec96db drivers: can: remove CAN_HAS_RX_TIMESTAMP Kconfig helper
Remove the CAN_HAS_RX_TIMESTAMP Kconfig helper symbol in order to allow
enabling CAN RX timestamps in the API regardless of driver support.

This simplifies application prj.conf settings across board supporting/not
supporting RX timestamps considerably.

CAN drivers not supporting RX timestamps already initialize the timestamp
to 0 for received frames.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-25 15:00:39 +00:00
Henrik Brix Andersen
51cac9e04f drivers: can: rcar: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the Renesas R-Car
CAN driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen
8b896fdf01 drivers: can: stm32: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the ST STM32 bxCAN
driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen
5517a935d0 drivers: can: mcux: flexcan: add RX overrun counter statistic support
Add support for the RX overrun statistics counter to the NXP FlexCAN
driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Henrik Brix Andersen
46136b3c12 drivers: can: mcux: flexcan: fix handling of failed RX MB reads
Fix handling of failed NXP FlexCAN RX mailbox reads. Instead of re-enabling
the RX MB in the ISR, we need to handle a failed RX MB read (e.g. due to a
busy MB bit).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-19 16:51:22 -08:00
Cong Nguyen Huu
d167d3a29a driver: can: add new filter to match CAN-FD frames
Add support FD frame filter to configure type frame for
each Rx msg to receive corresponding frames (classic, FD frames).

The Bosch M_CAN driver does not support FD frame filter,
so inmplement driver to handle it in software.

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
2023-01-04 08:18:13 -06:00
Martin Jäger
c8c0879963 drivers: can: mcan: Fix flag overflow for some MCUs
The number of extended filters can be up to 15 for MCUs like the NXP
LPC55Sxx series, so the flags don't fit into uint8_t.

Fixes #53417

Signed-off-by: Martin Jäger <martin@libre.solar>
2023-01-04 14:24:35 +01:00
Mikhail Siomin
d4f65e4031 mcux: flexcan: fixes the race condition
Since the FLEXCAN_TransferSendNonBlocking() function has
read-modify-write operations on global resources, then
if interrupts are enabled and/or if there is more than
one thread with a different priority, threads with
a lower priority can overwrite global resource changes
made by higher priority threads.
Fixes #52673.

Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
2023-01-03 11:01:31 +01:00
Bartosz Bilas
e077fb73ec drivers: tests: replace usage of spi_is_ready with spi_is_ready_dt
`spi_is_ready` function is being deprecated in favor of
`spi_is_ready_dt` so let's replace the old usage in the tree.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-12-07 09:40:23 -06:00
Carlo Caione
cc427b4bb0 cache: Fix libraries and drivers
Fix the usage to be compliant to the new cache API.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-01 13:40:56 -05:00
Johan Hedberg
e9b39efe9e drivers: can: kvaser_pci: Convert to use dynamic BDF lookup
Use the new PCIe core infrastructure for looking up the BDF at runtime
based on the VID/DID values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-16 11:18:43 +01:00
Johan Hedberg
54513c70d1 drivers: can: kvaser_pci: Fix incorrect RAM context struct type
The can_kvaser_pci_data_##inst type was supposed to be
can_kvaser_pci_data and not can_kvaser_pci_config. This got unnoticed
because there were no struct members to pre-initialize, and a reference
to the struct was stored using a void pointer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-11-11 12:10:09 +01:00
Perry Hung
9b5bc03f86 drivers: can: sam: select CACHE_MANAGEMENT for SAM M_CAN
A regression was introduced in ef804d8408
when the M_CAN driver was swapped to use the generic dcache API, but
cache management was not enabled on SAM devices.

Enable cache management on SAM devices when CAN_SAM is selected.

Signed-off-by: Perry Hung <perry@genrad.com>
2022-11-08 15:41:10 -05: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
566c64f0c0 drivers: can: loopback: guard against out-of-bounds filter IDs
Guard against out-of-bounds filter IDs when removing RX filters.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen
efd0d3ba96 drivers: can: loopback: add log message for full TX msgq
Emit a debug log message if the TX message queue is full.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen
728138023b drivers: can: loopback: rename receive function
Rename the CAN loopback driver receive function to make the code easier to
understand. Add proper check against NULL for RX callback function
pointers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen
a5e534a283 drivers: can: loopback: process TX callbacks in non-loopback mode
The TX callbacks must be processed regardless of the device being in
loopback mode or not.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-11-02 10:31:48 +01:00
Henrik Brix Andersen
abf82013ac drivers: can: add support for configuring CAN emulation in QEMU
Add support for configuring CAN emulation support in QEMU. For now, the
only supported CAN controller is the single-channel Kvaser PCIcan PCI card.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Henrik Brix Andersen
58e12726bf drivers: can: add driver for the Kvaser PCIcan CAN controller PCI card
Add driver for the Kvaser PCIcan CAN controller PCI card for use with QEMU.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-11-01 15:22:31 -04:00
Henrik Brix Andersen
58afbc8f26 drivers: can: mcp2515: add support for multiple device instances
Add support for multiple MCP2515 CAN controller device instances.

Fixes: #51458

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-10-27 11:03:05 +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
Henrik Brix Andersen
fa54e3aa1d drivers: can: sja1000: remove unused variables
Remove unused variables from the CAN SJA1000 driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-22 14:37:18 +09:00
Henrik Brix Andersen
5f8983f2ec drivers: can: npl: ensure CANFD_FDF flag is defined
Linux kernels before v5.14 do not define the CANFD_FDF flag. The flag is
disregarded within the Linux kernel. It is just there for being able to
reuse the canfd_frame struct for classic CAN frames in Linux user-space
applications.

Define the CANFD_FDF flag locally if not already defined to allow compiling
against older Linux kernel headers.

See the following Linux kernel commit for further details:
02546884221279da2725e87e35348290470363d7

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-10-17 17:04:16 +02:00
Gerard Marull-Paretas
178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Martin Jäger
93681feaba drivers: can: sja1000: configure PHY from devicetree
The phys property was not considered during initialization of the
driver config, so that the transceiver was not enabled properly
in case it has an enable/standby pin.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 14:24:00 +02:00
Martin Jäger
2a035f775b drivers: can: esp32_twai: add support for newer MCUs
Newer ESP32 series MCUs like the ESP32-C3 contain some register changes
incompatible to the original ESP32 and the SJA1000.

The additions in this commit consider these changes and fix the
incompatibilities in the TWAI front-end for the SJA1000 driver.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 09:55:09 +02:00
Martin Jäger
f936d68916 drivers: can: sja1000: use generic can_set_timing API
This is a preparation to use the custom implementation in ESP32 TWAI
frontend for newer ESP32 series chips like the ESP32-C3, which have
timing registers incompatible with the SJA1000.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-10-14 09:55:09 +02:00
Thad House
f37db90541 drivers: Correct tx and rx error counts in mcan
TX and RX error counts are swapped in the mcan driver.

Signed-off-by: Thad House <thadhouse@fb.com>
2022-09-28 20:34:36 +00:00
Henrik Brix Andersen
6d08944ac1 drivers: can: mcp2515: abort transfers before entering configuration mode
Abort any pending transmissions before entering configuration mode and
notify the senders.

Poll for mode change completion instead of assuming mode changes take
immediate effect. This is needed for successfully entering configuration
mode with recently aborted transmissions.

Fixes: #50545

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
f239c3d0e9 drivers: can: stm32: abort transfers after entering init mode
Abort any pending transmissions after entering init mode and notify the
senders.

Fixes: #50545

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
6cf34d0d33 drivers: can: mcan: notify of aborted transmission on can_stop()
Notify of any aborted transmission when entering init mode via can_stop().

Fixes: #50545

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
b8eb11de3b drivers: can: mcux: flexcan: abort transfers before entering freeze mode
Abort any pending transmissions before entering freeze mode and notify the
senders.

Fixes: #50545

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
94d4638ccc drivers: can: sja1000: notify of aborted transmission on can_stop()
Notify of any aborted transmission when entering reset mode via can_stop().

Fixes: #50545

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
a99a55eefb drivers: can: npl: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
50d77ab854 drivers: can: mcan: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

This saves approximately 500 bytes of SRAM on the lpcxpressso55s16 board
when running in default configuration.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
d3427d991a drivers: can: rcar: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
10cd28a61a drivers: can: loopback: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
4165186d13 drivers: can: stm32: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
78d6ba5ce3 drivers: can: mcp2515: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
eb06e6aed0 drivers: can: sja1000: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
fcf7c6e6d1 drivers: can: mcux: flexcan: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper,
assume that a callback is always provided at the driver level.

This saves approximately 500 bytes of SRAM on the frdm_k64f board, while on
the mimxrt1024_evk board the saving is approximately 2.5 kbytes of SRAM,
both when running in default configuration.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
d6fc3f6596 drivers: can: provide default callback to can_send() if NULL
Provide a default, internal callback to CAN controller drivers
implementation of can_send() if no callback was provided by the caller.

This allows for simplifying the CAN driver implementations of can_send() as
these no longer need special handling for callback/no callback operation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-23 17:25:01 +00:00
Henrik Brix Andersen
5ec7acca86 drivers: can: rcar: remote transmission request filters are not supported
The receive path for the Renesas R-Car CAN controller supports two RX
FIFOs, which are currently configured for standard 11-bit CAN ID data
frames in FIFO0, and extended 29-bit CAN ID data frames in FIFO1.

As this leaves no room for matching remote transmission request (RTR)
frames, have the driver return -ENOTSUP instead of silently accepting RTR
filters.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-21 08:50:47 +00:00
Thomas Stranger
fc33325fc7 drivers: can: native_posix_linux: drop rx frames while stopped
The driver should drop rx frames while in stopped state.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-09-15 16:20:04 +00:00
Thomas Stranger
0c365ac0ea drivers: can: mcan: don't enabled trasceiver in init
With the move to start/stop functions the transceiver is not expected
to be enabled after driver initialization.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-09-15 16:19:32 +00:00
Henrik Brix Andersen
6f1ff5ea83 drivers: can: shell: add CAN start/stop shell commands
Add shell commands for starting/stopping a CAN controller.

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
Martin Jäger
77e4c6515a drivers: can: native_posix_linux: initial implementation
This driver provides an interface to SocketCAN interfaces of the Linux
system running a Zephyr application with the native_posix board. These
interfaces may be virtual or actual CAN buses.

Signed-off-by: Martin Jäger <martin@libre.solar>
2022-09-09 10:08:59 +02:00
Henrik Brix Andersen
b01ea7c0c9 drivers: can: transceiver: Update drivers to use dts Kconfig symbol
Update the GPIO-controlled CAN transceiver driver to use the
DT_HAS_CAN_TRANSCEIVER_GPIO_ENABLED Kconfig symbol to expose the driver and
enable it by default based on devicetree.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-09-08 15:30:23 +00:00