Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #23448 > unrolled thread

Use RAM to modify a field

Started by"srao" <109468@EmbeddedRelated>
First post2016-04-01 19:37 -0500
Last post2016-04-05 11:04 -0500
Articles 17 on this page of 37 — 12 participants

Back to article view | Back to comp.arch.embedded


Contents

  Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-01 19:37 -0500
    Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-02 19:35 -0500
      Re: Use RAM to modify a field David Brown <david.brown@hesbynett.no> - 2016-04-04 08:55 +0200
        Re: Use RAM to modify a field Jack <jack4747@gmail.com> - 2016-04-04 00:52 -0700
        Re: Use RAM to modify a field Grant Edwards <invalid@invalid.invalid> - 2016-04-04 14:24 +0000
        Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 12:25 -0500
          Re: Use RAM to modify a field upsidedown@downunder.com - 2016-04-04 21:42 +0300
            Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 15:41 -0500
            Re: Use RAM to modify a field David Brown <david.brown@hesbynett.no> - 2016-04-05 08:02 +0200
      Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-04 11:42 -0500
      Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-04 12:09 -0500
        Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 12:34 -0500
          Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 13:41 -0500
            Re: Use RAM to modify a field Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-04 18:49 +0000
              Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 15:46 -0500
                Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-04 16:32 -0500
                  Re: Use RAM to modify a field Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-04 21:48 +0000
            Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-04 15:55 -0500
              Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-04 17:49 -0500
                Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-05 12:39 -0500
                  Re: Use RAM to modify a field Tim Wescott <seemywebsite@myfooter.really> - 2016-04-05 15:55 -0500
                    Re: Use RAM to modify a field lasselangwadtchristensen@gmail.com - 2016-04-05 14:45 -0700
                    Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-05 19:22 -0500
            Re: Use RAM to modify a field David Brown <david.brown@hesbynett.no> - 2016-04-05 08:29 +0200
          Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-04 15:50 -0500
            Re: Use RAM to modify a field David Brown <david.brown@hesbynett.no> - 2016-04-05 08:38 +0200
              Re: Use RAM to modify a field Tim Wescott <tim@seemywebsite.com> - 2016-04-05 11:11 -0500
              Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-05 11:46 -0500
          Re: Use RAM to modify a field David Brown <david.brown@hesbynett.no> - 2016-04-05 08:17 +0200
            Re: Use RAM to modify a field Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-04-05 09:58 +0300
              Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-05 11:54 -0500
                Re: Use RAM to modify a field Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-04-05 22:46 +0300
                  Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-05 18:21 -0500
                    Re: Use RAM to modify a field Reinhardt Behm <rbehm@hushmail.com> - 2016-04-06 12:58 +0800
                    Re: Use RAM to modify a field "srao" <109468@EmbeddedRelated> - 2016-04-06 11:57 -0500
                      Re: Use RAM to modify a field Dave Nadler <drn@nadler.com> - 2016-04-06 10:20 -0700
            Re: Use RAM to modify a field Tim Wescott <tim@seemywebsite.com> - 2016-04-05 11:04 -0500

Page 2 of 2 — ← Prev page 1 [2]


#23514

FromTim Wescott <seemywebsite@myfooter.really>
Date2016-04-05 15:55 -0500
Message-ID<z6OdnQHGec2xu5nKnZ2dnUU7-dlg4p2d@giganews.com>
In reply to#23508
On Tue, 05 Apr 2016 12:39:48 -0500, srao wrote:

>>On Mon, 04 Apr 2016 15:55:00 -0500, srao wrote:
>>
>>>>On Mon, 04 Apr 2016 12:34:28 -0500, Tim Wescott wrote:
>>>>
>>>>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
>>>>> 
>>>>>>>On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>>>>>
>>>>>>>> I need to use Copy and 8K block of data (from a parameter block
>>>>>> address
>>>>>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>>>>>> contents back to flash. The size of the RAM is 256K.  I believe
>>>>>> dynamic
>>>>>>>> memory allocation with heap (using a pointer)should work for
> this?
>>>>>> Would
>>>>>>>> like to know if this would be the right way togo?
>>>>>>>> Note: Please notify if any detail seems missing.
>>>>>>>
>>>>>>>A general description of what you're doing would be useful.
>>>>>>>
>>>>>>>If it's an embedded system and it has to run forever, using the
> heap
>>> is
>>>>>>>probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>>>>>>embedded engineers would allocate the block statically unless that
>>>>>>>makes
>>>>>> 
>>>>>>>the system run out of RAM.  If they did NOT allocate it statically,
>>>>>>>then
>>>>>> 
>>>>>>>they would ask themselves if they have enough memory in the first
>>>>>>>place.
>>>>>>>
>>>>>>>* In embedded, "paranoid" often means "successful"
>>>>>>>
>>>>>>>--
>>>>>>>
>>>>>>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>>>>> 
>>>>>> Also,
>>>>>> 
>>>>>> Would static allocation utilize RAM space? I am using this for an
>>>>>> embedded application which has to read data out from hardware,
> store
>>> it
>>>>>> in RAM and modify the field.
>>>>>> 
>>>>>> The RAM here is not part of processor.A separate flashchip  has
>>>>>> boot+flash+ RAM region  which the application uses. C++ borland
>>>>>> compiler in use.  Does static memory allocation use space out of
> RAM?
>>>>>> Or does it depend on the compiler?
>>>>> 
>>>>> I believe that you are asking if using the "static" keyword in some
> C
>>> or
>>>>> C ++ code would cause the tools to put the space in RAM.
>>>>> 
>>>>> The answer is that if the tools are working correctly, and if the
>>> space
>>>>> is not declared as "const", then yes.  The tools working correctly
>>>>> depends on both the tools (Borland was still good the last time I
> used
>>>>> it) and how they're set up, though, so I can't just say that it WILL
>>>>> work for you based on the fact that it's Borland.
>>>>> 
>>>>> HOWEVER -- if you're declaring a variable outside of any struct,
>>>>> function, or whatever, then "static" is telling the compiler about
> who
>>>>> can see the variable, not whether the variable is writable (and thus
>>> in
>>>>> RAM) or not.
>>>>> 
>>>>> Here's what SHOULD happen in most embedded systems, in C or C++, if
>>> you
>>>>> declare a variable outside of any struct, function, or whatever:
>>>>> 
>>>>> // "whatever" gets put in read-only memory, and is visible outside
> of
>>> //
>>>>> the resulting object file const sometype whatever = <inital value>;
>>>>> 
>>>>> // "whatever" gets put in read-only memory, and is only visible to
> //
>>>>> things within the C file:
>>>>> const static sometype whatever = <initial value>;
>>>>> 
>>>>> // "whatever" gets put in RAM, is visible outside of // the
> resulting
>>>>> object file, and (if the tools are set // up correctly) filled with
> 0
>>>>> bytes:
>>>>> sometype whatever;
>>>>> 
>>>>> // "whatever" gets put in RAM, is only visible to // things within
> the
>>> C
>>>>> file, and (if the tools are set // up correctly) filled with 0
> bytes:
>>>>> static sometype whatever;
>>>>> 
>>>>> HTH
>>>>> 
>>>>> If David Brown says that I'm wrong, just fill in a resigned sigh
> from
>>> me
>>>>> and believe what he says.
>>>>
>>>>I failed to mention:
>>>>
>>>>If you want to permanently allocate some space at compile time, from
>>>>within a function, then you need to use "static" -- otherwise the
>>>>compiler will try to create it on the heap or on the stack.  For an
> 8kB
>>>>hunk of memory, this would probably cause Bad Things to happen.
>>>>
>>>>void my_function(void)
>>>>{
>>>>  char bob[8192];  // Allocates on stack or heap -- ick static char
> sue
>>>>  [8192];  // allocates in RAM, only visible
>>>>                           // within this function
>>>>}
>>>>
>>>>Note that doing this, with this large a chunk of memory, is probably
> an
>>>>indication that you're doing something wrong.  I could easily see your
>>>>buffer as being static within a C file (or a C++ structure) that's
>>>>dedicated to talking to flash -- but I can't easily see it within a
>>>>function.
>>>>
>>>>--
>>>>
>>>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>> 
>>> Thanks! Completely understand. So do you feel there is a better way to
>>> handle this?
>>
>>Better than what?
>>
>>Keep in mind that with Embedded system programming there is no "best".
>>Using the heap is almost always not at all a good idea, but there are a
>>very few applications where it'll work OK.  Ditto for just about any
>>other idea that works.  Driving factors are how long the thing has to
>>work between reboots, how bad it is if the processor cocks up its toes
>>unexpectedly, how much RAM you're actually using, how much time you have
> 
>>to spend on coding, and, to some extent, how much time you need to
>>complete the operation.
>>
>>If, for instance, you told us that the product has to run for years and
>>years between reboots that would point away from using the heap, ever.
>>But if you then said that the _only_ time that this code is ever used is
> 
>>in the factory or by service personnel who then immediately cycle power,
> 
>>then I'd say "sure, go ahead" (in fact, this is one of the two places
>>where I'll routinely use the heap).
>>
>>In nearly all cases that I can think of, statically allocating a chunk
>>that's dedicated to this is best, because it's safe (unless you're
>>running out of RAM) and easy (so, fewer lines of code and hence fewer
>>opportunities for bugs).  But it's not best if you're almost out of
>>memory.
>>
>>Rob's idea of allocating on the stack would work well in a lot of cases,
> 
>>but you're using an old 16-bit x86 processor with segments, and that
>>makes it a not-quite-so-good idea because you're not talking about up to
> 
>>1/32 of the available RAM, you're talking about up to 1/8 of the
>>available stack space -- that seems a lot more cramped to me.
>>
>>Rob's idea of a "monoheap" could also be best, if you're really having
>>to
> 
>>shake the box to try to make room for a bit more cereal.
>>
>>--
>>
>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
> 
> Well, this is used by service personnel once in a while during a image
> update only. Once the image is in, the application running does not need
> to use this functionality, is a part of boot only.

In that case then I'd say go ahead and use the heap.  Most of the "OMG" 
connected with heap usage in an embedded system is that heaps don't 
usually stand up well to having everything in the world using one heap 
for a very long time.

You are proposing a very limited use of the heap -- it certainly works 
for me.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#23515

Fromlasselangwadtchristensen@gmail.com
Date2016-04-05 14:45 -0700
Message-ID<67b4f666-2a5a-4227-84bb-af42104efb79@googlegroups.com>
In reply to#23514
Den tirsdag den 5. april 2016 kl. 22.55.12 UTC+2 skrev Tim Wescott:
> On Tue, 05 Apr 2016 12:39:48 -0500, srao wrote:
> 
> >>On Mon, 04 Apr 2016 15:55:00 -0500, srao wrote:
> >>
> >>>>On Mon, 04 Apr 2016 12:34:28 -0500, Tim Wescott wrote:
> >>>>
> >>>>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
> >>>>> 
> >>>>>>>On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
> >>>>>>>
> >>>>>>>> I need to use Copy and 8K block of data (from a parameter block
> >>>>>> address
> >>>>>>>> in flash) to RAM, modify data at a particular offset and copy the
> >>>>>>>> contents back to flash. The size of the RAM is 256K.  I believe
> >>>>>> dynamic
> >>>>>>>> memory allocation with heap (using a pointer)should work for
> > this?
> >>>>>> Would
> >>>>>>>> like to know if this would be the right way togo?
> >>>>>>>> Note: Please notify if any detail seems missing.
> >>>>>>>
> >>>>>>>A general description of what you're doing would be useful.
> >>>>>>>
> >>>>>>>If it's an embedded system and it has to run forever, using the
> > heap
> >>> is
> >>>>>>>probably a bad idea (Google "heap fragmentation").  Truly paranoid*
> >>>>>>>embedded engineers would allocate the block statically unless that
> >>>>>>>makes
> >>>>>> 
> >>>>>>>the system run out of RAM.  If they did NOT allocate it statically,
> >>>>>>>then
> >>>>>> 
> >>>>>>>they would ask themselves if they have enough memory in the first
> >>>>>>>place.
> >>>>>>>
> >>>>>>>* In embedded, "paranoid" often means "successful"
> >>>>>>>
> >>>>>>>--
> >>>>>>>
> >>>>>>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
> >>>>>> 
> >>>>>> Also,
> >>>>>> 
> >>>>>> Would static allocation utilize RAM space? I am using this for an
> >>>>>> embedded application which has to read data out from hardware,
> > store
> >>> it
> >>>>>> in RAM and modify the field.
> >>>>>> 
> >>>>>> The RAM here is not part of processor.A separate flashchip  has
> >>>>>> boot+flash+ RAM region  which the application uses. C++ borland
> >>>>>> compiler in use.  Does static memory allocation use space out of
> > RAM?
> >>>>>> Or does it depend on the compiler?
> >>>>> 
> >>>>> I believe that you are asking if using the "static" keyword in some
> > C
> >>> or
> >>>>> C ++ code would cause the tools to put the space in RAM.
> >>>>> 
> >>>>> The answer is that if the tools are working correctly, and if the
> >>> space
> >>>>> is not declared as "const", then yes.  The tools working correctly
> >>>>> depends on both the tools (Borland was still good the last time I
> > used
> >>>>> it) and how they're set up, though, so I can't just say that it WILL
> >>>>> work for you based on the fact that it's Borland.
> >>>>> 
> >>>>> HOWEVER -- if you're declaring a variable outside of any struct,
> >>>>> function, or whatever, then "static" is telling the compiler about
> > who
> >>>>> can see the variable, not whether the variable is writable (and thus
> >>> in
> >>>>> RAM) or not.
> >>>>> 
> >>>>> Here's what SHOULD happen in most embedded systems, in C or C++, if
> >>> you
> >>>>> declare a variable outside of any struct, function, or whatever:
> >>>>> 
> >>>>> // "whatever" gets put in read-only memory, and is visible outside
> > of
> >>> //
> >>>>> the resulting object file const sometype whatever = <inital value>;
> >>>>> 
> >>>>> // "whatever" gets put in read-only memory, and is only visible to
> > //
> >>>>> things within the C file:
> >>>>> const static sometype whatever = <initial value>;
> >>>>> 
> >>>>> // "whatever" gets put in RAM, is visible outside of // the
> > resulting
> >>>>> object file, and (if the tools are set // up correctly) filled with
> > 0
> >>>>> bytes:
> >>>>> sometype whatever;
> >>>>> 
> >>>>> // "whatever" gets put in RAM, is only visible to // things within
> > the
> >>> C
> >>>>> file, and (if the tools are set // up correctly) filled with 0
> > bytes:
> >>>>> static sometype whatever;
> >>>>> 
> >>>>> HTH
> >>>>> 
> >>>>> If David Brown says that I'm wrong, just fill in a resigned sigh
> > from
> >>> me
> >>>>> and believe what he says.
> >>>>
> >>>>I failed to mention:
> >>>>
> >>>>If you want to permanently allocate some space at compile time, from
> >>>>within a function, then you need to use "static" -- otherwise the
> >>>>compiler will try to create it on the heap or on the stack.  For an
> > 8kB
> >>>>hunk of memory, this would probably cause Bad Things to happen.
> >>>>
> >>>>void my_function(void)
> >>>>{
> >>>>  char bob[8192];  // Allocates on stack or heap -- ick static char
> > sue
> >>>>  [8192];  // allocates in RAM, only visible
> >>>>                           // within this function
> >>>>}
> >>>>
> >>>>Note that doing this, with this large a chunk of memory, is probably
> > an
> >>>>indication that you're doing something wrong.  I could easily see your
> >>>>buffer as being static within a C file (or a C++ structure) that's
> >>>>dedicated to talking to flash -- but I can't easily see it within a
> >>>>function.
> >>>>
> >>>>--
> >>>>
> >>>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
> >>> 
> >>> Thanks! Completely understand. So do you feel there is a better way to
> >>> handle this?
> >>
> >>Better than what?
> >>
> >>Keep in mind that with Embedded system programming there is no "best".
> >>Using the heap is almost always not at all a good idea, but there are a
> >>very few applications where it'll work OK.  Ditto for just about any
> >>other idea that works.  Driving factors are how long the thing has to
> >>work between reboots, how bad it is if the processor cocks up its toes
> >>unexpectedly, how much RAM you're actually using, how much time you have
> > 
> >>to spend on coding, and, to some extent, how much time you need to
> >>complete the operation.
> >>
> >>If, for instance, you told us that the product has to run for years and
> >>years between reboots that would point away from using the heap, ever.
> >>But if you then said that the _only_ time that this code is ever used is
> > 
> >>in the factory or by service personnel who then immediately cycle power,
> > 
> >>then I'd say "sure, go ahead" (in fact, this is one of the two places
> >>where I'll routinely use the heap).
> >>
> >>In nearly all cases that I can think of, statically allocating a chunk
> >>that's dedicated to this is best, because it's safe (unless you're
> >>running out of RAM) and easy (so, fewer lines of code and hence fewer
> >>opportunities for bugs).  But it's not best if you're almost out of
> >>memory.
> >>
> >>Rob's idea of allocating on the stack would work well in a lot of cases,
> > 
> >>but you're using an old 16-bit x86 processor with segments, and that
> >>makes it a not-quite-so-good idea because you're not talking about up to
> > 
> >>1/32 of the available RAM, you're talking about up to 1/8 of the
> >>available stack space -- that seems a lot more cramped to me.
> >>
> >>Rob's idea of a "monoheap" could also be best, if you're really having
> >>to
> > 
> >>shake the box to try to make room for a bit more cereal.
> >>
> >>--
> >>
> >>Tim Wescott Wescott Design Services http://www.wescottdesign.com
> > 
> > Well, this is used by service personnel once in a while during a image
> > update only. Once the image is in, the application running does not need
> > to use this functionality, is a part of boot only.
> 
> In that case then I'd say go ahead and use the heap.  Most of the "OMG" 
> connected with heap usage in an embedded system is that heaps don't 
> usually stand up well to having everything in the world using one heap 
> for a very long time.
> 
> You are proposing a very limited use of the heap -- it certainly works 
> for me.
> 

and the heap and stack will usually be competing for the same memory


-Lasse

[toc] | [prev] | [next] | [standalone]


#23520

From"srao" <109468@EmbeddedRelated>
Date2016-04-05 19:22 -0500
Message-ID<3IWdnWfvZ7wly5nKnZ2dnUU7-IfNnZ2d@giganews.com>
In reply to#23514

>>>Tim Wescott Wescott Design Services http://www.wescottdesign.com
>> 
>>On Tue, 05 Apr 2016 12:39:48 -0500, srao wrote:
>> Well, this is used by service personnel once in a while during a image
>> update only. Once the image is in, the application running does not
need
>> to use this functionality, is a part of boot only.
>
>In that case then I'd say go ahead and use the heap.  Most of the "OMG" 
>connected with heap usage in an embedded system is that heaps don't 
>usually stand up well to having everything in the world using one heap 
>for a very long time.
>
>You are proposing a very limited use of the heap -- it certainly works 
>for me.
>
>-- 
>
>Tim Wescott
>Wescott Design Services
>http://www.wescottdesign.com

Yes, its only used every time the image needs to be updated.  
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23496

FromDavid Brown <david.brown@hesbynett.no>
Date2016-04-05 08:29 +0200
Message-ID<ndvlr1$dgn$1@dont-email.me>
In reply to#23480
On 04/04/16 20:41, Tim Wescott wrote:
> On Mon, 04 Apr 2016 12:34:28 -0500, Tim Wescott wrote:
> 
>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
>>
>>>> On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>>
>>>>> I need to use Copy and 8K block of data (from a parameter block
>>> address
>>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>>> contents back to flash. The size of the RAM is 256K.  I believe
>>> dynamic
>>>>> memory allocation with heap (using a pointer)should work for this?
>>> Would
>>>>> like to know if this would be the right way togo?
>>>>> Note: Please notify if any detail seems missing.
>>>>
>>>> A general description of what you're doing would be useful.
>>>>
>>>> If it's an embedded system and it has to run forever, using the heap is
>>>> probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>>> embedded engineers would allocate the block statically unless that
>>>> makes
>>>
>>>> the system run out of RAM.  If they did NOT allocate it statically,
>>>> then
>>>
>>>> they would ask themselves if they have enough memory in the first
>>>> place.
>>>>
>>>> * In embedded, "paranoid" often means "successful"
>>>>
>>>> --
>>>>
>>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>>
>>> Also,
>>>
>>> Would static allocation utilize RAM space? I am using this for an
>>> embedded application which has to read data out from hardware, store it
>>> in RAM and modify the field.
>>>
>>> The RAM here is not part of processor.A separate flashchip  has
>>> boot+flash+ RAM region  which the application uses. C++ borland
>>> compiler in use.  Does static memory allocation use space out of RAM?
>>> Or does it depend on the compiler?
>>
>> I believe that you are asking if using the "static" keyword in some C or
>> C ++ code would cause the tools to put the space in RAM.
>>
>> The answer is that if the tools are working correctly, and if the space
>> is not declared as "const", then yes.  The tools working correctly
>> depends on both the tools (Borland was still good the last time I used
>> it) and how they're set up, though, so I can't just say that it WILL
>> work for you based on the fact that it's Borland.
>>
>> HOWEVER -- if you're declaring a variable outside of any struct,
>> function, or whatever, then "static" is telling the compiler about who
>> can see the variable, not whether the variable is writable (and thus in
>> RAM) or not.
>>
>> Here's what SHOULD happen in most embedded systems, in C or C++, if you
>> declare a variable outside of any struct, function, or whatever:
>>
>> // "whatever" gets put in read-only memory, and is visible outside of //
>> the resulting object file const sometype whatever = <inital value>;
>>
>> // "whatever" gets put in read-only memory, and is only visible to //
>> things within the C file:
>> const static sometype whatever = <initial value>;
>>
>> // "whatever" gets put in RAM, is visible outside of // the resulting
>> object file, and (if the tools are set // up correctly) filled with 0
>> bytes:
>> sometype whatever;
>>
>> // "whatever" gets put in RAM, is only visible to // things within the C
>> file, and (if the tools are set // up correctly) filled with 0 bytes:
>> static sometype whatever;
>>
>> HTH
>>
>> If David Brown says that I'm wrong, just fill in a resigned sigh from me
>> and believe what he says.
> 
> I failed to mention:
> 
> If you want to permanently allocate some space at compile time, from 
> within a function, then you need to use "static" -- otherwise the 
> compiler will try to create it on the heap or on the stack.  For an 8kB 
> hunk of memory, this would probably cause Bad Things to happen.
> 
> void my_function(void)
> {
>   char bob[8192];  // Allocates on stack or heap -- ick
>   static char sue [8192];  // allocates in RAM, only visible
>                            // within this function
> }

I know of no compiler that would put "bob" on the heap in the function
above - indeed, I am not convinced that the compiler could do so in
general.  It /could/ have a separate memory area, and it could allocate
the space statically, perhaps shared with other such data if the
functions do not overlap (compilers for cpu's like the 8051 will do
that).  But assuming a half-decent processor and a normal compiler
setup, "bob" will always go on the stack.  Whether that is "ick" or not
depends on how much stack space you have, and how you use it.

> 
> Note that doing this, with this large a chunk of memory, is probably an 
> indication that you're doing something wrong.  I could easily see your 
> buffer as being static within a C file (or a C++ structure) that's 
> dedicated to talking to flash -- but I can't easily see it within a 
> function.
> 

If you are only ever using it within the one function, there is no
difference between declaring a static block within a function or outside
it.  (It may be more convenient for debugging, or for checking the map
file, if it is file-level rather than inside the function.  But the
memory usage and the generated code will be the same.)

And if you have a "bare metal" system, rather than separate tasks with
separate stacks, then your ram layout very often has the stack at the
top of the ram, growing downwards, and statically allocated data built
up from the bottom (followed by the heap if you use one).  It matters
little whether the buffer lives at a fixed address near the bottom of
the ram, or if it gets allocated on the stack near the top of the ram.

If you have multiple independent functions with local data like this,
putting the data on the stack makes it easy to re-use the space.  It can
also be convenient to use a VLA if the size of the space needed is not
known until run-time (but be sure to check the maximum size!).

But if you have a processor with poor address registers (such as an
AVR), using the stack will give less efficient code.  Putting the data
on the stack also makes it less "visible" (such as in the map file, or
with size-checking utilities.  Both methods are valid.

[toc] | [prev] | [next] | [standalone]


#23486

From"srao" <109468@EmbeddedRelated>
Date2016-04-04 15:50 -0500
Message-ID<VLidncyfm4U5Tp_KnZ2dnUU7-SfNnZ2d@giganews.com>
In reply to#23479
>I believe that you are asking if using the "static" keyword in some C or
C
>++ code would cause the tools to put the space in RAM.
>
>The answer is that if the tools are working correctly, and if the space 
>is not declared as "const", then yes.  The tools working correctly 
>depends on both the tools (Borland was still good the last time I used 
>it) and how they're set up, though, so I can't just say that it WILL work

>for you based on the fact that it's Borland.
>
>HOWEVER -- if you're declaring a variable outside of any struct, 
>function, or whatever, then "static" is telling the compiler about who 
>can see the variable, not whether the variable is writable (and thus in 
>RAM) or not.
>
>Here's what SHOULD happen in most embedded systems, in C or C++, if you 
>declare a variable outside of any struct, function, or whatever:
>
>// "whatever" gets put in read-only memory, and is visible outside of
>// the resulting object file
>const sometype whatever = <inital value>;
>
>// "whatever" gets put in read-only memory, and is only visible to
>// things within the C file:
>const static sometype whatever = <initial value>;
>
>// "whatever" gets put in RAM, is visible outside of
>// the resulting object file, and (if the tools are set
>// up correctly) filled with 0 bytes:
>sometype whatever;
>
>// "whatever" gets put in RAM, is only visible to
>// things within the C file, and (if the tools are set
>// up correctly) filled with 0 bytes:
>static sometype whatever;
>
>HTH
>
>If David Brown says that I'm wrong, just fill in a resigned sigh from me

>and believe what he says.
>
>-- 
>
>Tim Wescott
>Wescott Design Services
>http://www.wescottdesign.com


:) oh please don't. Been a great help
Thanks Tim, for all that information. 
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23497

FromDavid Brown <david.brown@hesbynett.no>
Date2016-04-05 08:38 +0200
Message-ID<ndvmbd$evu$1@dont-email.me>
In reply to#23486
On 04/04/16 22:50, srao wrote:
Tim Wescott wrote:
>>
>> If David Brown says that I'm wrong, just fill in a resigned sigh from me
> 
>> and believe what he says.
>>
>> -- 
>>
>> Tim Wescott
>> Wescott Design Services
>> http://www.wescottdesign.com
> 
> 
> :) oh please don't. Been a great help
> Thanks Tim, for all that information. 

I think Tim meant that I know more of the "ugly details" of C and C++
than he does, which I believe is true.  On the other hand, Tim is
fantastic and explaining the important issues in embedded development.
So pay attention to anything he says, and read my parts if you need the
fine print (but don't feel bad if you don't understand it in one
reading).  My posts are complementary to Tim's, not a replacement.

[toc] | [prev] | [next] | [standalone]


#23504

FromTim Wescott <tim@seemywebsite.com>
Date2016-04-05 11:11 -0500
Message-ID<noWdnbqTALw9fp7KnZ2dnUU7-T-dnZ2d@giganews.com>
In reply to#23497
On Tue, 05 Apr 2016 08:38:41 +0200, David Brown wrote:

> On 04/04/16 22:50, srao wrote:
> Tim Wescott wrote:
>>>
>>> If David Brown says that I'm wrong, just fill in a resigned sigh from
>>> me
>> 
>>> and believe what he says.
>>>
>>> --
>>>
>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>> 
>> 
>> :) oh please don't. Been a great help Thanks Tim, for all that
>> information.
> 
> I think Tim meant that I know more of the "ugly details" of C and C++
> than he does, which I believe is true.  On the other hand, Tim is
> fantastic and explaining the important issues in embedded development.
> So pay attention to anything he says, and read my parts if you need the
> fine print (but don't feel bad if you don't understand it in one
> reading).  My posts are complementary to Tim's, not a replacement.

Fine details.  They're only ugly details when you trip over them at some 
inconvenient time.  

I always like having folks like you on a project with me, and they 
usually seem to like having me (or the ones I've worked with have been 
incredibly polite).  It's nice to run my stuff through a sieve of brains 
made like yours.  

I hope I don't sound too much like Donald Trump when I say this, but I'm 
really good at turning an abstract description of some big electro-
mechanical wonder into reality.  My downside is that while I'm quite 
_competent_ at software and analog circuit design*, I'm not absolutely 
brilliant at either.

* Yes.  Those two.  No, I don't understand it either.

-- 
www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#23506

From"srao" <109468@EmbeddedRelated>
Date2016-04-05 11:46 -0500
Message-ID<Ub-dnUZLCsppdp7KnZ2dnUU7-fXNnZ2d@giganews.com>
In reply to#23497
>On 04/04/16 22:50, srao wrote:
>Tim Wescott wrote:
>>>
>>> If David Brown says that I'm wrong, just fill in a resigned sigh from
me
>> 
>>> and believe what he says.
>>>
>>> -- 
>>>
>>> Tim Wescott
>>> Wescott Design Services
>>> http://www.wescottdesign.com
>> 
>> 
>> :) oh please don't. Been a great help
>> Thanks Tim, for all that information. 
>
>I think Tim meant that I know more of the "ugly details" of C and C++
>than he does, which I believe is true.  On the other hand, Tim is
>fantastic and explaining the important issues in embedded development.
>So pay attention to anything he says, and read my parts if you need the
>fine print (but don't feel bad if you don't understand it in one
>reading).  My posts are complementary to Tim's, not a replacement.

Sure. Got it :)
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23495

FromDavid Brown <david.brown@hesbynett.no>
Date2016-04-05 08:17 +0200
Message-ID<ndvl2u$bge$1@dont-email.me>
In reply to#23479
On 04/04/16 19:34, Tim Wescott wrote:
> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
> 
>>> On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>
>>>> I need to use Copy and 8K block of data (from a parameter block
>> address
>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>> contents back to flash. The size of the RAM is 256K.  I believe
>> dynamic
>>>> memory allocation with heap (using a pointer)should work for this?
>> Would
>>>> like to know if this would be the right way togo?
>>>> Note: Please notify if any detail seems missing.
>>>
>>> A general description of what you're doing would be useful.
>>>
>>> If it's an embedded system and it has to run forever, using the heap is
>>> probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>> embedded engineers would allocate the block statically unless that makes
>>
>>> the system run out of RAM.  If they did NOT allocate it statically, then
>>
>>> they would ask themselves if they have enough memory in the first place.
>>>
>>> * In embedded, "paranoid" often means "successful"
>>>
>>> --
>>>
>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>
>> Also,
>>
>> Would static allocation utilize RAM space? I am using this for an
>> embedded application which has to read data out from hardware, store it
>> in RAM and modify the field.
>>
>> The RAM here is not part of processor.A separate flashchip  has
>> boot+flash+ RAM region  which the application uses. C++ borland compiler
>> in use.  Does static memory allocation use space out of RAM? Or does it
>> depend on the compiler?
> 
> I believe that you are asking if using the "static" keyword in some C or C
> ++ code would cause the tools to put the space in RAM.
> 
> The answer is that if the tools are working correctly, and if the space 
> is not declared as "const", then yes.  The tools working correctly 
> depends on both the tools (Borland was still good the last time I used 
> it) and how they're set up, though, so I can't just say that it WILL work 
> for you based on the fact that it's Borland.
> 
> HOWEVER -- if you're declaring a variable outside of any struct, 
> function, or whatever, then "static" is telling the compiler about who 
> can see the variable, not whether the variable is writable (and thus in 
> RAM) or not.
> 
> Here's what SHOULD happen in most embedded systems, in C or C++, if you 
> declare a variable outside of any struct, function, or whatever:
> 
> // "whatever" gets put in read-only memory, and is visible outside of
> // the resulting object file
> const sometype whatever = <inital value>;
> 
> // "whatever" gets put in read-only memory, and is only visible to
> // things within the C file:
> const static sometype whatever = <initial value>;
> 
> // "whatever" gets put in RAM, is visible outside of
> // the resulting object file, and (if the tools are set
> // up correctly) filled with 0 bytes:
> sometype whatever;
> 
> // "whatever" gets put in RAM, is only visible to
> // things within the C file, and (if the tools are set
> // up correctly) filled with 0 bytes:
> static sometype whatever;
> 
> HTH
> 
> If David Brown says that I'm wrong, just fill in a resigned sigh from me 
> and believe what he says.
> 

That's my cue for the nit-pick!  Your explanation is a good start, but
there are a couple of other points that I think are worth mentioning.

It is not clear if the OP is actually using C or C++ (his compiler
supports both).  But in the case of

	const sometype whatever = <initial value>;

there is a difference.  In C, the "whatever" has external linkage by
default - it is visible outside of the current object file, assuming
there is a matching "extern" declaration.  In C++, "whatever" has
internal linkage by default - it acts like "static const", unless there
is a matching "extern" declaration visible in the defining translation unit.

(The external visibility does not affect whether the object is put in
read-only or writeable memory, of course.)

Personally, I always make my file-level functions and data either
explicitly "static" (even in C++, in order to be consistent with my C
code), unless it has to be externally visible - in which case there is
always an "extern" declaration in the module's header file which is
#include'd by both the defining module and other modules that use it.
That keeps everything clear and consistent.

And I prefer to write "static const" rather than "const static" - the
compiler accepts both, of course, but I am more fussy!


Also note that when you make something "const", the compiler/linker does
not have to put it into read-only memory.  It /may/ put it in read-only
memory, and any attempt to change it in the program is undefined
behaviour, but it could equally well use ram.  On a PC, for example, it
will go in ram - but it will be put in a different segment from
read-write memory, and the segment will be marked read only.  On an AVR
(which has different cpu instructions for accessing flash and ram),
const data is usually put in RAM so that it can be accessed using the
same instructions as non-const data.  We don't know enough about the
OP's system to know where static const data would end up.

And of course if the compiler feels it doesn't actually /need/ to put
static const data in memory, due to the way it is used (or not used), it
will not put it in any memory.


[toc] | [prev] | [next] | [standalone]


#23499

FromTauno Voipio <tauno.voipio@notused.fi.invalid>
Date2016-04-05 09:58 +0300
Message-ID<ndvngl$i98$1@dont-email.me>
In reply to#23495
On 5.4.16 09:17, David Brown wrote:
> On 04/04/16 19:34, Tim Wescott wrote:
>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
>>
>>>> On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>>
>>>>> I need to use Copy and 8K block of data (from a parameter block
>>> address
>>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>>> contents back to flash. The size of the RAM is 256K.  I believe
>>> dynamic
>>>>> memory allocation with heap (using a pointer)should work for this?
>>> Would
>>>>> like to know if this would be the right way togo?
>>>>> Note: Please notify if any detail seems missing.
>>>>
>>>> A general description of what you're doing would be useful.
>>>>
>>>> If it's an embedded system and it has to run forever, using the heap is
>>>> probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>>> embedded engineers would allocate the block statically unless that makes
>>>
>>>> the system run out of RAM.  If they did NOT allocate it statically, then
>>>
>>>> they would ask themselves if they have enough memory in the first place.
>>>>
>>>> * In embedded, "paranoid" often means "successful"
>>>>
>>>> --
>>>>
>>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>>
>>> Also,
>>>
>>> Would static allocation utilize RAM space? I am using this for an
>>> embedded application which has to read data out from hardware, store it
>>> in RAM and modify the field.
>>>
>>> The RAM here is not part of processor.A separate flashchip  has
>>> boot+flash+ RAM region  which the application uses. C++ borland compiler
>>> in use.  Does static memory allocation use space out of RAM? Or does it
>>> depend on the compiler?
>>
>> I believe that you are asking if using the "static" keyword in some C or C
>> ++ code would cause the tools to put the space in RAM.
>>
>> The answer is that if the tools are working correctly, and if the space
>> is not declared as "const", then yes.  The tools working correctly
>> depends on both the tools (Borland was still good the last time I used
>> it) and how they're set up, though, so I can't just say that it WILL work
>> for you based on the fact that it's Borland.
>>
>> HOWEVER -- if you're declaring a variable outside of any struct,
>> function, or whatever, then "static" is telling the compiler about who
>> can see the variable, not whether the variable is writable (and thus in
>> RAM) or not.
>>
>> Here's what SHOULD happen in most embedded systems, in C or C++, if you
>> declare a variable outside of any struct, function, or whatever:
>>
>> // "whatever" gets put in read-only memory, and is visible outside of
>> // the resulting object file
>> const sometype whatever = <inital value>;
>>
>> // "whatever" gets put in read-only memory, and is only visible to
>> // things within the C file:
>> const static sometype whatever = <initial value>;
>>
>> // "whatever" gets put in RAM, is visible outside of
>> // the resulting object file, and (if the tools are set
>> // up correctly) filled with 0 bytes:
>> sometype whatever;
>>
>> // "whatever" gets put in RAM, is only visible to
>> // things within the C file, and (if the tools are set
>> // up correctly) filled with 0 bytes:
>> static sometype whatever;
>>
>> HTH
>>
>> If David Brown says that I'm wrong, just fill in a resigned sigh from me
>> and believe what he says.
>>
>
> That's my cue for the nit-pick!  Your explanation is a good start, but
> there are a couple of other points that I think are worth mentioning.
>
> It is not clear if the OP is actually using C or C++ (his compiler
> supports both).  But in the case of
>
> 	const sometype whatever = <initial value>;
>
> there is a difference.  In C, the "whatever" has external linkage by
> default - it is visible outside of the current object file, assuming
> there is a matching "extern" declaration.  In C++, "whatever" has
> internal linkage by default - it acts like "static const", unless there
> is a matching "extern" declaration visible in the defining translation unit.
>
> (The external visibility does not affect whether the object is put in
> read-only or writeable memory, of course.)
>
> Personally, I always make my file-level functions and data either
> explicitly "static" (even in C++, in order to be consistent with my C
> code), unless it has to be externally visible - in which case there is
> always an "extern" declaration in the module's header file which is
> #include'd by both the defining module and other modules that use it.
> That keeps everything clear and consistent.
>
> And I prefer to write "static const" rather than "const static" - the
> compiler accepts both, of course, but I am more fussy!
>
>
> Also note that when you make something "const", the compiler/linker does
> not have to put it into read-only memory.  It /may/ put it in read-only
> memory, and any attempt to change it in the program is undefined
> behaviour, but it could equally well use ram.  On a PC, for example, it
> will go in ram - but it will be put in a different segment from
> read-write memory, and the segment will be marked read only.  On an AVR
> (which has different cpu instructions for accessing flash and ram),
> const data is usually put in RAM so that it can be accessed using the
> same instructions as non-const data.  We don't know enough about the
> OP's system to know where static const data would end up.
>
> And of course if the compiler feels it doesn't actually /need/ to put
> static const data in memory, due to the way it is used (or not used), it
> will not put it in any memory.


The OP mentioned Borland C and Intel 80C186 - something I used much
about a quarter century ago.

The Borland toolset produces 16 bit DOS .exe files, which are segment-
relocatable. There is a need for a tool that makes absolute binary
images from the .exe files. I used Paradigm Locate for the conversion.

The Locate determines where a segment group goes, and its configuration
has the final say for the fate of a block of the memory image.

----

For memory allocation, my vote goes for the static block. In all
dynamic schemes, there is a difficult situation if the allocation
goes awry, and many embedded systems have no way to tell what
happened.

I guess that the erase block size of the flash is 8 kB, as the
OP was talking about changing a few bytes in it. I'd be careful
and first copy the contents of the block to a spare block in the
flash, and only after that erase the target for re-write.

-- 

-TV

[toc] | [prev] | [next] | [standalone]


#23507

From"srao" <109468@EmbeddedRelated>
Date2016-04-05 11:54 -0500
Message-ID<R5KdneB62qZ_cJ7KnZ2dnUU7-LnNnZ2d@giganews.com>
In reply to#23499
>On 5.4.16 09:17, David Brown wrote:
>> On 04/04/16 19:34, Tim Wescott wrote:
>>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
>>>
>>>>> On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>>>
>>>>>> I need to use Copy and 8K block of data (from a parameter block
>>>> address
>>>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>>>> contents back to flash. The size of the RAM is 256K.  I believe
>>>> dynamic
>>>>>> memory allocation with heap (using a pointer)should work for this?
>>>> Would
>>>>>> like to know if this would be the right way togo?
>>>>>> Note: Please notify if any detail seems missing.
>>>>>
>>>>> A general description of what you're doing would be useful.
>>>>>
>>>>> If it's an embedded system and it has to run forever, using the
heap
>is
>>>>> probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>>>> embedded engineers would allocate the block statically unless that
>makes
>>>>
>>>>> the system run out of RAM.  If they did NOT allocate it statically,
>then
>>>>
>>>>> they would ask themselves if they have enough memory in the first
>place.
>>>>>
>>>>> * In embedded, "paranoid" often means "successful"
>>>>>
>>>>> --
>>>>>
>>>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>>>
>>>> Also,
>>>>
>>>> Would static allocation utilize RAM space? I am using this for an
>>>> embedded application which has to read data out from hardware, store
it
>>>> in RAM and modify the field.
>>>>
>>>> The RAM here is not part of processor.A separate flashchip  has
>>>> boot+flash+ RAM region  which the application uses. C++ borland
>compiler
>>>> in use.  Does static memory allocation use space out of RAM? Or does
it
>>>> depend on the compiler?
>>>
>>> I believe that you are asking if using the "static" keyword in some C
or
>C
>>> ++ code would cause the tools to put the space in RAM.
>>>
>>> The answer is that if the tools are working correctly, and if the
space
>>> is not declared as "const", then yes.  The tools working correctly
>>> depends on both the tools (Borland was still good the last time I
used
>>> it) and how they're set up, though, so I can't just say that it WILL
>work
>>> for you based on the fact that it's Borland.
>>>
>>> HOWEVER -- if you're declaring a variable outside of any struct,
>>> function, or whatever, then "static" is telling the compiler about
who
>>> can see the variable, not whether the variable is writable (and thus
in
>>> RAM) or not.
>>>
>>> Here's what SHOULD happen in most embedded systems, in C or C++, if
you
>>> declare a variable outside of any struct, function, or whatever:
>>>
>>> // "whatever" gets put in read-only memory, and is visible outside of
>>> // the resulting object file
>>> const sometype whatever = <inital value>;
>>>
>>> // "whatever" gets put in read-only memory, and is only visible to
>>> // things within the C file:
>>> const static sometype whatever = <initial value>;
>>>
>>> // "whatever" gets put in RAM, is visible outside of
>>> // the resulting object file, and (if the tools are set
>>> // up correctly) filled with 0 bytes:
>>> sometype whatever;
>>>
>>> // "whatever" gets put in RAM, is only visible to
>>> // things within the C file, and (if the tools are set
>>> // up correctly) filled with 0 bytes:
>>> static sometype whatever;
>>>
>>> HTH
>>>
>>> If David Brown says that I'm wrong, just fill in a resigned sigh from
me
>>> and believe what he says.
>>>
>>
>> That's my cue for the nit-pick!  Your explanation is a good start, but
>> there are a couple of other points that I think are worth mentioning.
>>
>> It is not clear if the OP is actually using C or C++ (his compiler
>> supports both).  But in the case of
>>
>> 	const sometype whatever = <initial value>;
>>
>> there is a difference.  In C, the "whatever" has external linkage by
>> default - it is visible outside of the current object file, assuming
>> there is a matching "extern" declaration.  In C++, "whatever" has
>> internal linkage by default - it acts like "static const", unless
there
>> is a matching "extern" declaration visible in the defining translation
>unit.
>>
>> (The external visibility does not affect whether the object is put in
>> read-only or writeable memory, of course.)
>>
>> Personally, I always make my file-level functions and data either
>> explicitly "static" (even in C++, in order to be consistent with my C
>> code), unless it has to be externally visible - in which case there is
>> always an "extern" declaration in the module's header file which is
>> #include'd by both the defining module and other modules that use it.
>> That keeps everything clear and consistent.
>>
>> And I prefer to write "static const" rather than "const static" - the
>> compiler accepts both, of course, but I am more fussy!
>>
>>
>> Also note that when you make something "const", the compiler/linker
does
>> not have to put it into read-only memory.  It /may/ put it in
read-only
>> memory, and any attempt to change it in the program is undefined
>> behaviour, but it could equally well use ram.  On a PC, for example,
it
>> will go in ram - but it will be put in a different segment from
>> read-write memory, and the segment will be marked read only.  On an
AVR
>> (which has different cpu instructions for accessing flash and ram),
>> const data is usually put in RAM so that it can be accessed using the
>> same instructions as non-const data.  We don't know enough about the
>> OP's system to know where static const data would end up.
>>
>> And of course if the compiler feels it doesn't actually /need/ to put
>> static const data in memory, due to the way it is used (or not used),
it
>> will not put it in any memory.
>
>
>The OP mentioned Borland C and Intel 80C186 - something I used much
>about a quarter century ago.
>
>The Borland toolset produces 16 bit DOS .exe files, which are segment-
>relocatable. There is a need for a tool that makes absolute binary
>images from the .exe files. I used Paradigm Locate for the conversion.
>
>The Locate determines where a segment group goes, and its configuration
>has the final say for the fate of a block of the memory image.
>
>----
>
>For memory allocation, my vote goes for the static block. In all
>dynamic schemes, there is a difficult situation if the allocation
>goes awry, and many embedded systems have no way to tell what
>happened.
>
>I guess that the erase block size of the flash is 8 kB, as the
>OP was talking about changing a few bytes in it. I'd be careful
>and first copy the contents of the block to a spare block in the
>flash, and only after that erase the target for re-write.
>
>-- 
>
>-TV


Thanks TV for your input. 
So, changing the adj files would define how the RAM is being used up? "And
thus determine where the block goes" you mean into RAM/stack/ ROM?

Also a question, why do you think this needs to be copied to flash? to
save the data in case of a failure/ sudden power loss I believe?  
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23513

FromTauno Voipio <tauno.voipio@notused.fi.invalid>
Date2016-04-05 22:46 +0300
Message-ID<ne14gh$9v$1@dont-email.me>
In reply to#23507
On 5.4.16 19:54, srao wrote:
>> On 5.4.16 09:17, David Brown wrote:
>>> On 04/04/16 19:34, Tim Wescott wrote:
>>>> On Mon, 04 Apr 2016 12:09:53 -0500, srao wrote:
>>>>
>>>>>> On Fri, 01 Apr 2016 19:37:22 -0500, srao wrote:
>>>>>>
>>>>>>> I need to use Copy and 8K block of data (from a parameter block
>>>>> address
>>>>>>> in flash) to RAM, modify data at a particular offset and copy the
>>>>>>> contents back to flash. The size of the RAM is 256K.  I believe
>>>>> dynamic
>>>>>>> memory allocation with heap (using a pointer)should work for this?
>>>>> Would
>>>>>>> like to know if this would be the right way togo?
>>>>>>> Note: Please notify if any detail seems missing.
>>>>>>
>>>>>> A general description of what you're doing would be useful.
>>>>>>
>>>>>> If it's an embedded system and it has to run forever, using the
> heap
>> is
>>>>>> probably a bad idea (Google "heap fragmentation").  Truly paranoid*
>>>>>> embedded engineers would allocate the block statically unless that
>> makes
>>>>>
>>>>>> the system run out of RAM.  If they did NOT allocate it statically,
>> then
>>>>>
>>>>>> they would ask themselves if they have enough memory in the first
>> place.
>>>>>>
>>>>>> * In embedded, "paranoid" often means "successful"
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>>>>
>>>>> Also,
>>>>>
>>>>> Would static allocation utilize RAM space? I am using this for an
>>>>> embedded application which has to read data out from hardware, store
> it
>>>>> in RAM and modify the field.
>>>>>
>>>>> The RAM here is not part of processor.A separate flashchip  has
>>>>> boot+flash+ RAM region  which the application uses. C++ borland
>> compiler
>>>>> in use.  Does static memory allocation use space out of RAM? Or does
> it
>>>>> depend on the compiler?
>>>>
>>>> I believe that you are asking if using the "static" keyword in some C
> or
>> C
>>>> ++ code would cause the tools to put the space in RAM.
>>>>
>>>> The answer is that if the tools are working correctly, and if the
> space
>>>> is not declared as "const", then yes.  The tools working correctly
>>>> depends on both the tools (Borland was still good the last time I
> used
>>>> it) and how they're set up, though, so I can't just say that it WILL
>> work
>>>> for you based on the fact that it's Borland.
>>>>
>>>> HOWEVER -- if you're declaring a variable outside of any struct,
>>>> function, or whatever, then "static" is telling the compiler about
> who
>>>> can see the variable, not whether the variable is writable (and thus
> in
>>>> RAM) or not.
>>>>
>>>> Here's what SHOULD happen in most embedded systems, in C or C++, if
> you
>>>> declare a variable outside of any struct, function, or whatever:
>>>>
>>>> // "whatever" gets put in read-only memory, and is visible outside of
>>>> // the resulting object file
>>>> const sometype whatever = <inital value>;
>>>>
>>>> // "whatever" gets put in read-only memory, and is only visible to
>>>> // things within the C file:
>>>> const static sometype whatever = <initial value>;
>>>>
>>>> // "whatever" gets put in RAM, is visible outside of
>>>> // the resulting object file, and (if the tools are set
>>>> // up correctly) filled with 0 bytes:
>>>> sometype whatever;
>>>>
>>>> // "whatever" gets put in RAM, is only visible to
>>>> // things within the C file, and (if the tools are set
>>>> // up correctly) filled with 0 bytes:
>>>> static sometype whatever;
>>>>
>>>> HTH
>>>>
>>>> If David Brown says that I'm wrong, just fill in a resigned sigh from
> me
>>>> and believe what he says.
>>>>
>>>
>>> That's my cue for the nit-pick!  Your explanation is a good start, but
>>> there are a couple of other points that I think are worth mentioning.
>>>
>>> It is not clear if the OP is actually using C or C++ (his compiler
>>> supports both).  But in the case of
>>>
>>> 	const sometype whatever = <initial value>;
>>>
>>> there is a difference.  In C, the "whatever" has external linkage by
>>> default - it is visible outside of the current object file, assuming
>>> there is a matching "extern" declaration.  In C++, "whatever" has
>>> internal linkage by default - it acts like "static const", unless
> there
>>> is a matching "extern" declaration visible in the defining translation
>> unit.
>>>
>>> (The external visibility does not affect whether the object is put in
>>> read-only or writeable memory, of course.)
>>>
>>> Personally, I always make my file-level functions and data either
>>> explicitly "static" (even in C++, in order to be consistent with my C
>>> code), unless it has to be externally visible - in which case there is
>>> always an "extern" declaration in the module's header file which is
>>> #include'd by both the defining module and other modules that use it.
>>> That keeps everything clear and consistent.
>>>
>>> And I prefer to write "static const" rather than "const static" - the
>>> compiler accepts both, of course, but I am more fussy!
>>>
>>>
>>> Also note that when you make something "const", the compiler/linker
> does
>>> not have to put it into read-only memory.  It /may/ put it in
> read-only
>>> memory, and any attempt to change it in the program is undefined
>>> behaviour, but it could equally well use ram.  On a PC, for example,
> it
>>> will go in ram - but it will be put in a different segment from
>>> read-write memory, and the segment will be marked read only.  On an
> AVR
>>> (which has different cpu instructions for accessing flash and ram),
>>> const data is usually put in RAM so that it can be accessed using the
>>> same instructions as non-const data.  We don't know enough about the
>>> OP's system to know where static const data would end up.
>>>
>>> And of course if the compiler feels it doesn't actually /need/ to put
>>> static const data in memory, due to the way it is used (or not used),
> it
>>> will not put it in any memory.
>>
>>
>> The OP mentioned Borland C and Intel 80C186 - something I used much
>> about a quarter century ago.
>>
>> The Borland toolset produces 16 bit DOS .exe files, which are segment-
>> relocatable. There is a need for a tool that makes absolute binary
>> images from the .exe files. I used Paradigm Locate for the conversion.
>>
>> The Locate determines where a segment group goes, and its configuration
>> has the final say for the fate of a block of the memory image.
>>
>> ----
>>
>> For memory allocation, my vote goes for the static block. In all
>> dynamic schemes, there is a difficult situation if the allocation
>> goes awry, and many embedded systems have no way to tell what
>> happened.
>>
>> I guess that the erase block size of the flash is 8 kB, as the
>> OP was talking about changing a few bytes in it. I'd be careful
>> and first copy the contents of the block to a spare block in the
>> flash, and only after that erase the target for re-write.
>>
>> --
>>
>> -TV
>
>
> Thanks TV for your input.
> So, changing the adj files would define how the RAM is being used up? "And
> thus determine where the block goes" you mean into RAM/stack/ ROM?
>
> Also a question, why do you think this needs to be copied to flash? to
> save the data in case of a failure/ sudden power loss I believe?


You did not respond to the questions:
  - is the processor an Intel 80C186/80C188?
  - is the compiler Borland C (version?) ?
  - which is the locating tool you use for refining the .exe?

I do not recall any adj files in the toolset I used years ago,
but my memory may leak in a quarter century.

My recommedation to copy the image to a back corner of flash
is just for the situation when something goes awry (and sure
it will!). First do the code to do it and verify that you can
reliably make the copy and only after that start on the code
for erasing, modifying and rewriting the original loaction.
It is much easier to recover if you have a backup.

-- 

-TV (Tauno Voipio, older MSEE)

[toc] | [prev] | [next] | [standalone]


#23519

From"srao" <109468@EmbeddedRelated>
Date2016-04-05 18:21 -0500
Message-ID<Rc6dnZkEnL4S1ZnKnZ2dnUU7-QXNnZ2d@giganews.com>
In reply to#23513
>>> The OP mentioned Borland C and Intel 80C186 - something I used much
>>> about a quarter century ago.
>>>
>>> The Borland toolset produces 16 bit DOS .exe files, which are
segment-
>>> relocatable. There is a need for a tool that makes absolute binary
>>> images from the .exe files. I used Paradigm Locate for the
conversion.
>>>
>>> The Locate determines where a segment group goes, and its
configuration
>>> has the final say for the fate of a block of the memory image.
>>>
>>> ----
>>>
>>> For memory allocation, my vote goes for the static block. In all
>>> dynamic schemes, there is a difficult situation if the allocation
>>> goes awry, and many embedded systems have no way to tell what
>>> happened.
>>>
>>> I guess that the erase block size of the flash is 8 kB, as the
>>> OP was talking about changing a few bytes in it. I'd be careful
>>> and first copy the contents of the block to a spare block in the
>>> flash, and only after that erase the target for re-write.
>>>
>>> --
>>>
>>> -TV
>>
>>
>> Thanks TV for your input.
>> So, changing the adj files would define how the RAM is being used up?
>"And
>> thus determine where the block goes" you mean into RAM/stack/ ROM?
>>
>> Also a question, why do you think this needs to be copied to flash? to
>> save the data in case of a failure/ sudden power loss I believe?
>
>
>You did not respond to the questions:
>  - is the processor an Intel 80C186/80C188?
>  - is the compiler Borland C (version?) ?
>  - which is the locating tool you use for refining the .exe?
>
>I do not recall any adj files in the toolset I used years ago,
>but my memory may leak in a quarter century.
>
>My recommedation to copy the image to a back corner of flash
>is just for the situation when something goes awry (and sure
>it will!). First do the code to do it and verify that you can
>reliably make the copy and only after that start on the code
>for erasing, modifying and rewriting the original loaction.
>It is much easier to recover if you have a backup.
>
>-- 
>
>-TV (Tauno Voipio, older MSEE)


yes its an Intel 80c188
Boarland C++ 4.5
Paradigm LOCATE is the tool used. 

Yeah, even i agree a backup is essential and good way to do it.   
 
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23521

FromReinhardt Behm <rbehm@hushmail.com>
Date2016-04-06 12:58 +0800
Message-ID<ne24qn$1u8$1@dont-email.me>
In reply to#23519
srao wrote:

> yes its an Intel 80c188
> Boarland C++ 4.5
> Paradigm LOCATE is the tool used.
> 
> Yeah, even i agree a backup is essential and good way to do it.

But that is only one half  of the solution. You also need some means to 
detect if you should copy back from the backup. 
If or example during erase/modify/write of the flash segment you have a 
power loss, does your system start safely with the flash segment corrupted? 
Can you detect this corruption? 

-- 
Reinhardt

[toc] | [prev] | [next] | [standalone]


#23537

From"srao" <109468@EmbeddedRelated>
Date2016-04-06 11:57 -0500
Message-ID<Q5KdnRtvIuOJ3ZjKnZ2dnUU7-LvNnZ2d@giganews.com>
In reply to#23519
>>>> The OP mentioned Borland C and Intel 80C186 - something I used much
>>>> about a quarter century ago.
>>>>
>>>> The Borland toolset produces 16 bit DOS .exe files, which are
>segment-
>>>> relocatable. There is a need for a tool that makes absolute binary
>>>> images from the .exe files. I used Paradigm Locate for the
>conversion.
>>>>
>>>> The Locate determines where a segment group goes, and its
>configuration
>>>> has the final say for the fate of a block of the memory image.
>>>>
>>>> ----
>>>>
>>>> For memory allocation, my vote goes for the static block. In all
>>>> dynamic schemes, there is a difficult situation if the allocation
>>>> goes awry, and many embedded systems have no way to tell what
>>>> happened.
>>>>
>>>> I guess that the erase block size of the flash is 8 kB, as the
>>>> OP was talking about changing a few bytes in it. I'd be careful
>>>> and first copy the contents of the block to a spare block in the
>>>> flash, and only after that erase the target for re-write.
>>>>
>>>> --
>>>>
>>>> -TV
>>>
>>>
>>> Thanks TV for your input.
>>> So, changing the adj files would define how the RAM is being used up?
>>"And
>>> thus determine where the block goes" you mean into RAM/stack/ ROM?
>>>
>>> Also a question, why do you think this needs to be copied to flash?
to
>>> save the data in case of a failure/ sudden power loss I believe?
>>
>>
>>You did not respond to the questions:
>>  - is the processor an Intel 80C186/80C188?
>>  - is the compiler Borland C (version?) ?
>>  - which is the locating tool you use for refining the .exe?
>>
>>I do not recall any adj files in the toolset I used years ago,
>>but my memory may leak in a quarter century.
>>
>>My recommedation to copy the image to a back corner of flash
>>is just for the situation when something goes awry (and sure
>>it will!). First do the code to do it and verify that you can
>>reliably make the copy and only after that start on the code
>>for erasing, modifying and rewriting the original loaction.
>>It is much easier to recover if you have a backup.
>>
>>-- 
>>
>>-TV (Tauno Voipio, older MSEE)
>
>
>yes its an Intel 80c188
>Boarland C++ 4.5
>Paradigm LOCATE is the tool used. 
>
>Yeah, even i agree a backup is essential and good way to do it.   
> 
>---------------------------------------
>Posted through http://www.EmbeddedRelated.com

TV ,
Would you know where/how to figure out how Paragdigm locate works with the
LOC file and adj, cfg files to create the image. Any particular
information source on this tool ? 
---------------------------------------
Posted through http://www.EmbeddedRelated.com

[toc] | [prev] | [next] | [standalone]


#23541

FromDave Nadler <drn@nadler.com>
Date2016-04-06 10:20 -0700
Message-ID<1a66c451-c2b1-4c34-9d31-7d005463a317@googlegroups.com>
In reply to#23537
On Wednesday, April 6, 2016 at 12:58:00 PM UTC-4, srao wrote:
> TV ,
> Would you know where/how to figure out how Paragdigm locate works with the
> LOC file and adj, cfg files to create the image. Any particular
> information source on this tool ? 

See the excellent, detailed Locate reference manual that was provided to
any legitimate purchaser of the tool.....

[toc] | [prev] | [next] | [standalone]


#23503

FromTim Wescott <tim@seemywebsite.com>
Date2016-04-05 11:04 -0500
Message-ID<noWdnbuTALxsfJ7KnZ2dnUU7-T-dnZ2d@giganews.com>
In reply to#23495
On Tue, 05 Apr 2016 08:17:06 +0200, David Brown wrote:

> On 04/04/16 19:34, Tim Wescott wrote:

>> Here's what SHOULD happen in most embedded systems, in C or C++, if you
>> declare a variable outside of any struct, function, or whatever:
>> 
<< snip >>
 
> Also note that when you make something "const", the compiler/linker does
> not have to put it into read-only memory.  It /may/ put it in read-only
> memory, and any attempt to change it in the program is undefined
> behaviour, but it could equally well use ram.  On a PC, for example, it
> will go in ram - but it will be put in a different segment from
> read-write memory, and the segment will be marked read only.  On an AVR
> (which has different cpu instructions for accessing flash and ram),
> const data is usually put in RAM so that it can be accessed using the
> same instructions as non-const data.  We don't know enough about the
> OP's system to know where static const data would end up.
> 
> And of course if the compiler feels it doesn't actually /need/ to put
> static const data in memory, due to the way it is used (or not used), it
> will not put it in any memory.

Good point, but note the weasel-wording in my post: "should", meaning, in 
this case, "is morally obliged", not "can be expected".

One of the reasons I Really Like using the el-cheapo Cortex parts that 
are out now is that it's very easy to set up the tool chain to do what I 
think it should do (like putting const in some sort of ROM).

I really hate working with processors that need a different flavor of 
fetch to read from program or data memory.  I'll put up with it in a DSP, 
because you're trading speed for awkwardness, but in a general 8-bitter 
-- well, the Cortex M0 core is mighty nice.

-- 
www.wescottdesign.com

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.arch.embedded


csiph-web