Re: gEDA-user: C question

2007-03-04 Thread Andy Peters

On Mar 3, 2007, at 4:57 PM, [EMAIL PROTECTED] wrote:

Thanks.  I threw the question to the group because I know there's  
plenty of knowledgable people reading willing to answer it.


Anyway, I was trying to get the compiler to generate 2 versions of  
an initialized array: ROM, and RAM.  The processor I am using has  
more ROM than RAM, so
placing the code into ROM makes more sense, yet I was having  
trouble getting access it correctly due to a routine expecting a  
const ptr.  So, I was trying it in

RAM, but not sure if the code was correct.

Thanks again for the help :)


You didn't say which compiler you're using, nor which architecture.

But Keil's 8051 compiler has the code keyword, which tells the  
compiler that the variable should be put into CODE space, which is by  
definition ROM.


-a


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-04 Thread Hans Nieuwenhuis
On Sun, 4 Mar 2007 13:58:45 -0700
Andy Peters [EMAIL PROTECTED] wrote:

 On Mar 3, 2007, at 4:57 PM, [EMAIL PROTECTED] wrote:
 
  Thanks.  I threw the question to the group because I know there's  
  plenty of knowledgable people reading willing to answer it.
 
  Anyway, I was trying to get the compiler to generate 2 versions of  
  an initialized array: ROM, and RAM.  The processor I am using has  
  more ROM than RAM, so
  placing the code into ROM makes more sense, yet I was having  
  trouble getting access it correctly due to a routine expecting a  
  const ptr.  So, I was trying it in
  RAM, but not sure if the code was correct.
 
  Thanks again for the help :)
 
 You didn't say which compiler you're using, nor which architecture.
 
 But Keil's 8051 compiler has the code keyword, which tells the  
 compiler that the variable should be put into CODE space, which is by  
 definition ROM.
 

For gcc ports this keyword would be: __attribute__((section
(YOURSECTION))) where YOURSECTION must be replaced with .text for code
in ROM. 
GCC ports are not consistent though. If I develop for ARM and declare
avariable as const it will end up in RAM also unless I add the
__attribute__... keyword. However the MSP430 port places the variable in
ROM if I only declare it as const...
Maybe the reason for this behaviour is the difference in complexity in
ARM and MSP430 micros...

HTH,

Hans



 -a
 
 
 ___
 geda-user mailing list
 geda-user@moria.seul.org
 http://www.seul.org/cgi-bin/mailman/listinfo/geda-user
 


-- 

$ cat .sig /dev/null


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-03 Thread Philipp Klaus Krause
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

John Coppens schrieb:

 'Static' is normally reserved to specify the data should never be
 destroyed by the compiler if the compiler thinks it's not necessary any
 more (eg. to make data 'static', i.e. available between function calls to
 the same function).

static has two meanings: The one you mentioned for variables declared
inside a function, the one Ben Jackson mentioned for variables declared
outside a function.

Philipp
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF6WqKbtUV+xsoLpoRAlogAKDVJ2bMN+DsjRv63K91OjTySimyvwCg1ntE
YZtmuDvJm+dFdBlZ0ugvwQo=
=U2uw
-END PGP SIGNATURE-


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-03 Thread John Coppens
On Sat, 03 Mar 2007 13:31:06 +0100
Philipp Klaus Krause [EMAIL PROTECTED] wrote:

 static has two meanings: The one you mentioned for variables declared
 inside a function, the one Ben Jackson mentioned for variables declared
 outside a function.

Isn't internet great? Collaborative learning! Thanks Philipp - I had
never used 'static' in Ben's way.

John


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-03 Thread John Griessen

John Coppens wrote:

Though I can't image the reason to put this question on this forum,


Many of the systems made with gEDA tools have processors, and some of those are 
microcontrollers that GCC compiles C code.  It's germain to coding gEDA tools 
and the systems developed with them too.


I find comments like yours helpful, since most of my microcontroller experience 
has been in assembler and I'm learning C now for that, and to help with gEDA 
coding...


John Griessen


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-03 Thread carzrgr8
Thanks.  I threw the question to the group because I know there's plenty of 
knowledgable people reading willing to answer it.  

Anyway, I was trying to get the compiler to generate 2 versions of an 
initialized array: ROM, and RAM.  The processor I am using has more ROM than 
RAM, so 
placing the code into ROM makes more sense, yet I was having trouble getting 
access it correctly due to a routine expecting a const ptr.  So, I was trying 
it in 
RAM, but not sure if the code was correct.

Thanks again for the help :)

gene

- Original Message -
From: John Griessen 
Date: Saturday, March 3, 2007 11:51 am
Subject: Re: gEDA-user: C question
To: gEDA user mailing list 

 John Coppens wrote:
  Though I can't image the reason to put this question on this forum,
 
 Many of the systems made with gEDA tools have processors, and 
 some of those are 
 microcontrollers that GCC compiles C code.  It's germain to 
 coding gEDA tools 
 and the systems developed with them too.
 
 I find comments like yours helpful, since most of my 
 microcontroller experience 
 has been in assembler and I'm learning C now for that, and to 
 help with gEDA 
 coding...
 
 John Griessen
 
 
 ___
 geda-user mailing list
 geda-user@moria.seul.org
 http://www.seul.org/cgi-bin/mailman/listinfo/geda-user
 


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-03 Thread Ben Jackson
On Sat, Mar 03, 2007 at 11:57:36PM +, [EMAIL PROTECTED] wrote:
 
 Anyway, I was trying to get the compiler to generate 2 versions of
 an initialized array: ROM, and RAM.

Declaring something const might do it, although some architectures like
AVR address ROM and RAM differently, so you have to pay attention.

The only way to be sure that data goes were you want it is to write a
linker script.  That will ensure that all of the data and code is
organized the way you want.  For example, for a network card I organized
all of the primary functionality into a 'cached' section and used a
link script to group that section together.  By using one contiguous
block of memory the processor is able to keep all of the code in its
L1 icache.

-- 
Ben Jackson AD7GD
[EMAIL PROTECTED]
http://www.ben.com/


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


gEDA-user: C question

2007-03-02 Thread carzrgr8
Look at the following:1) int bob[5] = {0x1, 0x2];2) int const bob[2] = {0x1, 
0x2};3) static int const bob[2] = {0x1, 0x2};1  creates an initialized array in 
ram.2 creates a read-only array - presumably in ROMWhat does 3 do?  I think 3 
compiles to a read-only area of ram.  Am I correct?gene


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-02 Thread Ben Jackson
On Sat, Mar 03, 2007 at 03:23:22AM +, [EMAIL PROTECTED] wrote:
 Look at the following:1) int bob[5] = {0x1, 0x2];2) int const bob[2] = {0x1, 
 0x2};3) static int const bob[2] = {0x1, 0x2};1  creates an initialized array 
 in ram.2 creates a read-only array - presumably in ROMWhat does 3 do?  I 
 think 3 compiles to a read-only area of ram.  Am I correct?gene

static vs nothing (non-static, default) has to do with linking.  A static
variable is not global and cannot be accessed from other modules (files,
basically) when compiling.  It's basically hiding data and avoiding
namespace polution.

const vs nothing (non-const, default) determines whether you can modify
the data.  The compiler may put the data somewhere different than it
would put other initialized data, or it may not.  Where you put const
matters, because in one declaration different things might be protected.
For example,

const char *p;  /* p points to 'const chars', an immutable string */
char const *p;  /* the pointer p can't change, but the chars can */
const char const *p; /* neither p nor the chars it points at change */

So without looking it up, I'm not sure what your 'int const bob[]' means,
but you probably mean 'const int bob[]', the ints in bob don't change.

-- 
Ben Jackson AD7GD
[EMAIL PROTECTED]
http://www.ben.com/


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: C question

2007-03-02 Thread John Coppens
On Sat, 03 Mar 2007 03:23:22 + (GMT)
[EMAIL PROTECTED] wrote:

 Look at the following:1) int bob[5] = {0x1, 0x2];2) int const bob[2] =
 {0x1, 0x2};3) static int const bob[2] = {0x1, 0x2};1  creates an
 initialized array in ram.2 creates a read-only array - presumably in
 ROMWhat does 3 do?  I think 3 compiles to a read-only area of ram.  Am
 I correct?gene

Though I can't image the reason to put this question on this forum,
here's what I think:

'Static' is normally reserved to specify the data should never be
destroyed by the compiler if the compiler thinks it's not necessary any
more (eg. to make data 'static', i.e. available between function calls to
the same function).

'const' means the program shouldn't be able to change it. Like you said,
make it read-only. 

John


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user