|
| 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 | + |
| 11 | +#include "can_dm.h" |
| 12 | + |
| 13 | +static const rt_uint8_t dlc2len[] = |
| 14 | +{ |
| 15 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64 |
| 16 | +}; |
| 17 | + |
| 18 | +rt_uint8_t can_dlc2len(rt_uint8_t can_dlc) |
| 19 | +{ |
| 20 | + return dlc2len[can_dlc & 0x0F]; |
| 21 | +} |
| 22 | + |
| 23 | +static const rt_uint8_t len2dlc[] = |
| 24 | +{ |
| 25 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ |
| 26 | + 9, 9, 9, 9, /* 9 - 12 */ |
| 27 | + 10, 10, 10, 10, /* 13 - 16 */ |
| 28 | + 11, 11, 11, 11, /* 17 - 20 */ |
| 29 | + 12, 12, 12, 12, /* 21 - 24 */ |
| 30 | + 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */ |
| 31 | + 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */ |
| 32 | + 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */ |
| 33 | + 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */ |
| 34 | + 15, 15, 15, 15, 15, 15, 15, 15, /* 57 - 64 */ |
| 35 | +}; |
| 36 | + |
| 37 | +rt_uint8_t can_len2dlc(rt_uint8_t len) |
| 38 | +{ |
| 39 | + if (len <= 64) |
| 40 | + { |
| 41 | + return len2dlc[len]; |
| 42 | + } |
| 43 | + |
| 44 | + return 0xf; |
| 45 | +} |
0 commit comments