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 support@ccsinfo.com

Virtual RAM Help

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



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

Virtual RAM Help
PostPosted: Thu Dec 26, 2013 12:22 am     Reply with quote

CCS C 4:130

Ok, here is a pretty much out there idea... now please note:
* SSD1963 is 800x480 24bit colour LCD (i've set it to use 16bit colours only).
NOW this leaves about 400 KBytes to play with.

I've mapped the memory by a simple function, basically I'm drawing pixels OFF the screen (can't see it and it works!).
Since it is 16bit I'm losing 8bits per pixel (memory cell) which to be fair no worries for now.

Now what i want to do is figure out a way to make my MCU "POINT" to the "External ram"

Right as you know

Code:

typedef struct {
 int8 x,y,z;
} datainf;

datainf demo[2];



NOW as you know this allocates a location in the MCU rams, for 2 of demos

demo[0].x = 0; and so forth.. but make a few of these and you run out of ram..

I don't know how to approach this really as i do want to use the cpu's ram for registers only and allow to use 400 Kb for regular variables and lists...

I am considering an array of memory locations and sizes eg.

Code:

typedef struct {
  int32 alloc;
  int16 size;
} memoryinf;

memoryinf variables[800];



and so there for would do something like

variables[0].size = sizeof(datainf) * 8; // expect 8 arrays
variables[0].alloc = ext_malloc(variables[0].size); // find a location in ram that will work with this.


as you can imagine though, variables[0..800]; it soaks up ram!??

any input at this point would be awesome!

Thank you guys in advance.


(the project WILL load files into the FAKE RAM and run and show and play back the data from these areas...)
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 26, 2013 6:36 am     Reply with quote

comment: It sounds like you want to use the LCD modules RAM for data storage for the progam. That isn't a big deal.The LCD datasheet should have a 'memory map' or table describing how to access it.Even the common 2x16 LCD units have that! Writing to non-display memory locations saves the data, it just doesn't get displayed and if enabled, you can read back the LCD ram data. I imagine the LCD memory may be setup as 'blocks' or 'pages' so that several 'screens' or data can be quickly accessed and displayed.PC video cards do this making for fast access even when using QBASIC4.5 so it should be doable. The 'trick' is to read the datasheet,figure out the locations of 'displayable RAM' vs 'hidden RAM', code the algorithms to access it,try with KNOWN data,recode as required,retest,etc.Speed might be an issue depending on how you want to use the 'vitrual RAM' within your program and only testing will tell.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu Dec 26, 2013 8:04 am     Reply with quote

What you seem to want is addressmod.

This allows the CPU to access variables stored in external memory.

Problem is that while it was working a few compilers ago, it has been broken for the last few - for few, read 'large number' - compilers.

It is one of those 'brilliant' features, that CCS need to get working....

Best Wishes
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 26, 2013 5:56 pm     Reply with quote

@Ttelmah : Thanks for the info, i didn't know CCS had an external Variable stuff as that would have made things so very simply. Hope they fix it soon, but is there anyone that may have written some sort of algorithm.

@temtronic : I'm aware of the ram available, what I'm after is code to make USE of the ram in terms of CPU pointers, and variables.

Is the code still available for making use of External memory ? not just using ext_write(address,value); I'm talking about making it work using real declarations.

??
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 26, 2013 8:55 pm     Reply with quote

i run 4.130, was the addressmod function broken after this? or before? i can only go back to 4.114

ok seems to be ok ;

problem is, the addressmod doesn't work all that great with strcpy :(
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 27, 2013 3:01 pm     Reply with quote

addressmod its precicly what i needed!!! THANK YOU !!!

only issue i have is how to use malloc with it too? it works but it didn't seem to work beyond the pics physical ram

sooo need a way around this too
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Fri Dec 27, 2013 3:25 pm     Reply with quote

You really really really should avoid using malloc or any dynamic memory. The PIC really isn't suited for that typically. There is almost never a need to use it.
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 27, 2013 7:17 pm     Reply with quote

There is about 256Kb available to me (after altering the addressmod thing) - so messing about with static memory is ok, just seems extremely wasteful.

I'm thinking writing my own malloc system, be a bit slower, BUT why not Smile
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Fri Dec 27, 2013 7:33 pm     Reply with quote

Dynamic memory is going to be both more wasteful (on average) and slower than static. With Dynamic Memory, a memory pool will need to be allocated as well resources to manage it. Both of those waste memory that could be used for other things.

I'll agree it is a fun thing to do if you are making your own memory management module (I use to play around making virtual functions for structures in CCS...virtual table and all, so I understand the fun factor), but it usually isn't a good idea for anything commercial grade.
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 27, 2013 8:26 pm     Reply with quote

BOOO... oh well

ok I'm still having issues though

for some reason,

vram int16 test;

test=50;

sprintf (txt, "%lu", test);

this doesn't work, it says not a valid format! lol is the addressmod only able to use Signed stuff? as its screwed up alot of my code :(

scratched away the malloc stuff though, no need for it i guess then
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Sat Dec 28, 2013 10:47 am     Reply with quote

might be a compiler bug for your version. I just tried in 5.010 and it compiled fine. Try swapping the order VRAM and int16 around in front of test.

EDIT: however, in version 5.010 addressmod itself doesn't work properly. I emailed a bug report to CCS support the other day, but christmas season, so probably won't hear from them for a bit.
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Sat Dec 28, 2013 11:24 am     Reply with quote

i dont have 5.010 to be honest, 4.130 is the best one that worked for me, and i DID find that addressmod appears to be really in favour of SIGNED values!

even structs, i found that

typedef struct {
int16 x,y,z;
int8 a,b,c;
} test;

this was all messed up, it didn't work until i made a,b,c all 16bit

looks like the struct is widened up to the largest number?

and pointers are messy but they do work now!

THANK YOU



EDIT:: i cant seem to use strcpy(txt, "HELLO WORLD")

eg,
FakeRAM char txt[32];

strcpy(txt, "hello");

doesnt seem to work either

i have to run a loop to insert them from a text from a real string!
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 01, 2014 9:03 pm     Reply with quote

Sorry another question, i cant seem to find any infomation about addressmod limitations

i realise that the addressmod it self can only address up to 64kb or something like (seems to be able to for me right now) but i need more memory

can i use multiple addressmods?

Code:


void write_ram(int32 addr, char data){
   Address_set(addr, ram_y_offset, addr, ram_y_offset);      // area to grab   LCD_WR_DATA(data); 
   LCD_WR_DATA(data);
}




int8 read_ram(unsigned int32 addr){
   Address_set(addr, ram_y_offset, addr, ram_y_offset);      // area to grab
   LCD_WR_REG(CMD_RD_MEMSTART);// Time to read from Screen area
   return Read_Datafast();
}


void write_ram2(int32 addr, char data){
   Address_set(addr, ram_y_offset + page2, addr, ram_y_offset);      // area to grab   LCD_WR_DATA(data); 
   LCD_WR_DATA(data);
}




int8 read_ram2(unsigned int32 addr){
   Address_set(addr, ram_y_offset, addr, ram_y_offset);      // area to grab
   LCD_WR_REG(CMD_RD_MEMSTART);// Time to read from Screen area
   return Read_Datafast();
}




void ram_read(unsigned int32 addr,int8 *ram, int8 nbytes){
   int i;   

   //nbytes=2;
   for(i=0;i<nbytes;i++,ram++,addr++)
      *ram=read_ram(addr);

}


 
void ram_write(unsigned int32 addr,int8 *ram, int8 nbytes){                                                 
   int i;

   //nbytes=2;
   for(i=0;i<nbytes;i++,ram++,addr++)
     write_ram(addr,*ram);
     


}



void ram_read2(unsigned int32 addr,int8 *ram, int8 nbytes){
   int i;   

   //nbytes=2;
   for(i=0;i<nbytes;i++,ram++,addr++)
      *ram=read_ram2(addr);

}


 
void ram_write2(unsigned int32 addr,int8 *ram, int8 nbytes){                                                 
   int i;

   //nbytes=2;
   for(i=0;i<nbytes;i++,ram++,addr++)
     write_ram2(addr,*ram);
     


}


addressmod( FRAM, ram_read, ram_write, 0, 0xFFFF ); // text infos

addressmod( BRAM, ram_read2, ram_write2, 0, 0xFFFF ); // buttons and lists



i realise the code is very crude here but i have 400KB available of use and i wanna try it all?

or does addressmod have the ability to address 0-<a huge size>
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