【发布时间】:2018-11-20 08:54:38
【问题描述】:
我有两个略有不同的结构,我想以某种方式链接以获得最快的结果。
这是两个结构:
/**
* @brief CAN Tx message structure definition
*/
typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */
uint32_t ExtId; /*!< Specifies the extended identifier.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */
uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted.
This parameter can be a value of @ref CAN_Identifier_Type */
uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted.
This parameter can be a value of @ref CAN_remote_transmission_request */
uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted.
This parameter must be a number between Min_Data = 0 and Max_Data = 8 */
uint8_t Data[8]; /*!< Contains the data to be transmitted.
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
}CanTxMsgTypeDef;
/**
* @brief CAN Rx message structure definition
*/
typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF */
uint32_t ExtId; /*!< Specifies the extended identifier.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF */
uint32_t IDE; /*!< Specifies the type of identifier for the message that will be received.
This parameter can be a value of @ref CAN_Identifier_Type */
uint32_t RTR; /*!< Specifies the type of frame for the received message.
This parameter can be a value of @ref CAN_remote_transmission_request */
uint32_t DLC; /*!< Specifies the length of the frame that will be received.
This parameter must be a number between Min_Data = 0 and Max_Data = 8 */
uint8_t Data[8]; /*!< Contains the data to be received.
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
uint32_t FMI; /*!< Specifies the index of the filter the message stored in the mailbox passes through.
This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF */
uint32_t FIFONumber; /*!< Specifies the receive FIFO number.
This parameter can be CAN_FIFO0 or CAN_FIFO1 */
}CanRxMsgTypeDef;
它们是用于 ARM 的 IAR 嵌入式工作台的 ST 驱动程序的一部分,所以我无法更改它们。
我的功能主要是进行过滤,这意味着无论我收到什么,我都需要立即发送。
驱动函数(我也无法更改)只允许传输CanTxMsgTypeDef 类型。所以每次我需要将CanRxMsgTypeDef 变量复制到CanTxMsgTypeDef 变量,这是非常低效的。
我正在寻找最快结果的最佳实践,即以最少的复制粘贴传输CanRxMsgTypeDef 数据。
请注意CanRxMsgTypeDef 仅具有额外数据,即所有要在接收到的CanRxMsgTypeDef 变量中传输的信息。
【问题讨论】:
-
从技术上讲,您需要在两者之间将数据复制到 RAM - 没有办法。您不能将 CAN 寄存器 rx 缓冲区作为地址传递给 CAN tx。因此,即使使用联合版本(您应该这样做),您也会得到 2 个必须处理的硬拷贝。
标签: c embedded can-bus iar type-punning