Brad Collins

Zeroing Out the RAM

Discussion created by Brad Collins on Apr 28, 2006
Latest reply on Apr 28, 2006 by Brad Collins

I am porting some code from Cosmic to CW.  On reset, this code zeroes out all RAM variable space using the micro_clear_ram function:

void micro_clear_ram(void){   byte *i;   if (&_ubsct_start != &_ubsct_end)   {      for (i = &_ubsct_start; i < &_ubsct_end; i++)      {         i = 0;      }   }   if (&_nzpages_start != &_nzpages_end)   {      for (i = &_nzpages_start; i < &_nzpages_end; i++)      {         i = 0;      }   }}

Here is an excerpt from the Cosmic linker file that assigns names to portions of memory and evidently maps those memory locations to the start/end variables above:

+seg .ubsct    -b0x0050    -nZPAGE     -m0x0100-0x0050+seg .nzpages  -b0x0100    -nNZPAGES   -m0x0430-0x0100+def __ubsct_start=start(ZPAGE)+def __ubsct_end=end(ZPAGE)+def __nzpages_start=start(NZPAGES)+def __nzpages_end=end(NZPAGES)

Anything like that in CodeWarrior?  Using either the SECTIONS or PLACEMENT names, can I do something like this?

void micro_clear_ram_CW(void){   byte *i;   for (i = &START(MY_ZEROPAGE); i < &END(MY_ZEROPAGE); i++)   {      *i = 0;   }   for (i = &START(DEFAULT_RAM); i < &END(DEFAULT_RAM); i++)   {      *i = 0;   }}

Or, is there a setting somewhere (perhaps a bean setting) that zeroes out RAM on reset?

Thanks much for your help.

Outcomes