CANTxFrame outside threads.
Posted: Thu Jul 14, 2016 10:30 am
Hi everybody!
I am not sure this is the right section of the forum to ask the question, however I have the following question.
I have opened the STM32F4xx-CAN project embedded in Chibistudio GCC 4.9 that contains the thread :
[spoil]static THD_FUNCTION(can_tx, p) {
CANTxFrame txmsg;
(void)p;
chRegSetThreadName("transmitter");
txmsg.IDE = CAN_IDE_EXT;
txmsg.EID = 0x01234567;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x55AA55AA;
txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminateX()) {
canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
}[/spoil]
I have tried to move the declaration and the data assignment of txmsg outside the thread (I want to use it on a callback of an interrupt), but the compiler gave me the following result:
[spoil]11:20:49 **** Incremental Build of configuration Default for project STM32F4xx-CAN ****
make -j4 all
Compiling main.c
main.c:72:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.IDE = CAN_IDE_EXT;
^
main.c:73:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.EID = 0x01234567;
^
main.c:74:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.RTR = CAN_RTR_DATA;
^
main.c:75:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.DLC = 8;
^
main.c:76:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[0] = 0x55AA55AA;
^
main.c:77:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[1] = 0x00FF00FF;
^
make: *** [build/obj/main.o] Error 1
11:20:53 Build Finished (took 4s.720ms)[/spoil]
It seems that I cannot use this type outside of the thread. Why?
P.S. obviously I have commented the code in the thread that I moved outside.
I thank you in advance for your help.
I am not sure this is the right section of the forum to ask the question, however I have the following question.
I have opened the STM32F4xx-CAN project embedded in Chibistudio GCC 4.9 that contains the thread :
[spoil]static THD_FUNCTION(can_tx, p) {
CANTxFrame txmsg;
(void)p;
chRegSetThreadName("transmitter");
txmsg.IDE = CAN_IDE_EXT;
txmsg.EID = 0x01234567;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x55AA55AA;
txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminateX()) {
canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
}[/spoil]
I have tried to move the declaration and the data assignment of txmsg outside the thread (I want to use it on a callback of an interrupt), but the compiler gave me the following result:
[spoil]11:20:49 **** Incremental Build of configuration Default for project STM32F4xx-CAN ****
make -j4 all
Compiling main.c
main.c:72:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.IDE = CAN_IDE_EXT;
^
main.c:73:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.EID = 0x01234567;
^
main.c:74:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.RTR = CAN_RTR_DATA;
^
main.c:75:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.DLC = 8;
^
main.c:76:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[0] = 0x55AA55AA;
^
main.c:77:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[1] = 0x00FF00FF;
^
make: *** [build/obj/main.o] Error 1
11:20:53 Build Finished (took 4s.720ms)[/spoil]
It seems that I cannot use this type outside of the thread. Why?
P.S. obviously I have commented the code in the thread that I moved outside.
I thank you in advance for your help.