Linking two message structures together
I have two slightly different structures which i would like to somehow link for fastest results.
These are the two structues:
/**
* @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;
They are a part of ST drivers used at IAR embedded workbench for ARM, so I can't change them.
My function is mostly doing filtering which means that whatever I receive, I need to transmit almost immediately.
Driver functions (which I also can't change) only allow transmitting CanTxMsgTypeDef
types. So each time I need to copy CanRxMsgTypeDef
variable to CanTxMsgTypeDef
variable which is very inefficient.
I am looking for best practice for fastest results i.e. transmitting CanRxMsgTypeDef
data with minimum copy-paste.
Please note how CanRxMsgTypeDef
has only extra data i.e. all the information to transmit already at the received CanRxMsgTypeDef
variable.
c embedded can iar type-punning
add a comment |
I have two slightly different structures which i would like to somehow link for fastest results.
These are the two structues:
/**
* @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;
They are a part of ST drivers used at IAR embedded workbench for ARM, so I can't change them.
My function is mostly doing filtering which means that whatever I receive, I need to transmit almost immediately.
Driver functions (which I also can't change) only allow transmitting CanTxMsgTypeDef
types. So each time I need to copy CanRxMsgTypeDef
variable to CanTxMsgTypeDef
variable which is very inefficient.
I am looking for best practice for fastest results i.e. transmitting CanRxMsgTypeDef
data with minimum copy-paste.
Please note how CanRxMsgTypeDef
has only extra data i.e. all the information to transmit already at the received CanRxMsgTypeDef
variable.
c embedded can iar type-punning
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03
add a comment |
I have two slightly different structures which i would like to somehow link for fastest results.
These are the two structues:
/**
* @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;
They are a part of ST drivers used at IAR embedded workbench for ARM, so I can't change them.
My function is mostly doing filtering which means that whatever I receive, I need to transmit almost immediately.
Driver functions (which I also can't change) only allow transmitting CanTxMsgTypeDef
types. So each time I need to copy CanRxMsgTypeDef
variable to CanTxMsgTypeDef
variable which is very inefficient.
I am looking for best practice for fastest results i.e. transmitting CanRxMsgTypeDef
data with minimum copy-paste.
Please note how CanRxMsgTypeDef
has only extra data i.e. all the information to transmit already at the received CanRxMsgTypeDef
variable.
c embedded can iar type-punning
I have two slightly different structures which i would like to somehow link for fastest results.
These are the two structues:
/**
* @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;
They are a part of ST drivers used at IAR embedded workbench for ARM, so I can't change them.
My function is mostly doing filtering which means that whatever I receive, I need to transmit almost immediately.
Driver functions (which I also can't change) only allow transmitting CanTxMsgTypeDef
types. So each time I need to copy CanRxMsgTypeDef
variable to CanTxMsgTypeDef
variable which is very inefficient.
I am looking for best practice for fastest results i.e. transmitting CanRxMsgTypeDef
data with minimum copy-paste.
Please note how CanRxMsgTypeDef
has only extra data i.e. all the information to transmit already at the received CanRxMsgTypeDef
variable.
c embedded can iar type-punning
c embedded can iar type-punning
edited Nov 20 '18 at 9:59
Lundin
108k17158262
108k17158262
asked Nov 20 '18 at 8:54


RanRan
188
188
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03
add a comment |
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03
add a comment |
1 Answer
1
active
oldest
votes
Use union
of the two struct
s and you can access any member from the common initial part as per 6.5.2.3p6:
One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
Sample code:
union common
{
CanRxMsgTypeDef rx;
CanTxMsgTypeDef tx;
};
void someFunc(CanTxMsgTypeDef arg)
{
printf("inside func tx.StdId=%dn",arg.StdId);
printf("inside func tx.DLC=%dn",arg.DLC);
}
int main()
{
/* Assign RX type to the union */
union common test = {1,2,3,4,5,{0,0,0,0,0,0,0,0},7,8};
printf("test.tx.StdId=%dn",test.tx.StdId);
printf("test.rx.StdId=%dn",test.rx.StdId);
printf("test.tx.DLC=%dn",test.tx.DLC);
printf("test.rx.DLC=%dn",test.rx.DLC);
printf("test.rx.FMI=%dn",test.rx.FMI);
/* Use the union as tx type */
someFunc(test.tx);
return 0;
}
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be calledCanMsgTypeDef
which has arx
andtx
part. Or for those who aren't stuck with UnReadAbleCamelCase: unioncan_msg_t
, with structcan_txmsg_t
and structcan_rxmsg_t
.
– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the nameCanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.
– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389343%2flinking-two-message-structures-together%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use union
of the two struct
s and you can access any member from the common initial part as per 6.5.2.3p6:
One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
Sample code:
union common
{
CanRxMsgTypeDef rx;
CanTxMsgTypeDef tx;
};
void someFunc(CanTxMsgTypeDef arg)
{
printf("inside func tx.StdId=%dn",arg.StdId);
printf("inside func tx.DLC=%dn",arg.DLC);
}
int main()
{
/* Assign RX type to the union */
union common test = {1,2,3,4,5,{0,0,0,0,0,0,0,0},7,8};
printf("test.tx.StdId=%dn",test.tx.StdId);
printf("test.rx.StdId=%dn",test.rx.StdId);
printf("test.tx.DLC=%dn",test.tx.DLC);
printf("test.rx.DLC=%dn",test.rx.DLC);
printf("test.rx.FMI=%dn",test.rx.FMI);
/* Use the union as tx type */
someFunc(test.tx);
return 0;
}
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be calledCanMsgTypeDef
which has arx
andtx
part. Or for those who aren't stuck with UnReadAbleCamelCase: unioncan_msg_t
, with structcan_txmsg_t
and structcan_rxmsg_t
.
– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the nameCanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.
– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
add a comment |
Use union
of the two struct
s and you can access any member from the common initial part as per 6.5.2.3p6:
One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
Sample code:
union common
{
CanRxMsgTypeDef rx;
CanTxMsgTypeDef tx;
};
void someFunc(CanTxMsgTypeDef arg)
{
printf("inside func tx.StdId=%dn",arg.StdId);
printf("inside func tx.DLC=%dn",arg.DLC);
}
int main()
{
/* Assign RX type to the union */
union common test = {1,2,3,4,5,{0,0,0,0,0,0,0,0},7,8};
printf("test.tx.StdId=%dn",test.tx.StdId);
printf("test.rx.StdId=%dn",test.rx.StdId);
printf("test.tx.DLC=%dn",test.tx.DLC);
printf("test.rx.DLC=%dn",test.rx.DLC);
printf("test.rx.FMI=%dn",test.rx.FMI);
/* Use the union as tx type */
someFunc(test.tx);
return 0;
}
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be calledCanMsgTypeDef
which has arx
andtx
part. Or for those who aren't stuck with UnReadAbleCamelCase: unioncan_msg_t
, with structcan_txmsg_t
and structcan_rxmsg_t
.
– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the nameCanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.
– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
add a comment |
Use union
of the two struct
s and you can access any member from the common initial part as per 6.5.2.3p6:
One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
Sample code:
union common
{
CanRxMsgTypeDef rx;
CanTxMsgTypeDef tx;
};
void someFunc(CanTxMsgTypeDef arg)
{
printf("inside func tx.StdId=%dn",arg.StdId);
printf("inside func tx.DLC=%dn",arg.DLC);
}
int main()
{
/* Assign RX type to the union */
union common test = {1,2,3,4,5,{0,0,0,0,0,0,0,0},7,8};
printf("test.tx.StdId=%dn",test.tx.StdId);
printf("test.rx.StdId=%dn",test.rx.StdId);
printf("test.tx.DLC=%dn",test.tx.DLC);
printf("test.rx.DLC=%dn",test.rx.DLC);
printf("test.rx.FMI=%dn",test.rx.FMI);
/* Use the union as tx type */
someFunc(test.tx);
return 0;
}
Use union
of the two struct
s and you can access any member from the common initial part as per 6.5.2.3p6:
One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
Sample code:
union common
{
CanRxMsgTypeDef rx;
CanTxMsgTypeDef tx;
};
void someFunc(CanTxMsgTypeDef arg)
{
printf("inside func tx.StdId=%dn",arg.StdId);
printf("inside func tx.DLC=%dn",arg.DLC);
}
int main()
{
/* Assign RX type to the union */
union common test = {1,2,3,4,5,{0,0,0,0,0,0,0,0},7,8};
printf("test.tx.StdId=%dn",test.tx.StdId);
printf("test.rx.StdId=%dn",test.rx.StdId);
printf("test.tx.DLC=%dn",test.tx.DLC);
printf("test.rx.DLC=%dn",test.rx.DLC);
printf("test.rx.FMI=%dn",test.rx.FMI);
/* Use the union as tx type */
someFunc(test.tx);
return 0;
}
answered Nov 20 '18 at 9:42


iVoidiVoid
471111
471111
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be calledCanMsgTypeDef
which has arx
andtx
part. Or for those who aren't stuck with UnReadAbleCamelCase: unioncan_msg_t
, with structcan_txmsg_t
and structcan_rxmsg_t
.
– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the nameCanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.
– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
add a comment |
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be calledCanMsgTypeDef
which has arx
andtx
part. Or for those who aren't stuck with UnReadAbleCamelCase: unioncan_msg_t
, with structcan_txmsg_t
and structcan_rxmsg_t
.
– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the nameCanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.
– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
1
1
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be called
CanMsgTypeDef
which has a rx
and tx
part. Or for those who aren't stuck with UnReadAbleCamelCase: union can_msg_t
, with struct can_txmsg_t
and struct can_rxmsg_t
.– Lundin
Nov 20 '18 at 9:54
Yeah this is the correct solution. It even allows wild typecasts between the different types (type punning). The union should preferably be called
CanMsgTypeDef
which has a rx
and tx
part. Or for those who aren't stuck with UnReadAbleCamelCase: union can_msg_t
, with struct can_txmsg_t
and struct can_rxmsg_t
.– Lundin
Nov 20 '18 at 9:54
@Lundin, good suggestion about the name
CanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.– iVoid
Nov 20 '18 at 9:59
@Lundin, good suggestion about the name
CanMsgTypeDef
- CamelCase should be okay as this code intends to work with original ST library code and types which use CamelCase.– iVoid
Nov 20 '18 at 9:59
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Thank you! I will check it soon :)
– Ran
Nov 20 '18 at 13:08
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
Indeed seems to work. Thank you! :)
– Ran
Dec 11 '18 at 14:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389343%2flinking-two-message-structures-together%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Technically, you need to copy the data to RAM in between though - no way around it. You can't pass the CAN register rx buffer as address to CAN tx. So even if using the union version - which you should - you get 2 hardcopies that have to be processed.
– Lundin
Nov 20 '18 at 10:03