|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
Passing address of rom array into a function. |
Posted: Tue Feb 04, 2020 9:41 am |
|
|
Based on other threads in this forum dealing with strings, I think this is the way to do it... Am I close? I wasn't able to printf() the ptr[x] value as a number directly, so maybe there's a trick with that.
Code: | #include <main.h>
#include <stddef.h> // NULL
// Store this in ROM.
rom int8 data1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
rom int8 data2[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
void function(rom int8 *ptr, int size)
{
printf ("function(0x%x, %d)\r\n", ptr, size);
if (ptr != NULL)
{
for (int idx=0; idx < size; idx++)
{
// Load value from ROM.
int8 value = ptr[idx];
printf ("%d ", value);
}
printf ("\r\n");
}
}
void main()
{
// Call function.
function (data1, 10);
function (data2, 10);
while(TRUE)
{
//TODO: User Code
}
}
// End of main.c
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Tue Feb 04, 2020 10:45 am |
|
|
We already ran into a snag. How do I move the ROM array to its own file, and "extern" it? I tried variations of "extern", "rom extern", "extern rom", etc.
If we have something like this...
romarrays.c:
Code: | #include <main.h>
// Store this in ROM.
rom int8 data1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
rom int8 data2[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
// End of romarrays.c
|
...what lets us access that in other files?
I tried this, and while it compiles, it doesn't work.
Code: | extern rom int8 data1[];
extern rom int8 data2[]; |
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
ralph79
Joined: 29 Aug 2007 Posts: 87
|
|
Posted: Tue Feb 04, 2020 11:15 am |
|
|
My suggestion IMHO (based in some work already made and situations I had to change according to CCS versions) is:
Declare the const variables directly in the main.h file (putting these arrays as globals) and acessing it from other files. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Tue Feb 04, 2020 11:24 am |
|
|
Ah, CCS reports I should try "const" right now as there are some issues with "rom" they are working on.
I still had no luck with an extern of a const:
extern const int8 data1[];
extern const int8 data2[]; _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Tue Feb 04, 2020 11:25 am |
|
|
ralph79 wrote: | my suggestion IMHO (based in some work already made and situations I had to change according to CCS versions) is:
declare the const variables directly in the main.h file (putting these arrays as globals) and acessing it from other files... |
Yes, doing a #include of the .c or .h file appears to work. All roads always seem to lead back to "put everything in one file using include" to make it go _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
|
|
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
|