Forum: Mikrocontroller und Digitale Elektronik C pointer Problem : different mspace


von noxrox (Gast)


Lesenswert?

Hallo
beim Versuch ein Codebesispiel zu compilieren sagt mir der kompiler
folgendes :

MMC_DATALOGGER.C(1227): warning C259: '=': pointer: different mspace
dies betrifft folgende funktion:
1
void MMC_FLASH_Init (void);            // Initializes MMC and configures it to 
2
                                       // accept SPI commands;
3
4
                                       // Reads <length> bytes starting at 
5
                                       // <address> and stores them at <pchar>;
6
unsigned char MMC_FLASH_Read (unsigned long address, unsigned char *pchar,
7
                         unsigned int length);
8
9
                                       // Clears <length> bytes starting at 
10
                                       // <address>; uses memory at <scratch>
11
                                       // for temporary storage;
12
unsigned char MMC_FLASH_Clear (unsigned long address, unsigned char *scratch,
13
                          unsigned int length);
14
15
                                       // Writes <length> bytes of data at
16
                                       // <wdata> to <address> in MMC;
17
                                       // <scratch> provides temporary storage;
18
unsigned char MMC_FLASH_Write (unsigned long address, unsigned char *scratch,
19
                          unsigned char *wdata, unsigned int length);
20
21
                                       // Clears <length> bytes of FLASH 
22
                                       // starting at <address1>; Requires that
23
                                       // desired erase area be sector aligned;
24
unsigned char MMC_FLASH_MassErase (unsigned long address1, 
25
                                   unsigned long length);

und zwar an dieser stelle mit @ gekennzeichnet
1
unsigned char MMC_FLASH_Clear (unsigned long address, unsigned char *scratch,
2
                          unsigned int length)
3
{
4
   idata unsigned long flash_page_1;   // Stores address of first FLASH page;
5
   idata unsigned long flash_page_2;   // Stores address of second FLASH page;
6
   idata unsigned int card_status;     // Stores MMC status after each MMC
7
                                       // command;
8
   idata unsigned int counter;         // Counter for clearing bytes in local
9
                                       // block copy;
10
   unsigned char xdata *index;         // Index into local block used for 
11
                                       // clearing desired data;
12
   if(length > 512) return 0;          // Test desired clear length;  If 
13
                                       // length > 512, break out and return
14
                                       // zero;
15
                                       // Calculate first FLASH page address;
16
   flash_page_1 = address & ~(PHYSICAL_BLOCK_SIZE-1);
17
                                       // Calculate second FLASH page address;
18
   flash_page_2 = (address+length-1) & ~(PHYSICAL_BLOCK_SIZE-1);
19
   if(flash_page_1 == flash_page_2)    // Clear space all in one FLASH block
20
   {                                   // condition;
21
                                       // Read first FLASH block;
22
      card_status = MMC_Command_Exec(SET_BLOCKLEN,
23
                                 (unsigned long)PHYSICAL_BLOCK_SIZE,
24
                                 EMPTY);
25
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_1,scratch);
26
                                       // Set index to address of area to clear
27
                                       // in local block;
28
    @@  index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE) + scratch;
29
      counter = 0;
30
      while(counter<length)            // Clear desired area in local block;
31
      {
32
         *index++ = 0x00;
33
         counter++;
34
      }
35
                                       // Tag first FLASH page for erase;
36
      card_status = MMC_Command_Exec(TAG_SECTOR_START,flash_page_1,EMPTY);
37
      card_status = MMC_Command_Exec(TAG_SECTOR_END,flash_page_1,EMPTY);
38
                                       // Erase first FLASH page;
39
      card_status = MMC_Command_Exec(ERASE,EMPTY,EMPTY);
40
                                       // Write local copy of block back out
41
                                       // to MMC;
42
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_1,scratch);
43
   }
44
   else                                // Clear space crosses FLASH block
45
   {                                   // boundaries condition;
46
                                       // Follow same procedure as for single
47
                                       // block case above;  Read first block
48
                                       // clear data from start address to end
49
                                       // of block;  Erase block in FLASH;
50
                                       // Write local copy back out;
51
      card_status = MMC_Command_Exec(SET_BLOCKLEN,
52
                                 (unsigned long)PHYSICAL_BLOCK_SIZE,
53
                                 EMPTY);
54
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_1,scratch);
55
   @@   index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE) + scratch;
56
      counter = (unsigned int)(flash_page_2 - address);
57
      while(counter > 0)
58
      {
59
         *index++ = 0xFF;
60
         counter--;
61
      }
62
      card_status = MMC_Command_Exec(TAG_SECTOR_END,flash_page_1,EMPTY);
63
      card_status = MMC_Command_Exec(ERASE,EMPTY,EMPTY);
64
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_1,scratch);
65
                                       // Same process as above, but using
66
                                       // second FLASH block;  Area to be
67
                                       // cleared extends from beginning of
68
                                       // second FLASH block to end of desired
69
                                       // clear area;
70
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_2,scratch);
71
   @@   index = scratch;
72
      counter = (unsigned int)(length - (flash_page_2 - address));
73
      while(counter > 0)
74
      {
75
         *index++ = 0xFF;
76
         counter--;
77
      }
78
      card_status = MMC_Command_Exec(TAG_SECTOR_END,flash_page_2,EMPTY);
79
      card_status = MMC_Command_Exec(ERASE,EMPTY,EMPTY);
80
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_2,scratch);
81
   }
82
}
für die hilfe vielen dank im voraus
von Joachim D. (Firma: JDCC) (scheppertreiber)


Lesenswert?

"index" ist als Pointer definiert. Du weist ihm einen "unsigned int"
 zu, das geht halt nicht ... (erste Fundstelle).

index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE) + scratch;

Klammer falsch gesetzt ?

index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE + scratch);
von noxrox (Gast)


Lesenswert?

Super danke schön, habe die klammern korriegiert, jetzt sieht es so aus
1
unsigned char MMC_FLASH_Write (unsigned long address, unsigned char *scratch,
2
                          unsigned char *wdata, unsigned int length)
3
{
4
   idata unsigned long flash_page_1;   // First FLASH page address;
5
   idata unsigned long flash_page_2;   // Second FLASH page address;
6
   idata unsigned int card_status;     // Stores status returned from MMC;
7
   idata unsigned int counter;         // Byte counter used for writes to 
8
                                       // local copy of data block;
9
   unsigned char xdata *index;         // Pointer into local copy of data
10
                                       // block, used during modification;
11
   MMC_FLASH_Clear(address,scratch,length); // Clear desired write space;
12
   if(length > 512) return 0;          // Check for valid data length;
13
                                       // Calculate first FLASH page address;
14
   flash_page_1 = address & ~(PHYSICAL_BLOCK_SIZE-1);
15
                                       // Calculate second FLASH page address;
16
   flash_page_2 = (address+length-1) & ~(PHYSICAL_BLOCK_SIZE-1);
17
   if(flash_page_1 == flash_page_2)    // Handle single FLASH block condition;
18
   {
19
                                       // Set block length to default block
20
                                       // size (512 bytes);
21
      card_status = MMC_Command_Exec(SET_BLOCKLEN,
22
                                 (unsigned long)PHYSICAL_BLOCK_SIZE,
23
                                 EMPTY);
24
                                       // Read data block;
25
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_1,scratch);
26
      index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE + scratch);
27
      counter = 0;
28
      while(counter<length)            // Modify write space in local copy;
29
      {
30
         *index++ = *wdata++;
31
         counter++;
32
      }
33
                                       // Write modified block back to MMC;
34
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_1,scratch);
35
   }
36
   else                                // Handle multiple FLASH block 
37
   {                                   // condition;
38
                                       // Set block length to default block
39
                                       // size (512 bytes);
40
      card_status = MMC_Command_Exec(SET_BLOCKLEN,
41
                                 (unsigned long)PHYSICAL_BLOCK_SIZE,
42
                                 EMPTY);
43
                                       // Read first data block;
44
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_1,scratch);
45
      index = (unsigned int)(address % PHYSICAL_BLOCK_SIZE + scratch);
46
      counter = (unsigned int)(flash_page_2 - address);
47
      while(counter > 0)               // Modify data in local copy of first
48
      {                                // block;
49
         *index++ = *wdata++;
50
         counter--;
51
      }
52
                                       // Write local copy back to MMC;
53
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_1,scratch);
54
                                       // Read second data block;
55
      card_status = MMC_Command_Exec(READ_SINGLE_BLOCK,flash_page_2,scratch);
56
 @@@     index = scratch;
57
      counter = (unsigned int)(length - (flash_page_2 - address));
58
      while(counter > 0)               // Modify data in local copy of second
59
      {                                // block;
60
         *index++ = *wdata++;
61
         counter--;
62
      }
63
                                       // Write local copy back to MMC;
64
      card_status = MMC_Command_Exec(WRITE_BLOCK,flash_page_2,scratch);
65
   }
66
}

an der stelle meckert der compiler aber imer noch.??
von Joachim D. (Firma: JDCC) (scheppertreiber)


Lesenswert?

Na denk mal nach :-)))

Wie sind die Dinger definiert ?
von noxrox (Gast)


Lesenswert?

als unsigned char
von noxrox (Gast)


Lesenswert?

sorry, ich verstehe es leider nicht ganz. worüber meckert der kompiler 
denn nun.
von dunno.. (Gast)


Lesenswert?

schon unsigned char, aber index liegt scheinbar in xdata...
würde den "different mspace" meiner meinung nach erklären.....
von noxrox (Gast)


Lesenswert?

wie wäre es dann richtig, wundere mich dass der code nicht sofort 
funktioniert ist schließlich n codebsp von Silabs.
Könnte mir jemand bitte explizit sagen was ich und warum ändern 
muss.Bedanke mich im voraus.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.