tests: drivers: can: timing: add tests for all CiA recommended bitrates
Add tests for all CAN bitrates recommended by CAN in Automation (CiA). The newly added bitrate tests are guarded by new, local Kconfig option (CONFIG_TEST_ALL_BITRATES) to avoid breaking existing board tests. Some boards may need adjustments to their CAN core clock in order to pass the newly added tests. Once a board is confirmed to meet these additional checks, this Kconfig can be enabled for that board to avoid future regressions. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
f9dc6f7d13
commit
9f174ec452
2 changed files with 78 additions and 4 deletions
40
tests/drivers/can/timing/Kconfig
Normal file
40
tests/drivers/can/timing/Kconfig
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright (c) 2024 Vestas Wind Systems A/S
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mainmenu "CAN timing test"
|
||||
|
||||
config TEST_ALL_BITRATES
|
||||
bool "Test all CAN in Automation (CiA) recommended bitrates"
|
||||
help
|
||||
Enable test of all bitrates recommended by CAN in Automation (CiA). Not all CAN
|
||||
controllers can meet all of the bitrates listed below, and some board configurations may
|
||||
impose limits on which bitrates can be met due to limitations in the CAN core clock
|
||||
frequency selection.
|
||||
|
||||
CiA 301 lists the following nominal bitrates as recommended:
|
||||
- 10 kbit/s
|
||||
- 20 kbit/s
|
||||
- 50 kbit/s
|
||||
- 125 kbit/s
|
||||
- 250 kbit/s
|
||||
- 500 kbit/s
|
||||
- 800 kbit/s
|
||||
- 1 Mbit/s
|
||||
|
||||
CiA 601-2 lists the following exemplary CAN FD data phase bitrates:
|
||||
- 1.0 Mbit/s
|
||||
- 2.0 Mbit/s
|
||||
- 4.0 Mbit/s
|
||||
- 5.0 Mbit/s
|
||||
- 8.0 Mbit/s
|
||||
|
||||
CiA 601-3 recommends the following CAN FD core clock frequencies for good node
|
||||
interoperability. The higher the frequency, the better:
|
||||
- 20 MHz
|
||||
- 40 MHz
|
||||
- 80 MHz
|
||||
|
||||
If this option is not enabled, the tests will be limited to a historical, safe set of CAN
|
||||
bitrates.
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
|
|
@ -35,7 +35,10 @@ struct can_timing_test {
|
|||
* @brief List of CAN timing values to test.
|
||||
*/
|
||||
static const struct can_timing_test can_timing_tests[] = {
|
||||
/** Standard bitrates. */
|
||||
/* CiA 301 recommended bitrates */
|
||||
#ifdef CONFIG_TEST_ALL_BITRATES
|
||||
{ 10000, 875 },
|
||||
#endif /* CONFIG_TEST_ALL_BITRATES */
|
||||
{ 20000, 875 },
|
||||
{ 50000, 875 },
|
||||
{ 125000, 875 },
|
||||
|
|
@ -49,9 +52,14 @@ static const struct can_timing_test can_timing_tests[] = {
|
|||
* @brief List of CAN FD data phase timing values to test.
|
||||
*/
|
||||
static const struct can_timing_test can_timing_data_tests[] = {
|
||||
/** Standard bitrates. */
|
||||
{ 500000, 875 },
|
||||
/* CiA 601-2 recommended data phase bitrates */
|
||||
{ 1000000, 750 },
|
||||
#ifdef CONFIG_TEST_ALL_BITRATES
|
||||
{ 2000000, 750 },
|
||||
{ 4000000, 750 },
|
||||
{ 5000000, 750 },
|
||||
{ 8000000, 750 },
|
||||
#endif /* CONFIG_TEST_ALL_BITRATES */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -230,13 +238,39 @@ void *can_timing_setup(void)
|
|||
int err;
|
||||
|
||||
zassert_true(device_is_ready(dev), "CAN device not ready");
|
||||
k_object_access_grant(dev, k_current_get());
|
||||
|
||||
err = can_get_core_clock(dev, &core_clock);
|
||||
zassert_equal(err, 0, "failed to get core CAN clock");
|
||||
|
||||
printk("testing on device %s @ %u Hz\n", dev->name, core_clock);
|
||||
|
||||
k_object_access_grant(dev, k_current_get());
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
can_mode_t cap;
|
||||
|
||||
err = can_get_capabilities(dev, &cap);
|
||||
zassert_equal(err, 0, "failed to get CAN controller capabilities (err %d)", err);
|
||||
|
||||
if ((cap & CAN_MODE_FD) != 0) {
|
||||
switch (core_clock) {
|
||||
case MHZ(20):
|
||||
break;
|
||||
case MHZ(40):
|
||||
break;
|
||||
case MHZ(80):
|
||||
break;
|
||||
default:
|
||||
TC_PRINT("Warning: CiA 601-3 recommends a CAN FD core clock of "
|
||||
"20, 40, or 80 MHz for good node interoperability\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_TEST_ALL_BITRATES)) {
|
||||
TC_PRINT("Warning: Testing limited selection of bitrates "
|
||||
"(CONFIG_TEST_ALL_BITRATES=n)\n");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue