Avr: PROGMEM, PSTR i struktura

Witam.

Chce zrobić coś takiego:

struct Data { const char *foo; unsigned char a; };

Data PROGMEM data = { PSTR("Coś"), 4 };

Oczywiscie nie mogę, bo PSTR to jest "__extension__" i można tego używać chyba tylko jako argumentu funkcji: " statement-expressions are not allowed outside functions nor in template-argument lists"

W kazdym razie padłem na tym że nie mam jak zainicjować statycznej const struktury. Chciałbym ja inicjować dokladnie tak jak to widać, tzn w miejscu.

Tak też się nie da:

const char PROGMEM *z = "Inne";

Data PROGMEM data2 = { z, 8 };

Wylatuje z: "error: data2 causes a section type conflict"

Zamiana z const char* na PGM_P tez nic nie pomaga. Co jeszcze powinienem sprawdzić?

WinAVR-20100110.

Reply to
Sebastian Biały
Loading thread data ...

W dniu 2011-08-08 00:38, Sebastian Biały pisze:

I jest to nawet opisane w FAQ:

formatting link

U siebie stosuję coś takiego:

static const prog_char cmd_sin_rgb_fast[] = "$sin_rgb_fast#"; [...]

struct{ const prog_char * cmd; uint8_t len; uint8_t mode; }static const PROGMEM cmd_tab[] = { {cmd_sin_rgb_fast, sizeof(cmd_sin_rgb_fast) - 1, mode_sin_rgb_fast}, [...] };

i działa.

Reply to
Zbych

Take the red pill, Sebastian Biały...

Spróbuj tak :

#v+ #include <avr/pgmspace.h> typedef struct{ const char * foo; unsigned char a; } Data;

const char const string1[] PROGMEM = "foo.shmoo";

const Data const data PROGMEM = { string1 , 7 };

int main() { // ... return 0; } #v-

00000026 <string1>: 26: 66 6f 6f 2e 73 68 6d 6f 6f 00 foo.shmoo. 00000031 <data>: 31: 26 00 07 &..

Sławek

Reply to
Sławomir Szczyrba

A miało być tak pięknie:

formatting link
Co się stało z tym pomysłem? gcc miało coś implementować.

Reply to
Sebastian Biały

Niby ma przestrzenie adresowe i są jakieś próby z avr:

formatting link
formatting link

Reply to
Zbych

Trochę strzelam, bo nie mam teraz jak sprawdzić, ale czy nie zadziała po prostu: Data PROGMEM data = {"Coś" , 4}; ??

Reply to
Konop

Nie, "coś" ląduje w RAM zamiast Flash. We Flash znajdzie się tylko sama struktura z pointerem.

Reply to
Sebastian Biały

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.