Better use of NO INIT section
Posted: Sat Aug 25, 2018 7:30 pm
I'm trying to improve using the "NO_INIT" section to keep data on any type of reset (including some POWER_ON with BOD), but I need more information ...
For now, the simplest method would be to initialize the variable if the reason for the reset is POWER_ON, but some tests with BOD to save variables, even the reason is POWER_ON, the variables are still saved. This added me a second check that if the variable has a value outside my scope (eg. 0-128), I know it has been "reset".
But there the problem is born, what are the chances of the variable NO_INIT being initialized with a value within my scope? In all tests, the variables init with very large random(?) values (> 1G) ...
1. What values and why do they receive these values?
2. What is their scope when the RAM is initialized (totally random)?
3. Is there any bit or something specifying that the values have been changed? How can I improve the method of initializing variables if even with POWER_ON they can keep what was saved.
A simple example of what I have been using to know if my values have been overwritten:
For now, the simplest method would be to initialize the variable if the reason for the reset is POWER_ON, but some tests with BOD to save variables, even the reason is POWER_ON, the variables are still saved. This added me a second check that if the variable has a value outside my scope (eg. 0-128), I know it has been "reset".
But there the problem is born, what are the chances of the variable NO_INIT being initialized with a value within my scope? In all tests, the variables init with very large random(?) values (> 1G) ...
1. What values and why do they receive these values?
2. What is their scope when the RAM is initialized (totally random)?
3. Is there any bit or something specifying that the values have been changed? How can I improve the method of initializing variables if even with POWER_ON they can keep what was saved.
A simple example of what I have been using to know if my values have been overwritten:
Code: Select all
RTC_NOINIT_ATTR uint8_t x;
if (rtc_get_reset_reason(0) == POWERON_RESET && x > 5000)
{
x = 0;
}