DSPRelated.com
Forums

how to use the pointer to visit the data space in c54x

Started by Unknown April 5, 2005

i want to program flash using C,and the code as
follow:

void flash_write(unsigned int *pa,unsigned int pd) ;
void judge(unsigned int *pa)

void main(void)
{
/**************
initial routine
**************/
while (1)
{
flash_write((unsigned int *)0x8000,0x5555);
}
}

void flash_write(unsigned int *pa,unsigned int pd)
{

*(volatile unsigned *)0xd555=0xaa;
*(volatile unsigned *)0xaaaa=0x55;
*(volatile unsigned *)0xd555=0xa0;

*pa=pd;

judge(pa);
return;
}

void judge(unsigned int *pa)
{
unsigned int temp_1,temp_2;
do
{
temp_1=(*pa);
temp_2=(*pa);
temp_1=temp_1 & 0x40;
temp_2=temp_2 & 0x40;
}while(temp_1!=temp_2);
return;
}

but the result is wrong,i 'd wonder my pointer using
is right or not, i'm confused with the pointer.
3x
the deassembly code as follow:

0000:0449 main
0000:0449 EEFD FRAME -3
;initial routine
0000:045B 7600 ST #5555h,0h ;second parameter in 0h
0000:045D F6B8 RSBX SXM
0000:045E F274 CALLD flash_write
0000:0460 F020 LD #8000h,0,A ;first parameter in A
0000:0462 F073 B L1
0000:0464 flash_write
0000:0464 4A11 PSHM 11h
0000:0465 EEFE FRAME -2
0000:0466 F495 NOP
0000:0467 8000 STL A,0h ;it seems wrong ,A to 0h,
0000:0468 7711 STM 0d555h,11h
0000:046A 7681 ST #0aah,*AR1
0000:046C 7711 STM 0aaaah,11h
0000:046E 7681 ST #55h,*AR1
0000:0470 7711 STM 0d555h,11h
0000:0472 7681 ST #0a0h,*AR1
0000:0474 1004 LD 4h,A ;take second parameter from
04h,wrong position
0000:0475 7100 MVDK 0h,11h
0000:0477 8081 STL A,*AR1
0000:0478 1000 LD 0h,A
0000:0479 F074 CALL judge
0000:047B EE02 FRAME 2
0000:047C 8A11 POPM 11h
0000:047D FC00 RET
0000:047E judge
0000:047E 4A11 PSHM 11h
0000:047F EEFD FRAME -3
0000:0480 F495 NOP
0000:0481 8000 STL A,0h
0000:0482 L2
0000:0482 7100 MVDK 0h,11h
0000:0484 1081 LD *AR1,A
0000:0485 8001 STL A,1h
0000:0486 1081 LD *AR1,A
0000:0487 8002 STL A,2h
0000:0488 6801 ANDM 40h,1h
0000:048A 6802 ANDM 40h,2h
0000:048C 1001 LD 1h,A
0000:048D 0802 SUB 2h,A
0000:048E F844 BC L2,ANEQ
0000:0490 EE03 FRAME 3
0000:0491 8A11 POPM 11h
0000:0492 FC00 RET

what's the matter with my program,who can help me?
thanks