Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: can: add support for minimum supported bitrates #69533

Merged

Conversation

henrikbrixandersen
Copy link
Member

Some CAN controllers and CAN transceivers have a lower limit for which bitrates they support.

In-tree examples:

  • The ESP32 TWAI CAN controller only supports bitrates from 25kbit/s to 1Mbit/s.
  • The NXP TJA1050 CAN transceiver supports bitrates from 60kbit/s up to 1Mbit/s.

This patch series adds:

  • Optional CAN transceiver devicetree properties for specifying a minimum supported bitrate.
  • CAN transceiver devicetree API macros (+ tests) for getting the minimum supported CAN transceiver bitrate.
  • Support for specifying a minimum supported bitrate for a CAN controller driver.
  • A new can_get_min_bitrate() API function (+ tests) for getting the minimum supported bitrate for a given CAN controller/transceiver combo.
  • Changes to the CAN timing calculation to take the minimum supported bitrate into consideration.
  • Minor adjustment to the CAN timing test now the ESP32 TWAI no longer needs special-casing.

@henrikbrixandersen henrikbrixandersen added area: CAN Release Notes Required Release notes required for this change labels Feb 27, 2024
@henrikbrixandersen henrikbrixandersen self-assigned this Feb 27, 2024
@henrikbrixandersen henrikbrixandersen force-pushed the can_min_bitrate branch 3 times, most recently from e095e60 to 99aed69 Compare March 4, 2024 09:08
@henrikbrixandersen henrikbrixandersen removed the Release Notes Required Release notes required for this change label Mar 4, 2024
@henrikbrixandersen henrikbrixandersen marked this pull request as ready for review March 4, 2024 09:34
@henrikbrixandersen henrikbrixandersen added this to the v3.7.0 milestone Mar 4, 2024
boards/shields/mcp2515/dfrobot_can_bus_v2_0.overlay Outdated Show resolved Hide resolved
include/zephyr/drivers/can.h Show resolved Hide resolved
tests/drivers/can/timing/src/main.c Show resolved Hide resolved
doc/releases/release-notes-3.7.rst Outdated Show resolved Hide resolved
@henrikbrixandersen
Copy link
Member Author

Rebased to resolve merge conflict in doc/releases/release-notes-3.7.rst.

@henrikbrixandersen
Copy link
Member Author

@str4t0m PTAL

str4t0m
str4t0m previously approved these changes Mar 6, 2024
Some CAN transceivers have a lower limit on their supported bitrate. Add an
optional "min-bitrate" for specifying this limit via devicetree.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
The NXP TJA1050 supports bitrates from 60kbit/s up to 1Mbit/s.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add support for getting the minimum supported bitrate of a CAN transceiver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add tests for DT_CAN_TRANSCEIVER_MIN_BITRATE() and
DT_INST_CAN_TRANSCEIVER_MIN_BITRATE().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add support for specifying the minimum bitrate supported by a CAN
controller in CAN_DT_DRIVER_CONFIG_GET() and
CAN_DT_DRIVER_CONFIG_INST_GET().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Allow frontend drivers based on the SJA1000 backend to specify a minimum
supported bitrate.

The ESP32 TWAI supports bitrates from 25kbit/s to 1Mbit/s.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add a new CAN controller API function can_get_min_bitrate() for getting the
minimum supported bitrate of a CAN controller/transceiver combination.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add test for validating the CAN controller bitrate limits.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Take the minimum supported bitrate into consideration when validating the
bitrate.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Enable testing of all bitrates for all drivers and report which bitrates
are not supported by the CAN controller under test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add release notes related to the added support for minimum supported CAN
transceiver/controller bitrates.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
@henrikbrixandersen
Copy link
Member Author

Rebased to resolve merge conflict in doc/releases/release-notes-3.7.rst.

@@ -363,7 +366,7 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
return ret;
}

if ((max_bitrate > 0) && (bitrate > max_bitrate)) {
if ((bitrate < min_bitrate) || (((max_bitrate > 0) && (bitrate > max_bitrate)))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is the check for max_bitrate of zero needed here? It is marked as required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing! Currently, it is needed. It will go away in a future revision.

@henrikbrixandersen henrikbrixandersen merged commit 8dd03c6 into zephyrproject-rtos:main Mar 12, 2024
22 checks passed
@henrikbrixandersen henrikbrixandersen deleted the can_min_bitrate branch March 19, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants