Hi
The following is a trivial routine. Function: Using the SSI controller, write a byte of data (dat) into the SSI (Synchronous Serial Interface)(Luminary LM3S9B96) Tx register(actually a FIFO) and flush the Rx register(also a FIFO) by reading it. Works fine no problem... but the compliler (correctley) says:
Fatfs\port\fm_mmc.c(65): warning: #550-D: variable "rcvdat" was set but never used.
Any ideas on how to keep the code tight (can't see how you can make it tighter... - using direct pointers to the registers) and - stop it complaining?
#define HWREGB(x) (*((volatile unsigned char *)(x))) #define HWREG(x) (*((volatile unsigned long *)(x))) #define SSI0_BASE 0x40008000 // SSI0 // etc void XmitSsi (unsigned char dat) { unsigned char rcvdat; // Write dat // Wait until there is space. while(!(HWREG(SSI0_BASE + SSI_O_SR) & SSI_SR_TNF)){} // Write to the SSI. HWREGB(SSI0_BASE + SSI_O_DR) = dat; // Flush Recieve FIFO // Wait until there is data to be read. while(!(HWREG(SSI0_BASE + SSI_O_SR) & SSI_SR_RNE)){} // Read data from SSI. rcvdat = HWREGB(SSI0_BASE + SSI_O_DR); }
Make rcvdat volatile.
Thank you works!!
In embedded programming, it's not uncommon to have a situation like this where it's the act of reading that's important - not the value read.
Therefore, it'd be really useful if Keil had a specific feature to support this; eg, a #pragma unused ?
"Therefore, it'd be really useful if Keil had a specific feature to support this; eg, a #pragma unused ?"
Agreed.
#pragma diag_suppress can be used to suppress all instances of a specified message - maybe extend that to suppress the specified warning just for a specific symbol...?
www.keil.com/.../armccref_CIHECIAD.htm http://www.keil.com/support/man/docs/armcc/armcc_Chdcgaie.htm
You don't have to assign the value to a variable to read it. Try this:
(void)HWREGB(SSI0_BASE + SSI_O_DR); /* read register and discard value */
But then you get it complaining that "code has no effect" or suchlike...
Hi Andrew Pretty smart idea! I love niffty software tricks.:) Compiler liked it - said nothing. Trying to understand what that means - like a void return argument to a function? Oh - it does work :)
Apolageez - Andrew - thank you as well - I am very much a rookie programmer, although I am a hardware engineer - so that helps (a lot). First time I have used a discussion forum... to answer those questions that are not in any of the reference/text books :) Will be back, if I may... got lots of questions:)
The (void) isn't needed for the code.
It's there as some form of "contract": Me (the developer) promises that I understand that the called function returns a value, but I do not want to keep that result.
Adding the (void) means that static code analyzers will not generate a warning about an unused return value. But the code will work (and the compiler itself) should not warn if you don't have any (void).