Commit graph

127 commits

Author SHA1 Message Date
Jordan Yates 750ccd39dc can: mcp2515: Add chip select flags
Adds the chip select devicetree flags to the spi_cs_control instance.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-07-01 16:40:03 -05:00
Anas Nashif ee985d81aa shell: enable modules by default if shell is enabled
If shell is enabled then enable all sub-shells if their dependencies are
satisfied. This was done for some modules and subsystems but was not
consistent.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-24 21:37:12 -04:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Henrik Brix Andersen 974e05a9d8 drivers: can: flexcan: handle rx overflow and undhandled irqs
Add handling of RX overflows and IRQs reported as undhandled by the
NXP MCUX HAL.

Fixes: #22625

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-06-02 21:49:53 +02:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Kumar Gala c2135f8721 devicetree: DT_NODE_HAS_COMPAT_STATUS_OKAY -> DT_NODE_HAS_COMPAT_STATUS
Swap this out and make the status a parameter.
Leave a couple of cases of DT_NODE_HAS_COMPAT().

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00
Martí Bolívar 17b8667197 dts: clean up some redundant DT checks
These are redundantly checking a node's status twice.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-08 19:37:18 -05:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.

Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.

To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:

- emit macros for all existing nodes in gen_defines.py, regardless
  of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -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
Joakim Andersson 293cd5664d drivers: can: Fix use of DT_HAS_DRV_INST which does not exist
Fix use of DT_HAS_DRV_INST which does not exist.
Use DT_HAS_NODE_STATUS_OKAY(DT_DRV_INST(n)) instead.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 07:49:16 -05:00
Kumar Gala fbb1de6aac drivers: can: Remove per instance Kconfig symbols
All users of per instance CAN symbols are removed so we can remove them.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 10:08:31 +02:00
Kumar Gala aec38f3fda drivers: can: mcp2515: Convert from Kconfig to DT_NODELABEL
As we phase out per instance Kconfig symbols convert to utilize
DT_DRV_INST to initialize CAN instances.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 10:08:31 +02:00
Kumar Gala 9d4cdd732e drivers: can: mcux_flexcan: Convert from Kconfig to DT_NODELABEL
As we phase out per instance Kconfig symbols convert to utilize
DT_DRV_INST to initialize CAN instances.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 10:08:31 +02:00
Kumar Gala fdd85d5ad7 dts: Rename DT_HAS_NODE macro to DT_HAS_NODE_STATUS_OKAY
Rename DT_HAS_NODE to DT_HAS_NODE_STATUS_OKAY so the semantics are
clear.  As going forward DT_HAS_NODE will report if a NODE exists
regardless of its status.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-06 05:25:41 -05:00
Alexander Wachter 464f135ce6 canbus: Convert canbus driver and subsys to new timeout API
Convert all canbus related API/samples/tests/subsys
to the new timeout API with k_timeout_t.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-05-06 10:19:13 +02:00
Peter Bigot 52885d0576 coccinelle: run ms_timeout conversion semantic patch
Substitute integral constants where call sites passed named constants
that have timeout values as arguments to parameters that expect
millisecond durations.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-30 18:26:26 +02:00
Kumar Gala 3f236f2183 can: dts: Convert can-primary alias to zephyr,can-primary chosen prop
Convert CAN to use a chosen node property that is similar to how we
handle zephyr,entroy or zephyr,flash-controller as the means to select a
specific peripheral instance utilized by a subsystem.

Replace references of the form:

alias {
	can-primary = &can1;
};

with:

chosen {
	zephyr,can-primary = &can1;
};

Replace various macro/define references with either
DT_CHOSEN(zephyr_can_primary) or replace DT_ALIAS_CAN_PRIMARY_LABEL
with DT_CHOSEN_ZEPHYR_CAN_PRIMARY_LABEL.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-29 14:27:31 -05:00
Erwan Gouriou c9135686b2 drivers/can: stm32: Convert to DT macros
Use DT macros to configure stm32 can device instances.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-28 14:49:55 -05:00
Erwan Gouriou 826e24ca58 drivers/can: stm32: configure driver thanks to compatible
Remove need to configure from soc/

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-28 14:49:55 -05:00
Henrik Brix Andersen 42af963db2 drivers: can: shell: add command for configuring a CAN controller
Add shell command for configuring the mode and bitrate of a CAN
controller.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-04-21 18:26:16 +02:00
Andy Ross 7832738ae9 kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument.  Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created.  This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.

The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.

The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.

Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.

For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided.  When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.

Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions.  These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig.  These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.

k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.

Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate.  Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure.  But k_poll() does not fail
spuriously, so the loop was removed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Tomasz Bursztyka 4ae72db135 net: Enable PM settings on network devices
By changing the various *NET_DEVICE* macros. It is up to the device
drivers to either set a proper PM function or, if not supported or PM
disabled, to use device_pm_control_nop relevantly.

All existing macro calls are updated. Since no PM support was added so
far, device_pm_control_nop is used as the default everywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Kumar Gala 1c3ed6dab6 devicetree: Rename spi cs gpio macros
Rename the DT_*_CS_* macro's to DT_*_CS_GPIOS_* to be more clear.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:24:23 -05:00
Kumar Gala 4b9fe8a24e drivers: mcux: Convert MCUX drivers to new DT_INST macros
Convert older DT_INST_ macro use in MCUX drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 03:40:09 -05:00
Kumar Gala 0bf9e0da94 drivers: can: can_mcp2515: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 03:34:37 -05:00
Alexander Wachter 79ed6a7e53 drivers: can: loopback: Use thread to send frames.
The loopback driver is a simple driver that can be used to
test CAN subsystems. The actual implementation sends frames
in the same thread that calls the send function.
Some libraries have problems with that behavior.
This PR implements a dedicated thread that calls the callback
for the receiving functions and a msgq in between the sender
and the TX thread.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-03-12 16:10:09 +02:00
Karsten Koenig 4897c95462 drivers: can: mcp2515: Switch to new GPIO API
Mark the INT signal to be active low and use the new functions to get
gpio state and configure the gpio interrupt flanks.

Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
2020-02-05 12:00:36 +01:00
Ivo Clarysse fe9025aafb drivers: can: stm32: Support CAN_2 interface
Add support for the CAN_2 interface.

Simultaneous use of CAN_1 and CAN_2 is not supported yet.

Signed-off-by: Ivo Clarysse <ivo@bcdevices.com>
2020-01-30 14:27:28 -05:00
Peter van der Perk 11ef49b65c drivers: can: Add SocketCAN support to mcux flexcan driver
Used the SocketCAN initalization code from the can_stm32.c driver which
successfully initializes SocketCAN for the Flexcan driver

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
2020-01-30 16:03:34 +02:00
Ivo Clarysse a290d30c9a drivers: can: stm32: Fix bit timing conversion
Fix CAN TS1, TS2 and SJW bit timing conversion to properly
handle upper limits.

Signed-off-by: Ivo Clarysse <ivo@bcdevices.com>
2020-01-27 15:07:32 -06:00
Alexander Wachter 2f44990e9b can: Introduce can-primary alias
This commit introduces the can-primary alias to identify
the primary CAN interface.
This alias is used for all samples and tests, so they don't
need to probe the right interface.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-01-27 10:25:00 -06:00
Peter Bigot 0b0d2e640b treewide: use full path to clock_control/stm32_clock_control.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
Henrik Brix Andersen 66e109cab7 drivers: can: flexcan: use initialization from MCUX v2.7.0
Update the NXP Kinetis FlexCAN driver to use the initialization
parameters for disabling self-reception and enabling listen-only mode
added in MCUXpresso v2.7.0.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-01-20 09:25:02 -06:00
Kumar Gala 24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Nick Ward ee99749ee5 drivers: CAN: MCP2515: Optimise TX SPI data length
When loading the TX buffer via SPI only transfer the data bytes of
the CAN message that will be used as defined by the DLC.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2019-11-06 21:45:08 +01:00
Alexander Wachter d558fd055a drivers: CAN: Limit the DLC to 8
This commit limits the data length code to eight.
DLC > 8 returns a newly introduced CAN_TX_EINVAL error code.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-11-06 21:00:45 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Nick Ward 0c5ef3e156 drivers: CAN: MCP2515: Add and use Read RX Buffer instruction
Reduces SPI RX buffer read overhead by a byte and further reduces the
SPI use by automatically clearing the associated receive flag RXxIF.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2019-10-25 15:20:32 +03:00
Nick Ward d5a5d960e6 drivers: CAN: MCP2515: Add and use RTS instruction
Reduces SPI data required for Request To Send from 4 bytes to 1

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2019-10-25 15:20:32 +03:00
Nick Ward 4816d06cfb drivers: CAN: MCP2515: Add and use Load TX Buffer instruction
Reduces SPI data for loading TX buffer by 1 byte

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2019-10-25 15:20:32 +03:00
Nick Ward a64f998645 drivers: CAN: MCP2515: Read INT GPIO pin to check interrupt status
Faster than the 3 byte SPI read operation when no interrupt flags are
expected to be set.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2019-10-25 15:20:32 +03:00
Alexander Wachter c0da8a7901 drivers: can: Extend CAN API for bus-state management.
This commit extends the CAN API with the following functions:
- can_get_state
- can_recover
- can_register_state_change_isr

This functions can be used to get the error-counters and the state
of the CAN controller. The recover function can be used to recover
from bus-off state when automatic recovery is disabled.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-10-24 12:28:01 +03:00
Ulf Magnusson c433a2ba33 can: loopback: kconfig: Remove unused CAN_LOOPBACK_FRAME_BUF_SIZE sym
Added in commit 0e807c3f54 ("drivers: can: Add loopback driver"), then
never used.

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-21 15:28:26 -05:00
Ulf Magnusson 894ec29606 can: loopback: kconfig: Remove unused CAN_RECEIVER_WORKQ_PRIO symbol
Added in commit 0e807c3f54 ("drivers: can: Add loopback driver"), then
never used.

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-21 15:28:26 -05:00
Alexander Wachter 8b214117ec drivers: CAN: MCP2515: Move OSC frequency definition to device-tree
Move the oscillator frequency definition from Kconfig to device-tree.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-10-09 06:27:53 -05:00
Henrik Brix Andersen 00f0fb73fd drivers: flexcan: fix loopback mode
Fix CAN loopback mode in the NXP MCUX FlexCAN driver by only disabling
self-reception when loopback mode was not requested.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2019-10-07 12:38:44 -05:00
Henrik Brix Andersen 8940c25145 drivers: can: flexcan: disable self-reception and support listen-only
Add work-around for the NXP MCUxpresso SDK not exposing APIs for
setting the listen-only (LOM) bit of the FlexCAN MCR register and the
self-reception disable (SRXDIS) bit of the CTRL1 register.

These bits can only be written when the FlexCAN module is in freeze
mode. Add a set of simplified functions (not supporting errata 9595) for
entering/exiting freeze mode.

This work-around can be removed again once the NXP MCUxpresso SDK
exposes the needed functionality.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2019-09-30 12:31:27 -05:00
Henrik Brix Andersen 5d4607554e drivers: can: flexcan: limit number of concurrent rx filters on k6x soc
Limit the number of concurrent FlexCAN RX filters in Kconfig on the
NXP Kinetis K6x SoC.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2019-09-16 15:36:37 -05:00
Alexander Wachter ec0e199206 drivers: can: mcux: Persuade the driver to send in chronological order
The mcux CAN controller uses frame ID and position to calculate the
priority, but the driver expects chronological ordering.
This PR mimics this behavior by only using the last free message box.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-09-13 09:58:11 -05:00