CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Addressmod issues

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

Addressmod issues
PostPosted: Wed Feb 15, 2012 9:01 am     Reply with quote

This is an interesting feature, but I am not sure whether it works as expected - any hint on what is the type of the "start_address" and "end_address" in the addressmod()?
Code:

addressmod (name,read_function,write_function,start_address,end_address);

My current understanding is it is an unsigned int32, as the r/w prototype functions use int32 as the address.
Code:

void read_function(int32 addr,int8 *ram, int nbytes){}


However, when the end_address is set bigger than 0xffff - to ie. 0x3ffff (my FRAM size) it does not provide any check, so you can define ie. an array of any size without getting an error.. So it seems it provides a check on available size ie array's size up to 0xffff only (int16 type??).
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 10:47 am     Reply with quote

It depends on your processor.
The maximum range of memory that can be handled via addressmod, is limited to what can be handled by the memory type used to address the RAM, less the RAM the processor already has. So if (for instance) you have #device *=16 (the largest size supported on normal PICs), the range of addresses available must fit into an int16 range, less whatever RAM the processor already has.
The whole 'point' is to make an external memory behave as if it is part of the RAM of the processor, so the available address range is limited to what the processor could potentially support.
Realistically, if you need more than 64K for variable storage, look at a different processor family. If you don't need it to be accessible through named variables, treat it as a data store, and don't use addressmod.

Best Wishes
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 12:00 pm     Reply with quote

Ttelmah wrote:
It depends on your processor.

Well, for example pic24hj128gp502. The datasheet says "The program counter (PC) is 23bits wide and addresses up to 4Mx24 bits of user program memory space. The data space can be linearly addressed as 32K words or 64 Kbytes using an Address Generation Unit (AGU). The upper 32 Kbytes of the data space memory map can optionally be mapped into program space at any 16K program word boundary defined by the 8-bit Program Space Visibility Page (PSVPAG) register. The program to data space mapping feature lets any instruction access program space as if it were data space." Rolling Eyes
How to apply that to the addressmod then?
I still have problems with mixing variables and arrays in the addressmod space of that mcu, so the first step would be to understand how it actualy works Sad
Is that "start_address" and "end_address" in the addressmod() related to the actual mcu data space or to external memory device data space?
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 2:06 pm     Reply with quote

The data space of my FRAM is 0x00000-0x3FFFF (256kByte)

addressmod (FRAM, fram_read_function, fram_write_function, 0x0000, 0x3ffff);

I am writing the FRAM with random data and reading back and comparing the data with the same sequence of random data. These are the results - all are without an error (tick=1ms, v4.128).

FRAM unsigned int8 buffer[200000];
ELAPSED TICKS_rd&comp= 1942

FRAM unsigned int16 buffer[100000];
ELAPSED TICKS_rd&comp= 1141

FRAM unsigned int32 buffer[50000];
ELAPSED TICKS_rd&comp= 734

FRAM unsigned int64 buffer[25000];
ELAPSED TICKS_rd&comp= 526

So it seems to me the addressmod can handle large data spaces (>64kB).

However, I cannot mix the above array with variables (a mcu crash) in the FRAM space.

And, for example:

FRAM unsigned int64 buffer[X];

X=999 ok
X=1000 crashes the mcu
X=1001 crashes the mcu
X=1002 compiler complains: Not enough RAM for all variables
X=1003 crashes the mcu
X=1050 ok
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 3:52 pm     Reply with quote

OK.
On the PIC 24, yes, you can address larger sizes, _but_ you will find people having problems, with large and complex structures, even when they are in the main memory, and not mapped via addressmod.
There are hidden limits in the CCS code, with numbers of variables in a structure, arrays of structures exceeding sizes used in parts of the arithmetic, and developing overflow problems, etc. etc..

I'd really say you are hundreds of times 'safer', to not use addressmod, and instead treat such an array in FRAM, as a linear data file, with you retrieving the required index yourself, rather than trying to let CCS handle it.

Historically the old problem of the stack not being large enough will also hit even worse with addressmod. The compiler uses a large lump of stack space which seems to be the size of the entity you transfer using addressmod, so your stack size needs to be increased to (say) 512+sizeof(largest addresmod variable), if you are not going to hit problems from this....

Best Wishes
miro



Joined: 15 Jan 2011
Posts: 62

View user's profile Send private message

PostPosted: Wed Feb 15, 2012 4:24 pm     Reply with quote

I've tried #build(stack=2000) but it does not help much. The mixing vars and arrays in FRAM space does not work at least in my code. It would be great if the guys will fix that and provide more info how it works and how to use it, though.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group