Re: .text variable and optimization issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2012/7/4 Ángel González <keisial@xxxxxxxxx>:
> On 04/07/12 22:30, Marcin S wrote:
>> 2012/7/4 Václav Zeman:
>>> The compiler probably sees through your games. The language defines that
>>> constants are really, constant, AFAIK. Try changing the 'const uint16_t
>>> CFlashSignature::SIGNATURE' to 'const volatile uint16_t
>>> CFlashSignature::SIGNATURE' or just drop the const entirely (and add
>>> volatile).
>> Hi,
>> Yes, i did tried this before, unfortunately with this modifier
>> (volatile or omitting const at all) makes variable not to land in
>> .text (flash) but in RAM, so, this won't do me any good if flag will
>> reset after power down - i need it to be persistent, thats the whole
>> point.
> Have you tried adding an explicit section attribute?
>
> __attribute__ ((section (".text")));
>
> http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bsection_007d-function-attribute-2598


Yes, when tried to put non-const var into .text, the attribute is
ignored and it lands in ram anyway :(
But i came up with new implementation, so far its working with any
level of optimization and it leaves little or no room for it.

const uint16_t CFlashSignature::SIGNATURE = 0xFFFF;
uint32_t CFlashSignature::addr = (uint32_t)&CFlashSignature::SIGNATURE;

bool CFlashSignature::isFristRun()
{
	return *(uint16_t*)addr;
}

CFlashSignature::TFlashUpdResult CFlashSignature::setSignature()
{
	if(isFristRun())
	{
		FLASH_Unlock();
                FLASH_ProgramHalfWord(addr,0);
		FLASH_Lock();
	}
}

I've introduced new  RW variable "uint32_t addr" located in ram, which
holds an address to SIGNATURE and its used for reading and writing
operations. It's in global scope and its loaded at run time, ATM i
don't see how this could be optimized.

Any thoughts on that solution?



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux