canframelen.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * canframelen.h
  3. *
  4. * Copyright (c) 2013, 2014 Czech Technical University in Prague
  5. *
  6. * Author: Michal Sojka <sojkam1@fel.cvut.cz>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of Czech Technical University in Prague nor the
  17. * names of its contributors may be used to endorse or promote
  18. * products derived from this software without specific prior
  19. * written permission.
  20. *
  21. * Alternatively, provided that this notice is retained in full, this
  22. * software may be distributed under the terms of the GNU General
  23. * Public License ("GPL") version 2, in which case the provisions of the
  24. * GPL apply INSTEAD OF those given above.
  25. *
  26. * The provided data structures and external interfaces from this code
  27. * are not restricted to be used by modules with a GPL compatible license.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40. * DAMAGE.
  41. *
  42. * Send feedback to <linux-can@vger.kernel.org>
  43. *
  44. */
  45. #ifndef CANFRAMELEN_H
  46. #define CANFRAMELEN_H
  47. #include <linux/can.h>
  48. /**
  49. * Frame length calculation modes.
  50. *
  51. * CFL_WORSTCASE corresponds to *worst* case calculation for
  52. * stuff-bits - see (1)-(3) in [1]. The worst case number of bits on
  53. * the wire can be calculated as:
  54. *
  55. * (34 + 8n - 1)/4 + 34 + 8n + 13 for SFF frames (11 bit CAN-ID) => 55 + 10n
  56. * (54 + 8n - 1)/4 + 54 + 8n + 13 for EFF frames (29 bit CAN-ID) => 80 + 10n
  57. *
  58. * while 'n' is the data length code (number of payload bytes)
  59. *
  60. * [1] "Controller Area Network (CAN) schedulability analysis:
  61. * Refuted, revisited and revised", Real-Time Syst (2007)
  62. * 35:239-272.
  63. *
  64. */
  65. enum cfl_mode {
  66. CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */
  67. CFL_WORSTCASE, /* worst case estimation - see above */
  68. CFL_EXACT, /* exact calculation of stuffed bits based on frame
  69. * content and CRC */
  70. };
  71. /**
  72. * Calculates the number of bits a frame needs on the wire (including
  73. * inter frame space).
  74. *
  75. * Mode determines how to deal with stuffed bits.
  76. */
  77. unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu);
  78. #endif