miro
Joined: 15 Jan 2011 Posts: 62
|
Addressmod problem v5.009 |
Posted: Sun Jul 14, 2013 5:05 am |
|
|
Hi, still the issue with addressmod. See below the code and its disassembly.
"fram_wr()" has not been compiled, both reading/writing functions point to "fram_rd()" (see at the address 0x206).
Code: | #include <33FJ128GP802.h>
#device *=16
#device ADC=12
//dummy SPI
unsigned int16 spi_x( unsigned int16 data_out)
{
return (data_out);
}
// read procedure for reading n bytes from the memory starting at location addr
void fram_rd(unsigned int32 address, unsigned int8 *dat, unsigned int nbytes)
{
// write opcode, address
spi_x(22);
spi_x(address>>16);
spi_x(address>>8);
spi_x(address);
while (nbytes--) *dat++ = spi_x(0xAA);
}
//write procedure for writing n bytes to the memory starting at location addr
void fram_wr(unsigned int32 address, unsigned int8 *dat, unsigned int nbytes)
{
// write opcode, address, data
spi_x(33);
spi_x(address>>16);
spi_x(address>>8);
spi_x(address);
while (nbytes--) spi_x( *dat++ );
}
addressmod (FRAM, fram_rd, fram_wr, 0x0000, 0x0fff);
FRAM int16 sector[512];
volatile unsigned int dummy, i;
void main()
{
setup_oscillator( OSC_INTERNAL, 79872000);
#use delay(clock = 79872000)
for (i=0; i<512; i++)
{
sector[i] = i;
}
for (i=0; i<512; i++)
{
dummy = sector[i];
}
delay_ms(200);
}
|
And the disassembly:
Code: | 1: #include <33FJ128GP802.h>
00000 040266 goto 0x000266
2:
3: #device *=16
4: #device ADC=12
5:
6: //dummy SPI
7: unsigned int16 spi_x( unsigned int16 data_out)
8: {
9: return (data_out);
00200 F8081A push.w 0x081a
00202 F90000 pop.w 0x0000
00204 060000 return
10: }
11:
12: // read procedure for reading n bytes from the memory starting at location addr
13: void fram_rd(unsigned int32 address, unsigned int8 *dat, unsigned int nbytes)
00206 781F85 mov.w 0x000a,[0x001e++]
14: {
15: // write opcode, address
16: spi_x(22);
00208 200164 mov.w #0x16,0x0008
0020A 8840D4 mov.w 0x0008,0x081a
0020C 020200 call 0x000200
17: spi_x(address>>16);
00210 804055 mov.w 0x080a,0x000a
00212 8840D5 mov.w 0x000a,0x081a
00214 020200 call 0x000200
18: spi_x(address>>8);
00218 BFC809 mov.b 0x0809,0x0000
0021A 784280 mov.b 0x0000,0x000a
0021C BFC80A mov.b 0x080a,0x0000
0021E B7E00B mov.b 0x0000,0x000b
00220 8840D5 mov.w 0x000a,0x081a
00222 020200 call 0x000200
19: spi_x(address);
00226 804045 mov.w 0x0808,0x000a
00228 8840D5 mov.w 0x000a,0x081a
0022A 020200 call 0x000200
20: while (nbytes--) *dat++ = spi_x(0xAA);
0022E BF880E mov.w 0x080e,0x0000
00230 ED280E dec.w 0x080e
00232 E00000 cp0.w 0x0000
00234 32000A bra z, 0x00024a
00236 BF880C mov.w 0x080c,0x0000
00238 EC280C inc.w 0x080c
0023A 780280 mov.w 0x0000,0x000a
0023C 200AA4 mov.w #0xaa,0x0008
0023E 8840D4 mov.w 0x0008,0x081a
00240 020200 call 0x000200
00244 784A80 mov.b 0x0000,[0x000a]
00246 04022E goto 0x00022e
0024A 7802CF mov.w [--0x001e],0x000a
0024C 060000 return
21: }
22:
23: //write procedure for writing n bytes to the memory starting at location addr
24: void fram_wr(unsigned int32 address, unsigned int8 *dat, unsigned int nbytes)
25: {
26: // write opcode, address, data
27: spi_x(33);
28: spi_x(address>>16);
29: spi_x(address>>8);
30: spi_x(address);
31: while (nbytes--) spi_x( *dat++ );
32: }
33:
34: addressmod (FRAM, fram_rd, fram_wr, 0x0000, 0x0fff);
35:
36: FRAM int16 sector[512];
37:
38: volatile unsigned int dummy, i;
39:
40: void main()
00266 A8E081 bset.b 0x0081,#7
00268 EFA32C setm.w 0x032c
0026A 23F80F mov.w #0x3f80,0x001e
0026C 23FFF0 mov.w #0x3fff,0x0000
0026E B7A020 mov.w 0x0000,0x0020
00270 000000 nop
00272 23F80F mov.w #0x3f80,0x001e
00274 23FFF0 mov.w #0x3fff,0x0000
00276 B7A020 mov.w 0x0000,0x0020
00278 000000 nop
41: {
42:
43: setup_oscillator( OSC_INTERNAL, 79872000);
0027A 200014 mov.w #0x1,0x0008
0027C 883A24 mov.w 0x0008,0x0744
0027E 2003F4 mov.w #0x3f,0x0008
00280 883A34 mov.w 0x0008,0x0746
44: #use delay(clock = 79872000)
0024E E00000 cp0.w 0x0000
00250 AF2042 btsc.b 0x0042,#1
00252 370008 bra 0x000264
00254 091BFB repeat #7163
00256 000000 nop
00258 093FFE repeat #16382
0025A 000000 nop
0025C 093FFE repeat #16382
0025E 000000 nop
00260 E90000 dec.w 0x0000,0x0000
00262 3AFFF8 bra nz, 0x000254
00264 060000 return
45:
46: for (i=0; i<512; i++)
00282 EF2802 clr.w 0x0802
00284 804014 mov.w 0x0802,0x0008
00286 202003 mov.w #0x200,0x0006
00288 E11804 cp.w 0x0006,0x0008
0028A 36000F bra leu, 0x0002aa
47: {
48: sector[i] = i;
0028C BF8802 mov.w 0x0802,0x0000
0028E DD0041 sl 0x0000,#1,0x0000
00290 780280 mov.w 0x0000,0x000a
00292 4282E0 add.w 0x000a,#0,0x000a
00294 884045 mov.w 0x000a,0x0808
00296 EF280A clr.w 0x080a
00298 208024 mov.w #0x802,0x0008
0029A 884064 mov.w 0x0008,0x080c
0029C 200044 mov.w #0x4,0x0008
0029E 884074 mov.w 0x0008,0x080e
002A0 020206 call 0x000206 <<<<< fram_rd() SHOULD BE fram_wr()
002A4 EC2802 inc.w 0x0802
002A6 040284 goto 0x000284
49: }
50:
51: for (i=0; i<512; i++)
002AA EF2802 clr.w 0x0802
002AC 804014 mov.w 0x0802,0x0008
002AE 202003 mov.w #0x200,0x0006
002B0 E11804 cp.w 0x0006,0x0008
002B2 36000F bra leu, 0x0002d2
52: {
53: dummy = sector[i];
002B4 BF8802 mov.w 0x0802,0x0000
002B6 DD0041 sl 0x0000,#1,0x0000
002B8 400060 add.w 0x0000,#0,0x0000
002BA 780280 mov.w 0x0000,0x000a
002BC 884045 mov.w 0x000a,0x0808
002BE EF280A clr.w 0x080a
002C0 208004 mov.w #0x800,0x0008
002C2 884064 mov.w 0x0008,0x080c
002C4 200024 mov.w #0x2,0x0008
002C6 884074 mov.w 0x0008,0x080e
002C8 020206 call 0x000206 <<< fram_rd()
002CC EC2802 inc.w 0x0802
002CE 0402AC goto 0x0002ac
54: }
55:
56: delay_ms(200);
002D2 200C80 mov.w #0xc8,0x0000
002D4 02024E call 0x00024e
002D8 FE4000 pwrsav #0 |
|
|