Zeroing Out the RAM

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Zeroing Out the RAM

2,845件の閲覧回数
TheBroadLea
Contributor I

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.

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

563件の閲覧回数
rhinoceroshead
Contributor I
If you create a project and use ANSI C, then the CodeWarrior automatically generated startup code will clear all of your global variables for you.  It won't clear all of the RAM though.  Why would you need to?
0 件の賞賛
返信

563件の閲覧回数
TheBroadLea
Contributor I

That's essentially it: to reset variables to zero.

Thanks for the tip.  With your comment, I've been able to find that code.  It's in the Init function in Start08.c for anyone who's curious.

Thanks again.

Message Edited by The Broad Lea on 04-28-200610:31 AM

0 件の賞賛
返信