]> rtime.felk.cvut.cz Git - can-utils.git/commitdiff
canbusload: Fix worst-case frame length estimation
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 30 Jan 2014 13:38:59 +0000 (14:38 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 30 Jan 2014 15:23:32 +0000 (16:23 +0100)
The Tindell's method used previously is incorrect. It does not account for
the fact that the stuffed bits are themselves also subject to bit stuffing.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
canframelen.c
canframelen.h

index 46671a1d6863a6127823d6e820c32b2390387014..388295a81ae1482244e1287393eef15e225adc70 100644 (file)
@@ -246,7 +246,7 @@ unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu
        case CFL_NO_BITSTUFFING:
                return (eff ? 67 : 47) + frame->len * 8;
        case CFL_WORSTCASE:
-               return ((eff ? 389 : 269) + frame->len * 48) / 5;
+               return (eff ? 80 : 55) + frame->len * 10;
        case CFL_EXACT:
                return cfl_exact((struct can_frame*)frame);
        }
index 225bc09f756dbb744785fc57abcd26a4aabb2660..39b770648579ab00bccac7395fcad048b2dfcbe8 100644 (file)
@@ -6,20 +6,23 @@
 /**
  * Frame length calculation modes.
  *
- * CFL_WORSTCASE corresponds to Ken Tindells *worst* case calculation
- * for stuff-bits (see "Guaranteeing Message Latencies on Controller
- * Area Network" 1st ICC'94) the needed bits on the wire can be
- * calculated as:
+ * CFL_WORSTCASE corresponds to *worst* case calculation for
+ * stuff-bits - see (1)-(3) in [1]. The worst case number of bits on
+ * the wire can be calculated as:
  *
- * (34 + 8n)/5 + 47 + 8n for SFF frames (11 bit CAN-ID) => (269 + 48n)/5
- * (54 + 8n)/5 + 67 + 8n for EFF frames (29 bit CAN-ID) => (389 + 48n)/5
+ * (34 + 8n - 1)/4 + 34 + 8n + 13 for SFF frames (11 bit CAN-ID) => 55 + 10n
+ * (54 + 8n - 1)/4 + 54 + 8n + 13 for EFF frames (29 bit CAN-ID) => 80 + 10n
  *
  * while 'n' is the data length code (number of payload bytes)
  *
+ * [1] "Controller Area Network (CAN) schedulability analysis:
+ *     Refuted, revisited and revised", Real-Time Syst (2007)
+ *     35:239-272.
+ *
  */
 enum cfl_mode {
        CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */
-       CFL_WORSTCASE, /* with bitstuffing following Tindells estimation */
+       CFL_WORSTCASE, /* worst case estimation - see above */
        CFL_EXACT, /* exact calculation of stuffed bits based on frame
                    * content and CRC */
 };