array of data in cog memory?
jcook
Posts: 8
Is there a way in C to create an array of variables in cog memory?
I am using SimpleIDE with cog_c_toggle as an example. I tried this line to create the array of data that I want:
static _COGMEM unsigned char pdata[512];
When I build I get this error:
cog_array_fw.cogc:10:30: error: data type of 'pdata' isn't suitable for a register
What is the proper way to declare an array and have it in cog memory?
I am using SimpleIDE with cog_c_toggle as an example. I tried this line to create the array of data that I want:
static _COGMEM unsigned char pdata[512];
When I build I get this error:
cog_array_fw.cogc:10:30: error: data type of 'pdata' isn't suitable for a register
What is the proper way to declare an array and have it in cog memory?
Comments
Are you trying to store 8 bit characters? CogRam is all 32bit and nothing else unless you provide the code to convert data.
I have no problem doing this in PropForth as there is quite a bit of extra space in each cog. The only problem is the StopCog and Reset dump the data. If you are going to do this, you have to deal with more volatility than in HubRam. And wehn the data is lost, the contents of the CogRam are indeterminate.. they are not all a predicitable default value. So you have to initialize again. I suppose that means a shadow image of the array in HubRam.
What are you trying to accomplish? There may be another way to achieve your goal. An array in HUB memory often performs almost as well as one in COG memory (the cost of HUB memory accesses is often hidden by the compiler, and COG memory arrays are slowed down by the requirement to add 1 cycle after modifying the access instruction).
(You could keep each byte in a long COG register wasting three bytes of space each to save packing/unpacking, but that is, well, a waste).
Could you point me to some information on the self modifying code? I have never seen an example of that and it sounds like an interesting thing to investigate.
As for what I am trying to accomplish, I stumbled across the propeller in a web search and thought it would be a neat thing to play with so I bought a quickstart board and am converting some code I used for digital pattern generation as a learning experience.
COG memory is organized as 32 bit registers, which also hold instructions. The memory read operations (like RDBYTE) that the C compiler uses can only access HUB memory, not COG memory, which is why C doesn't allow arrays in COG memory. If you did want an array in COG memory you'd have to do something like:
The movd and movs instructions are specifically designed for modifying the destination and source fields of instructions.
Welcome to the Propeller world! It is a very neat processor. If you're just starting out, I'd recommend keeping things simple and just using HUB memory to start with. Porting code from other environments is pretty straightforward with the C compiler. Once you have it working then you can start thinking about optimizing it with inline assembly or COGMEM declarations.
Regards,
Eric