can_dm.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-26 GuEe-GUI first version
  9. */
  10. #include "can_dm.h"
  11. static const rt_uint8_t dlc2len[] =
  12. {
  13. 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64
  14. };
  15. rt_uint8_t can_dlc2len(rt_uint8_t can_dlc)
  16. {
  17. return dlc2len[can_dlc & 0x0F];
  18. }
  19. static const rt_uint8_t len2dlc[] =
  20. {
  21. 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
  22. 9, 9, 9, 9, /* 9 - 12 */
  23. 10, 10, 10, 10, /* 13 - 16 */
  24. 11, 11, 11, 11, /* 17 - 20 */
  25. 12, 12, 12, 12, /* 21 - 24 */
  26. 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */
  27. 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */
  28. 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */
  29. 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */
  30. 15, 15, 15, 15, 15, 15, 15, 15, /* 57 - 64 */
  31. };
  32. rt_uint8_t can_len2dlc(rt_uint8_t len)
  33. {
  34. if (len <= 64)
  35. {
  36. return len2dlc[len];
  37. }
  38. return 0xf;
  39. }