Skip to content

Commit c1aae77

Browse files
Merge pull request #302 from kurt-vd/more-chips-bittiming
[v2] more chips bittiming
2 parents e9dd86f + 37f316e commit c1aae77

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

can-calc-bit-timing.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,57 @@ static void printf_btr_rcar_can(struct can_bittiming *bt, bool hdr)
273273
}
274274
}
275275

276+
static void printf_btr_bxcan(struct can_bittiming *bt, bool hdr)
277+
{
278+
if (hdr) {
279+
printf("%10s", "CAN_BTR");
280+
} else {
281+
uint32_t btr;
282+
283+
btr = (((bt->brp -1) & 0x3ff) << 0) |
284+
(((bt->prop_seg + bt->phase_seg1 -1) & 0xf) << 16) |
285+
(((bt->phase_seg2 -1) & 0x7) << 20) |
286+
(((bt->sjw -1) & 0x3) << 24);
287+
288+
printf("0x%08x", btr);
289+
}
290+
}
291+
292+
static void printf_btr_c_can(struct can_bittiming *bt, bool hdr)
293+
{
294+
if (hdr) {
295+
printf("%s", " BTR BRPEXT");
296+
} else {
297+
uint32_t btr;
298+
uint32_t brpext;
299+
300+
btr = (((bt->brp -1) & 0x3f) << 0) |
301+
(((bt->sjw -1) & 0x3) << 6) |
302+
(((bt->prop_seg + bt->phase_seg1 -1) & 0xf) << 8) |
303+
(((bt->phase_seg2 -1) & 0x7) << 12);
304+
brpext = ((bt->brp -1) >> 6) & 0xf;
305+
306+
printf("0x%04x 0x%04x", btr, brpext);
307+
}
308+
}
309+
310+
static void printf_btr_mcan(struct can_bittiming *bt, bool hdr)
311+
{
312+
if (hdr) {
313+
printf("%10s", "NBTP");
314+
} else {
315+
uint32_t nbtp;
316+
317+
318+
nbtp = (((bt->brp -1) & 0x1ff) << 16) |
319+
(((bt->sjw -1) & 0x7f) << 25) |
320+
(((bt->prop_seg + bt->phase_seg1 -1) & 0xff) << 8) |
321+
(((bt->phase_seg2 -1) & 0x7f) << 0);
322+
323+
printf("0x%08x", nbtp);
324+
}
325+
}
326+
276327
static struct calc_bittiming_const can_calc_consts[] = {
277328
{
278329
.bittiming_const = {
@@ -417,6 +468,54 @@ static struct calc_bittiming_const can_calc_consts[] = {
417468
{ .clk = 65000000, },
418469
},
419470
.printf_btr = printf_btr_rcar_can,
471+
}, {
472+
.bittiming_const = {
473+
.name = "bxcan",
474+
.tseg1_min = 1,
475+
.tseg1_max = 16,
476+
.tseg2_min = 1,
477+
.tseg2_max = 8,
478+
.sjw_max = 4,
479+
.brp_min = 1,
480+
.brp_max = 1024,
481+
.brp_inc = 1,
482+
},
483+
.ref_clk = {
484+
{ .clk = 48000000, },
485+
},
486+
.printf_btr = printf_btr_bxcan,
487+
}, {
488+
.bittiming_const = {
489+
.name = "c_can",
490+
.tseg1_min = 2,
491+
.tseg1_max = 16,
492+
.tseg2_min = 1,
493+
.tseg2_max = 8,
494+
.sjw_max = 4,
495+
.brp_min = 1,
496+
.brp_max = 1024,
497+
.brp_inc = 1,
498+
},
499+
.ref_clk = {
500+
{ .clk = 24000000, },
501+
},
502+
.printf_btr = printf_btr_c_can,
503+
}, {
504+
.bittiming_const = {
505+
.name = "mcan-v3.1+",
506+
.tseg1_min = 2,
507+
.tseg1_max = 256,
508+
.tseg2_min = 2,
509+
.tseg2_max = 128,
510+
.sjw_max = 128,
511+
.brp_min = 1,
512+
.brp_max = 512,
513+
.brp_inc = 1,
514+
},
515+
.ref_clk = {
516+
{ .clk = 40000000, },
517+
},
518+
.printf_btr = printf_btr_mcan,
420519
},
421520
};
422521

0 commit comments

Comments
 (0)