尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
在项目文件夹中运行 /nomorevibe verify,即可验证所有权并自行管理介绍。
一分钟完成验证C99 CAN FD bit-timing library for Bosch M_CAN: finds exact settings, encodes NBTP/DBTP/TDCR with transmitter delay compensation. No heap, tested against the web calculator, CI with sanitizers.
翻译准备中
取自仓库 README
正在加载完整 README。
查看完整 README ↗A small C99 library that finds CAN FD bit timings for Bosch M_CAN-style controllers, and encodes them into
the NBTP, DBTP and TDCR registers, including transmitter delay compensation. No dependencies, no heap,
one header. It is the C version of the calculator on
moutazm.com/projects/can-tools, and the tests check that both agree.
$ ./canfd-bt 40 500 80 2000 75
4 valid settings, best:
nominal brp 1 tq 80 = 1 + 63 + 16 sjw 16 sample point 80.00 %
data brp 1 tq 20 = 1 + 14 + 5 sjw 5 sample point 75.00 %
TDC on, TDCO = 15 clock cycles
M_CAN NBTP 0x1E003E0F DBTP 0x00800D44 TDCR 0x00000F00
Linux ip link set can0 up type can bitrate 500000 sample-point 0.800 dbitrate 2000000 dsample-point 0.750 fd on
For a CAN clock, a nominal and a data bit rate and two target sample points it:
m_can driver uses):
nominal prescaler 1–512, TSEG1 2–256, TSEG2 2–128; data prescaler 1–32, TSEG1 1–32, TSEG2 1–16;TDCO = data BRP × (1 + TSEG1) and says whether TDC is
allowed (ISO 11898-1: data prescaler 1 or 2 only);#include "canfd_bittiming.h"
cfd_setting best[3];
size_t n = cfd_solve(40000000u, 500000u, 0.80, 2000000u, 0.75, true, best, 3);
if (n) {
bool tdc = cfd_tdc_possible(&best[0].data);
uint32_t nbtp = cfd_mcan_nbtp(&best[0].nominal);
uint32_t dbtp = cfd_mcan_dbtp(&best[0].data, tdc);
uint32_t tdcr = cfd_mcan_tdcr(&best[0].data);
}
cfd_solve returns how many valid settings exist and writes the best max (up to 64) into your buffer, best
first. Pass NULL, 0 to only count.
make # libcanfd_bittiming.a + the canfd-bt command-line tool
make test # unit tests
CI builds with gcc and clang, -std=c99 -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror, and runs the
tests again under AddressSanitizer and UndefinedBehaviorSanitizer. The reference cases in
tests/test_bittiming.c (prescalers, time quanta, segments, SJW, register values, TDCO, number of solutions) were
generated by the website's JavaScript, so a change in either one shows up as a failing test.
MIT