-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[DM/CAN] Update CAN for DM #10992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−2
Merged
[DM/CAN] Update CAN for DM #10992
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright (c) 2006-2022, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2022-11-26 GuEe-GUI first version | ||
| */ | ||
|
|
||
| #include "can_dm.h" | ||
|
|
||
| static const rt_uint8_t dlc2len[] = | ||
| { | ||
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64 | ||
| }; | ||
|
|
||
| rt_uint8_t can_dlc2len(rt_uint8_t can_dlc) | ||
| { | ||
| return dlc2len[can_dlc & 0x0F]; | ||
| } | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static const rt_uint8_t len2dlc[] = | ||
| { | ||
| 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ | ||
| 9, 9, 9, 9, /* 9 - 12 */ | ||
| 10, 10, 10, 10, /* 13 - 16 */ | ||
| 11, 11, 11, 11, /* 17 - 20 */ | ||
| 12, 12, 12, 12, /* 21 - 24 */ | ||
| 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */ | ||
| 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */ | ||
| 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */ | ||
| 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */ | ||
| 15, 15, 15, 15, 15, 15, 15, 15, /* 57 - 64 */ | ||
| }; | ||
|
|
||
| rt_uint8_t can_len2dlc(rt_uint8_t len) | ||
| { | ||
| if (len <= 64) | ||
| { | ||
| return len2dlc[len]; | ||
| } | ||
|
|
||
| return 0xf; | ||
| } | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Copyright (c) 2006-2022, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2022-11-26 GuEe-GUI first version | ||
| */ | ||
|
|
||
| #ifndef __CAN_DM_H__ | ||
| #define __CAN_DM_H__ | ||
|
|
||
| #include <drivers/misc.h> | ||
|
|
||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* Special address description flags for the CAN_ID */ | ||
| #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ | ||
| #define CAN_RTR_FLAG 0x40000000U /* Remote transmission request */ | ||
| #define CAN_ERR_FLAG 0x20000000U /* Error message frame */ | ||
|
|
||
| /* Valid bits in CAN ID for frame formats */ | ||
| #define CAN_SFF_MASK 0x000007ffU /* Standard frame format (SFF) */ | ||
| #define CAN_EFF_MASK 0x1fffffffU /* Extended frame format (EFF) */ | ||
| #define CAN_ERR_MASK 0x1fffffffU /* Omit EFF, RTR, ERR flags */ | ||
| #define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */ | ||
|
|
||
| /* CAN payload length and DLC definitions according to ISO 11898-1 */ | ||
| #define CAN_MAX_DLC 8 | ||
| #define CAN_MAX_RAW_DLC 15 | ||
| #define CAN_MAX_DLEN 8 | ||
|
|
||
| /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ | ||
| #define CANFD_MAX_DLC 15 | ||
| #define CANFD_MAX_DLEN 64 | ||
|
|
||
| /* | ||
| * To be used in the CAN netdriver receive path to ensure conformance with | ||
| * ISO 11898-1 Chapter 8.4.2.3 (DLC field) | ||
| */ | ||
| #define can_get_dlc(v) (rt_min_t(rt_uint8_t, (v), CAN_MAX_DLC)) | ||
| #define canfd_get_dlc(v) (rt_min_t(rt_uint8_t, (v), CANFD_MAX_DLC)) | ||
|
|
||
| /** | ||
| * @brief Convert CAN DLC value to actual data length | ||
| * | ||
| * Converts a CAN Data Length Code (DLC) to the actual number of data bytes | ||
| * according to ISO 11898-1 and ISO 11898-7 (CAN FD) specifications. | ||
| * | ||
| * @param can_dlc The DLC value (0-15) | ||
| * @return The actual data length in bytes | ||
| */ | ||
| rt_uint8_t can_dlc2len(rt_uint8_t can_dlc); | ||
|
|
||
| /** | ||
| * @brief Convert data length to CAN DLC value | ||
| * | ||
| * Converts a data length in bytes to the appropriate CAN Data Length Code (DLC) | ||
| * according to ISO 11898-1 and ISO 11898-7 (CAN FD) specifications. | ||
| * | ||
| * @param len The data length in bytes (0-64) | ||
| * @return The corresponding DLC value (0-15) | ||
| */ | ||
| rt_uint8_t can_len2dlc(rt_uint8_t len); | ||
|
|
||
| #endif /* __CAN_DM_H__ */ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.