Reply by simitel0299 August 16, 20042004-08-16
static unsigned char ProgBuff[0x100];
static unsigned char EraseBuff[0x100];

unsigned char srcbuf[0x100];

static unsigned long la, lb;
static unsigned char num4k, data, b1, b2;
static unsigned char aa, uu, lastb;
static unsigned int addr16;

static unsigned long fphyaddr;
static unsigned char fwrdata;

void _H16DoRAM(void * ramfunc);
void lowlevelprog(void);
void lowlevelerase(void);
void LowLevelErase(unsigned long dst, unsigned char sec_chip);
char EraseFLASH(unsigned long dst);
int GenWriteFlash(long dst, void * src, unsigned int leng);

unsigned char buf_4k[0x1000]; //////////////////////////////////////////////////////////////////////
///
/*****************************************************************/
/* Write squence of Commands to PROGRAM data to FLASH.
***************************************************************/
#asm root nodebug
lowlevelprog::
LD A, XPC
PUSH AF
PUSH BC
PUSH hl

ld a, (b1)
ld xpc, a
ld a, (aa)
ld (0xE555), a

ld a, (b2)
ld xpc, a
ld a, (uu)
ld (0xEAAA), a

ld a, (b1)
ld xpc, a
ld a, (lastb)
ld (0xE555), a

ld a, (num4k)
ld b, 0xE
sub b
ld xpc, a
ld hl, (addr16)
ld a, (data)
ld (hl), a

ld A, 0xFE
.waitloop_lo:
DEC A

CP 0
JR NZ, .waitloop_lo
.out:
POP hl

POP BC
LD L,C
LD H,B

POP AF
ld XPC, A

JP (HL)

END_OF_Prog::
#endasm

/********************************************************************/
/* Write sequence of commands to erase one FLASH sector, starting at
para. */
/********************************************************************/
#asm root nodebug
lowlevelerase::
ld a, xpc ;; Save XPC !
PUSH AF
PUSH BC
PUSH hl ld a, (b1)
ld xpc, a
ld a, (aa)
ld (0xE555), a

ld a, (b2)
ld xpc, a
ld a, (uu)
ld (0xEAAA), a

ld a, (b1)
ld xpc, a
ld a, 0x80
ld (0xE555), a

ld a, (b1)
ld xpc, a
ld a, (aa)
ld (0xE555), a

ld a, (b2)
ld xpc, a
ld a, (uu)
ld (0xEAAA), a ld a, (num4k)
ld b, 0xE
sub b

ld xpc, a
ld a, 0x30///////////(lastb)
ld (0xE000), a ld A, 0xFE
.waitloop_lo:
DEC A

CP 0
JR NZ, .waitloop_lo

POP HL
POP BC
LD L,C
LD H,B

POP AF
ld xpc, a

JP (HL)

END_OF_Erase::
#endasm void MapFlashArea(void)
{
auto unsigned char aa;
aa = 0xC0;
WrPortI(MB0CR, &MB0CRShadow, aa);
WrPortI(MB1CR, &MB1CRShadow, aa);
#endif
}

nodebug void UnMapFlashArea(void)
{
}

root nodebug void LowLevelProg(unsigned long dst, unsigned char idata)
{
fphyaddr = dst;
fwrdata = idata;

la = (fphyaddr & 0xF0000ul) | 0x5555ul;
lb = (fphyaddr & 0xF0000ul) | 0x2AAAul;
b1 = (unsigned char)((la - 0xE555ul) >> 12ul);
b2 = (unsigned char)((lb - 0xE555ul) >> 12ul);

num4k = (unsigned char)( (fphyaddr >> 12ul) & 0xFFul);
addr16 = (unsigned int)( (fphyaddr & 0x0FFFul) + 0xE000ul);
data = fwrdata;

aa = 0xAA & 0xFF;
uu = 0x55 & 0xFF;
lastb = 0xA0 & 0xFF;

_H16DoRAM(ProgBuff);
}

root nodebug void LowLevelErase(unsigned long dst, unsigned char
sec_chip)
{
sec_chip = sec_chip;

num4k = (unsigned char) ((dst >> 12) & 0xFFul);

la = (dst & 0xF0000ul) | 0x5555ul;
lb = (dst & 0xF0000ul) | 0x2AAAul;

b1 = (unsigned char)((la - 0xE555ul) >> 12ul);
b2 = (unsigned char)((lb - 0xE555ul) >> 12ul);

aa = 0xAA & 0xFF;
uu = 0x55 & 0xFF;

lastb = 0x30 & 0xFF;

_H16DoRAM(EraseBuff);
}

#asm root nodebug
_H16DoRAM::
PUSH BC
PUSH HL
ld bc, ret_addr
ld hl, (sp+@SP+2+4)

jp (hl) // CALL the RAM Function!

ret_addr:
POP HL
POP BC
ret
#endasm

root char EraseFLASH(unsigned long dst)
{
dst &= 0xFFF000ul;

LowLevelErase(dst, 0);

return 0;
}

/*** BeginHeader ProgramFLASH */
root char ProgramFLASH(unsigned long dst, unsigned long src, unsigned
long length);
/*** EndHeader */
/*********************************************************************
*******/
/* ProgramFLASH: Write data to FLASH ROM.
*/
/* Inputs: dst, Destination address in FLASH;
*/
/* src, Source address containing data to write
into the FLASH. */
/* length, the length of data to Programe.
*/
/* NOTES: It is used when compiled to _RAM_.
*/
/* Return: 0: Error in address range.
*/
/*********************************************************************
*******/
root nodebug char ProgramFLASH(unsigned long dst, unsigned long src,
unsigned long length)
{
auto unsigned char idata;
auto unsigned long i;

for(i=0;i<length;i++)
{
idata = getonebyte(src);
LowLevelProg(dst, idata);
dst ++;
src ++;
}
return 1;
} int GenWriteFlash(long dst, void * src, unsigned int leng)
{
auto int rc;
auto unsigned long bsec, nsec, soff, edst;
auto unsigned int slen, len;

edst = dst + leng;

while (edst > dst)
{
soff = dst & 0xFFF;
bsec = dst & 0xFFF000;
nsec = bsec + 0x1000; ///
MapFlashArea();

xmem2root(buf_4k, bsec, 0x1000);

slen = (unsigned int)(nsec - dst);
len = (slen > leng) ? leng : slen;

memcpy( buf_4k + (unsigned int)soff, src, (size_t)
len);
EraseFLASH(bsec);
ProgramFLASH(bsec, paddr(buf_4k), 0x1000);

UnMapFlashArea();

dst += len;
leng -= len;
}
rc = 0;

return rc;
}

main(void)
{
auto int i;
auto unsigned long dst;

for(i=0;i<0x100;i++)
srcbuf[i] = i;

aa = uu = lastb = b1 = b2 = num4k = 0;

i = (int)END_OF_Prog - (int)lowlevelprog;
memcpy(ProgBuff, (void*)lowlevelprog, i);

i = (int)END_OF_Erase - (int)lowlevelerase;
memcpy(EraseBuff, (void*)lowlevelerase, i);
#ifdef _FLASH_
GenWriteFlash(0x75000, srcbuf, 0x100);
#else
GenWriteFlash(0xF5000, srcbuf, 0x100);
#endif
printf("Done!\n");
while(1)
{
for(i=0;i<0x1000;i++)
;
printf("Done!\n");
}
}


Reply by simitel0299 August 14, 20042004-08-14
Thank you for your reply!
But, I want to know why I can do FLASH operation when compile the
application in RAM.

But why not when I compile it into FLASH.

The app. did all the copying and jumping, why the result is
different?????

--- In rabbit-semi@rabb..., gautham kotha <gautham4ind@y...>
wrote:
>
> Ok simitel i am not sure whether i am right or wrong. The
addressing concept may be different in flash memories paging and
segmentaion comes into picture please refer with some note spare me
if iam wrong. Writing a byte and erasing a byte my be same but
loading a program may differs
> Gautham
>
> simitel0299 <simitel0299@y...> wrote:
> Why nobody help me?
> Please, I want to know the answer.
> Thank you for all your help and regards
>
> SiMitel > --- In rabbit-semi@rabb..., "simitel0299"
<simitel0299@y...>
> wrote:
> > Dear all,
> > I am now using DC8.XX with Rabbit 3000 as CPU, and one 512KB
> > FLASH, and 512KB SRAM on the board.
> >
> > I programe an application which will store some data to
FLASH.
> I
> > know I can write FLASH ROM by using WriteFlash or WriteFlash2
from
> > Dynamic C. But I want to do this by myself !
> >
> > That is: I want to implement these functions by myself !
> > I did this in the following way.
> >
> > 1. I define two char array which are in Data Segment, which
are
> > used to run the Erase Flash and Write FLash functions in RAM.
> >
> > 2. In the code, I copied the Erase and Write FLASH function
to
> > these char arrays, and setup stacks that these functions run in
RAM
> > can return back to the control flow in FLASH.
> >
> > 3. Call wrapper functions which ready the data to needed by
> Erase
> > and Write FLash Functions, and then the wrapper functions will
Jump
> > to the function(char array) to Programe FLASH.
> >
> > The psuduo codes are as follows:
> >
> > static unsigned char erasefunc[0x200], writefunc[0x200];
> >
> > void EraseWrapper()
> > {
> > setup data needed by EraseFlash functions.
> > ....
> > memcpy(erasefunc, EraseFlash, len);
> >
> > #asm
> > :
> > :
> > calling erasefunc[]
> > :
> > :
> > #endasm
> > }
> >
> > void WriteWrapper()
> > {
> > setup data needed by WriteFlash functions.
> > ....
> > memcpy(writefunc, WriteFlash, len);
> >
> > #asm
> > :
> > :
> > calling writefunc[]
> > :
> > :
> > #endasm
> > }
> >
> > void EraseFlash()
> > {
> > #asm
> > Erasing the Flash as expected!
> > #endasm
> > }
> >
> > void WriteFlash()
> > {
> > #asm
> > Writing the FLASH as expected!
> > #endasm
> > }
> >
> > When I downloaded and debug the application in RAM, it did
Erase
> > and Write the FLASH as I
> > needed.
> >
> > But the Problem occurs when I download and debug the
> application
> > in FLASH, it did not Erase and Write FLASH ROM as I expected !!!!
> >
> > Even when I unplug the Debug Cable, and let the application
run
> > freely, it did not Erase and WRite FLASH as I expected !!
> >
> > I don't know what is wrong with my methods !
> > Would you like to help me with it in details ???
> > Thank you and regards!
> >
> >
> > SiMitel
> > 13-8-2004 > ---------------------------------
> Yahoo! Groups Links
>
> To >
> ---------------------------------
>


Reply by gautham kotha August 14, 20042004-08-14

Ok simitel i am not sure whether i am right or wrong. The addressing concept may be different in flash memories paging and segmentaion comes into picture please refer with some note spare me if iam wrong. Writing a byte and erasing a byte my be same but loading a program may differs
Gautham

simitel0299 <s...@yahoo.com> wrote:
Why nobody help me?
Please, I want to know the answer.
Thank you for all your help and regards

               SiMitel--- In r...@yahoogroups.com, "simitel0299" <simitel0299@y...>
wrote:
> Dear all,
>     I am now using DC8.XX with Rabbit 3000 as CPU, and one 512KB
> FLASH, and 512KB SRAM on the board.
>
>     I programe an application which will store some data to FLASH.
I
> know I can write FLASH ROM by using WriteFlash or WriteFlash2 from
> Dynamic C. But I want to do this by myself !
>    
>     That is: I want to implement these functions by myself !
>     I did this in the following way.
>    
>     1. I define two char array which are in Data Segment, which are
> used to run the Erase Flash and Write FLash functions in RAM.
>
>     2. In the code, I copied the Erase and Write FLASH function to
> these char arrays, and setup stacks that these functions run in RAM
> can return back to the control flow in FLASH.
>
>     3. Call wrapper functions which ready the data to needed by
Erase
> and Write FLash Functions, and then the wrapper functions will Jump
> to the function(char array) to Programe FLASH.
>
>    The psuduo codes are as follows:
>      
> static unsigned char erasefunc[0x200], writefunc[0x200];
>
> void EraseWrapper()
> {
>  setup data needed by EraseFlash functions.
> ....
>  memcpy(erasefunc, EraseFlash, len);
>      
> #asm
>  :
>  :
>  calling erasefunc[]
>  :
>  :
> #endasm
> }
>
> void WriteWrapper()
> {
>  setup data needed by WriteFlash functions.
> ....
>  memcpy(writefunc, WriteFlash, len);
>      
> #asm
>  :
>  :
>  calling writefunc[]
>  :
>  :
> #endasm
> }
>
> void EraseFlash()
> {
> #asm
>  Erasing the Flash as expected!
> #endasm
> }
>
> void WriteFlash()
> {
> #asm
>  Writing the FLASH as expected!
> #endasm
> }
>
>   When I downloaded and debug the application in RAM, it did Erase
> and Write the FLASH as I
> needed.

>     But the Problem occurs when I download and debug the
application
> in FLASH, it did not Erase and Write FLASH ROM as I expected !!!!
>    
>     Even when I unplug the Debug Cable, and let the application run
> freely, it did not Erase and WRite FLASH as I expected !!
>
>     I don't know what is wrong with my methods !
>     Would you like to help me with it in details ???
>     Thank you and regards!
>    
>    
>                                  SiMitel
>                                  13-8-2004




Reply by simitel0299 August 14, 20042004-08-14
Why nobody help me?
Please, I want to know the answer.
Thank you for all your help and regards

SiMitel --- In rabbit-semi@rabb..., "simitel0299" <simitel0299@y...>
wrote:
> Dear all,
> I am now using DC8.XX with Rabbit 3000 as CPU, and one 512KB
> FLASH, and 512KB SRAM on the board.
>
> I programe an application which will store some data to FLASH.
I
> know I can write FLASH ROM by using WriteFlash or WriteFlash2 from
> Dynamic C. But I want to do this by myself !
>
> That is: I want to implement these functions by myself !
> I did this in the following way.
>
> 1. I define two char array which are in Data Segment, which are
> used to run the Erase Flash and Write FLash functions in RAM.
>
> 2. In the code, I copied the Erase and Write FLASH function to
> these char arrays, and setup stacks that these functions run in RAM
> can return back to the control flow in FLASH.
>
> 3. Call wrapper functions which ready the data to needed by
Erase
> and Write FLash Functions, and then the wrapper functions will Jump
> to the function(char array) to Programe FLASH.
>
> The psuduo codes are as follows:
>
> static unsigned char erasefunc[0x200], writefunc[0x200];
>
> void EraseWrapper()
> {
> setup data needed by EraseFlash functions.
> ....
> memcpy(erasefunc, EraseFlash, len);
>
> #asm
> :
> :
> calling erasefunc[]
> :
> :
> #endasm
> }
>
> void WriteWrapper()
> {
> setup data needed by WriteFlash functions.
> ....
> memcpy(writefunc, WriteFlash, len);
>
> #asm
> :
> :
> calling writefunc[]
> :
> :
> #endasm
> }
>
> void EraseFlash()
> {
> #asm
> Erasing the Flash as expected!
> #endasm
> }
>
> void WriteFlash()
> {
> #asm
> Writing the FLASH as expected!
> #endasm
> }
>
> When I downloaded and debug the application in RAM, it did Erase
> and Write the FLASH as I
> needed.
>
> But the Problem occurs when I download and debug the
application
> in FLASH, it did not Erase and Write FLASH ROM as I expected !!!!
>
> Even when I unplug the Debug Cable, and let the application run
> freely, it did not Erase and WRite FLASH as I expected !!
>
> I don't know what is wrong with my methods !
> Would you like to help me with it in details ???
> Thank you and regards! > SiMitel
> 13-8-2004




Reply by simitel0299 August 13, 20042004-08-13
Dear all,
I am now using DC8.XX with Rabbit 3000 as CPU, and one 512KB
FLASH, and 512KB SRAM on the board.

I programe an application which will store some data to FLASH. I
know I can write FLASH ROM by using WriteFlash or WriteFlash2 from
Dynamic C. But I want to do this by myself !

That is: I want to implement these functions by myself !
I did this in the following way.

1. I define two char array which are in Data Segment, which are
used to run the Erase Flash and Write FLash functions in RAM.

2. In the code, I copied the Erase and Write FLASH function to
these char arrays, and setup stacks that these functions run in RAM
can return back to the control flow in FLASH.

3. Call wrapper functions which ready the data to needed by Erase
and Write FLash Functions, and then the wrapper functions will Jump
to the function(char array) to Programe FLASH.

The psuduo codes are as follows:

static unsigned char erasefunc[0x200], writefunc[0x200];

void EraseWrapper()
{
setup data needed by EraseFlash functions.
....
memcpy(erasefunc, EraseFlash, len);

#asm
:
:
calling erasefunc[]
:
:
#endasm
}

void WriteWrapper()
{
setup data needed by WriteFlash functions.
....
memcpy(writefunc, WriteFlash, len);

#asm
:
:
calling writefunc[]
:
:
#endasm
}

void EraseFlash()
{
#asm
Erasing the Flash as expected!
#endasm
}

void WriteFlash()
{
#asm
Writing the FLASH as expected!
#endasm
}

When I downloaded and debug the application in RAM, it did Erase
and Write the FLASH as I
needed.

But the Problem occurs when I download and debug the application
in FLASH, it did not Erase and Write FLASH ROM as I expected !!!!

Even when I unplug the Debug Cable, and let the application run
freely, it did not Erase and WRite FLASH as I expected !!

I don't know what is wrong with my methods !
Would you like to help me with it in details ???
Thank you and regards! SiMitel
13-8-2004