Commit graph

26 commits

Author SHA1 Message Date
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Carles Cufi 8e4d499fa0 treewide: Use CONFIG_*_ENDIAN instead of __BYTE_ORDER__
In order to avoid using multiple sources of truth for the platfom's
endianness, convert the in-tree code to use the (BIG|LITTLE)_ENDIAN
Kconfig variables exclusively, instead of the compiler's
__BYTE_ORDER__.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-10-28 19:23:46 +09: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 05455c3d23 modules: canopennode: storage: fix size_t format specifier
Fix the format specifier for logging size_t values.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2022-10-22 14:36:11 +09: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
Dominik Ermel f4398e1ad6 modules: canopennode: Switch to FIXED_PARTITION_ macros
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Henrik Brix Andersen 590cd5cb72 drivers: can: rename can_state enumerations
Rename the can_state enumerations to contain the word STATE to make their
meaning more clear:
- CAN_ERROR_ACTIVE  => CAN_STATE_ERROR_ACTIVE
- CAN_ERROR_WARNING => CAN_STATE_ERROR_WARNING
- CAN_ERROR_PASSIVE => CAN_STATE_ERROR_PASSIVE
- CAN_BUS_OFF       => CAN_STATE_BUS_OFF

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-18 21:41:11 +00: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 3f97d11afd drivers: can: convert enum can_mode to a bit field
Convert the can_mode enum to a bit field to prepare for future extensions
(CAN-FD mode, transmitter delay compensation, one-shot mode, 3-samples
mode, ...).

Rename the existing modes:
- CAN_NORMAL_MODE   -> CAN_MODE_NORMAL
- CAN_SILENT_MODE   -> CAN_MODE_LISTENONLY
- CAN_LOOPBACK_MODE -> CAN_MODE_LOOPBACK

These mode names align with the Linux naming for CAN control modes.

The old CAN_SILENT_LOOPBACK_MODE can be set with the bitmask
(CAN_MODE_LISTENONLY | CAN_MODE_LOOPBACK).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-05-11 10:47:54 +02:00
Henrik Brix Andersen 18890828b8 drivers: can: split CAN classic and CAN-FD syscalls
Split CAN classic and CAN-FD syscalls into two:
- can_set_timing() -> can_set_timing() + can_set_timing_data()
- can_set_bitrate() -> can_set_bitrate() + can_set_bitrate_data()

Fixes: #45303

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-05-11 10:47:54 +02:00
Gerard Marull-Paretas 5f5a905784 modules: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all modules code to the
new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:57:47 +02:00
Henrik Brix Andersen 38ee953547 modules: canopennode: can_get_max_filters() is optional
Support for the can_get_max_filters() API function is optional and may
not be supported by all drivers.

The check for an adequate amount of filters is just there in order to
fail early. If the driver does not support can_get_max_filters(),
reporting of a failure will be delayed until a filter addition fails.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-04-19 11:47:40 +02:00
Henrik Brix Andersen 2f43226b3d modules: canopennode: CANopenNode does not support CAN-FD
The CANopenNode stack does not support CAN-FD. Depend on it being
disabled and explicitly disable it in the CANopenNode sample.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-03-25 15:35:10 -07:00
Henrik Brix Andersen 67ba9900f0 drivers: can: add struct device argument to callback functions
Include a pointer to the CAN controller device for the CAN
transmit, receive, and state change callback functions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-03-19 14:31:22 -04:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Henrik Brix Andersen 2aed5a1237 drivers: can: remove CAN_BUS_UNKNOWN CAN controller state
The CAN_BUS_UNKNOWN CAN controller state is only used to indicate that
the current CAN controller state could not be read.

Remove it and change the signature of the can_get_state() API function
to return an integer indicating success or failure.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-28 10:05:29 +01:00
Henrik Brix Andersen d727547f79 modules: canopennode: increase stack sizes
Increase the default CANopenNode stack sizes a bit. The current stack
sizes are too small for e.g. ST STM32F3, likely other platforms as well.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-11 14:40:49 -06:00
Henrik Brix Andersen 8af4bb722d drivers: can: rename API functions for better consistency
Rename a few CAN API functions for clarity and consistency with other
Zephyr RTOS APIs.

CAN_DEFINE_MSGQ() becomes CAN_MSGQ_DEFINE() to match K_MSGQ_DEFINE().

can_attach_isr() becomes can_add_rx_filter() since a filter callback
function is not an interrupt service routine (although it is called in
isr context). The word "attach" is replaced with "add" since filters are
added, not attached. This matches the terminology used is other Zephyr
APIs better.

can_detach() becomes can_remove_rx_filter() to pair with
can_add_rx_filter().

can_attach_msgq() becomes can_add_rx_filter_msgq() and documentation is
updated to mention its relationship with can_add_rx_filter().

can_register_state_change_isr() becomes can_set_state_change_callback()
since a state change callback function is not an interrupt service
routine (although it is called in isr context). The word "register" is
replaced with "set" since only one state change callback can be in
place.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-10 10:44:37 +01:00
Henrik Brix Andersen b1b77c1774 drivers: can: change can_tx_callback_t function signature
Change the can_tx_callback_t function signature to use an "int" (not an
uint32_t) for representing transmission errors.

The "error" callback function parameter is functionally equivalent to
the return value from can_send() and thus needs to use the same data
type and needs to be able to hold negative errno values.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-01-01 07:40:29 -05:00
Henrik Brix Andersen f499559434 drivers: can: deprecate the use of CAN-specific error return values
Deprecate the use of CAN-specific error return values and replace them
with standard errno values.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-12-09 12:37:40 -05:00
Henrik Brix Andersen 53f85df551 modules: canopennode: switch to using can_set_mode()
Switch from using can_configure() to using can_set_mode() for disabling
CAN controller transmissions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-12-02 10:54:44 +01:00
Fabio Baltieri b5f9f34fb5 modules: canopennode: set tx_workq thread name
Set a thread name for the tx_workq thread, so that it shows up in
"kernel stacks" when the shell or thread debugging are enabled.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-11-12 14:51:16 +01:00
Martin Jäger ec576a59d3 canbus: canopen: Use new API to check number of filters
The previous CONFIG_CAN_MAX_FILTER is specific to certain drivers.

Using the new API makes the CAN open driver independent of the used
CAN hardware / driver.

Signed-off-by: Martin Jäger <martin@libre.solar>
2021-10-28 13:56:58 -04:00
Henrik Brix Andersen 4216b9f622 modules: canopennode: rename header and Kconfig options
Rename the top-level header file from <canbus/canopen.h> to
<canopennode.h>.

Rename CANopenNode related Kconfig options from CONFIG_CANOPEN* to
CONFIG_CANOPENNODE*.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-07-01 13:32:18 -04:00
Henrik Brix Andersen d679037643 modules: canopennode: move glue code to modules directory
Move the Zephyr-specific interface and support code for CANopenNode into
the modules directory. Consolidate the CMakeLists.txt files into one.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-07-01 13:32:18 -04:00