Hi All,
I am trying to write some functions to transmit data using the CAN interface in which would be possible to select the mailbox to use in the transmission.
The idea is to pass the Mailbox number as a parameter of the function and then set up the corresponding mailbox inside. I am trying to do it with a switch() and then add a case for each of the 16 mailboxes available for transmission, but the issue is that as I have to set up the ECanaMboxes and ECanaRegs structures for each of them separately, it results in a HUGE amount of code.
Is there a better way to implement such a feature?
I though of the possibility of using a variable that replace the ECanaMboxes and ECanaRegs field of each mailbox I want to use, so that I use the same code for all of them... for instance:
If I want to use mailbox 10 it would be:
ECanaShadow.CANTRR.all = ECanaRegs.CANTRR.all;
ECanaShadow.CANTRR.bit.B10 = 1;
ECanaRegs.CANTRR.all = ECanaShadow.CANTRR.all;
and it would be great to have a solution like this:
ECanaShadow.CANTRR.all = ECanaRegs.CANTRR.all;
ECanaShadow.CANTRR.bit.mailbox_variable = 1;
ECanaRegs.CANTRR.all = ECanaShadow.CANTRR.all;
I know what I propose is not feasible like this, but I would like to know if using a macro or something like that it is possible to access the registers using a variable