Jump to content
ELFORUM - Forumul Electronistilor
Sign in to follow this  
mitescu

Compilator pentru AVR, cu pointer pe 24(32) biti???

Recommended Posts

Compilatoarele care le utilizez(CAVR,Avr_gcc...AVRStudio..) pentru AVR-uri utilizeaza pointer pe 16 biti. Prin urmare, nu se poate adresa DIRECT decat 64K de RAM. Si acum intrebarea: Exista un complilator pentru AVR-uri pe 8 biti si care poate adresa DIRECT o capacitate RAM mai mare decat 64k. ( ex. cazul ATXMega128A1U)????

Share this post


Link to post
Share on other sites

Salut,

m-ai facut curios, asa ca am cautat si eu putin si am inteles ca avr-gcc ar trebui sa mearga daca folosesti __memx ca tip pentru variabile.

6.16.1 AVR Named Address Spaces

 

On the AVR target, there are several address spaces that can be used in order to put read-only data into the flash memory and access that data by means of the special instructions LPM or ELPM needed to read from flash.

 

Per default, any data including read-only data is located in RAM (the generic address space) so that non-generic address spaces are needed to locate read-only data in flash memory and to generate the right instructions to access this data without using (inline) assembler code.

 

__flash

The __flash qualifier locates data in the .progmem.data section. Data is read using the LPM instruction. Pointers to this address space are 16 bits wide.

__flash1

__flash2

__flash3

__flash4

__flash5

These are 16-bit address spaces locating data in section .progmemN.data where N refers to address space __flashN. The compiler sets the RAMPZ segment register appropriately before reading data by means of the ELPM instruction.

__memx

This is a 24-bit address space that linearizes flash and RAM: If the high bit of the address is set, data is read from RAM using the lower two bytes as RAM address. If the high bit of the address is clear, data is read from flash with RAMPZ set according to the high byte of the address. See __builtin_avr_flash_segment.

Objects in this address space are located in .progmemx.data.

 

Example

 

char my_read (const __flash char ** p)

{

/* p is a pointer to RAM that points to a pointer to flash.

The first indirection of p reads that flash pointer

from RAM and the second indirection reads a char from this

flash address. */

 

return **p;

}

 

/* Locate array[] in flash memory */

const __flash int array[] = { 3, 5, 7, 11, 13, 17, 19 };

 

int i = 1;

 

int main (void)

{

/* Return 17 by reading from flash memory */

return array[array];

}

For each named address space supported by avr-gcc there is an equally named but uppercase built-in macro defined. The purpose is to facilitate testing if respective address space support is available or not:

 

#ifdef __FLASH

const __flash int var = 1;

 

int read_var (void)

{

return var;

}

#else

#include /* From AVR-LibC */

 

const int var PROGMEM = 1;

 

int read_var (void)

{

return (int) pgm_read_word (&var);

}

#endif /* __FLASH */

Notice that attribute progmem locates data in flash but accesses to these data read from generic address space, i.e. from RAM, so that you need special accessors like pgm_read_byte from AVR-LibC together with attribute progmem.

 

Limitations and caveats

 

Reading across the 64 KiB section boundary of the __flash or __flashN address spaces shows undefined behavior. The only address space that supports reading across the 64 KiB flash segment boundaries is __memx.

If you use one of the __flashN address spaces you must arrange your linker script to locate the .progmemN.data sections according to your needs.

Any data or pointers to the non-generic address spaces must be qualified as const, i.e. as read-only data. This still applies if the data in one of these address spaces like software version number or calibration lookup table are intended to be changed after load time by, say, a boot loader. In this case the right qualification is const volatile so that the compiler must not optimize away known values or insert them as immediates into operands of instructions.

The following code initializes a variable pfoo located in static storage with a 24-bit address:

extern const __memx char foo;

const __memx void *pfoo = &foo;

Such code requires at least binutils 2.23, see PR13503.

 

Share this post


Link to post
Share on other sites

"__memx" , in acest caz se refera la citirea constantelor din FLASH(din spatiul ce depaseste 64K). intrebarea mea se referea la RAM.

De exemplu am o configuratie a lui atxmega128a1 cu 512K de RAM. Intrebarea care o puneam este legata de accesul DIRECT la intreaga arie de memorie, fara a scrie o functie speciala, in care sa initializez (de ex.) registrul RAMPx (ptr instructiuni de genul LD R4,X)...

Share this post


Link to post
Share on other sites

Aha, sorry, cred ca am inteles gresit.Intrebare de nepriceput: aia 512K RAM sunt externi? Ca am crezut ca te referi la memoria interna a controllerului.Cel mai simplu ar fi sa folosesti un controller pe 32 de biti (ARM), nu?

Share this post


Link to post
Share on other sites

Da, 512K de RAM , este extern(xmega128a1 poate adresa pana la 16M de ram extern, 512k daca este sram)Ideea cu MC de 32 biti: tocmai asta este ideea sa NU utilizez decat xmega128a1

Share this post


Link to post
Share on other sites

Interesant, intr-adevar GCC nu stie sa adreseze direct variabilele din spatiul de memorie extins. O prima banuiala ar fi fost ca IAR Workbench ar putea fi capabil sa adreseze intreaga zona de memorie, dar aparent nu am gasit o confirmare pe net.Iar acum o intrebare de profan: te-ar putea ajuta controllerul de DMA sa plimbi valorile de la o anumita adresa (in blocuri de cat ai nevoie) in niste buffere pentru o prelucrare ulterioara in cazul aplicatiei tale sau aceasta solutie nu se preteaza?

Share this post


Link to post
Share on other sites

Este buna ideea cu DMA-ul , dar pentru ce-mi trebuie , nu se prea poate aplica. Datele din spatiul "extins" trebuiesc prelucrate individual. Ar fi o "pierdere de timp" sa utilizez dma. Asa imi scriu propria functie de citire din spatiul extins...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.