Reply by Anders Lindgren October 20, 20052005-10-20
Pranav wrote:

> The malloc() returns an error. Is there any way I
can force malloc() 
> or any other technique to allocate a chunk of memory from particular 
> address ? 

Well, that is something that isn't C standard so every supplier has 
their own ways of doing this.

If you're using the IAR tools you can use:

1) The @ operator (or pragma location), e.g.
     char my_array[1000] @ 0x1000;

2) Use the linker to place a segment at a speific memory location.
    You can then use the @ location again to place the array in
    that segment, or you can use the intrinsic functions __segment_begin
    and __segment_end to get the start and end of the segment.

     -- Anders Lindgren, IAR Systems
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Beginning Microcontrollers with the MSP430

Reply by Paul Curtis October 19, 20052005-10-19
Rolf, 

> you can avoid memory fragmentation by using alloca
instead of 
> malloc, but it seems that no MSP430 compiler has alloca.

alloca isn't ANSI/ISO standard and supporting it then requires a
dedicated frame pointer for any function using it.  Hence, no support
for it...

--
Paul Curtis, Rowley Associates Ltd  http://www.rowley.co.uk
CrossWorks for MSP430, ARM, AVR and now MAXQ processors

Reply by rolf...@... October 19, 20052005-10-19
Hi,

you can avoid memory fragmentation by using alloca instead of malloc,
but it seems that no MSP430 compiler has alloca.

Regards,

Rolf


msp430@msp4... schrieb am 20.10.05 00:30:13:
> 
> Malloc is good to steer clear of if possible due to memory fragmentation. 
Is there a reason for the linked list?  It sounded like you were always reading
40 samples  so wouldn't a simple static array work?  
> 
> /Bill
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> .
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 



Reply by rolf...@... October 19, 20052005-10-19
Hi,

msp430@msp4... schrieb am 19.10.05 23:33:29:
> 
> The malloc() returns an error. Is there any way I can force malloc() 
> or any other technique to allocate a chunk of memory from particular 
> address ? 

impossible; that would be cheating!
When the RAM is full there is no way to allocate a chunk of free memory
because it does not exist.
You have to use a processor with more RAM, e. g. the MSP430F1611.

Maybe there is enough RAM free and you can get the chunk of memory
by declaring a static array but that increases the risk of stack overflow.

Regards,

Rolf

 
> --- In msp430@msp4..., "Rachel Adamec"
<adamec.rachel@v...> 
> wrote:
> >
> > Pranav,
> > 
> >  
> > 
> > > Following is the code for the linked list. When I tried single 
> > > steping, I found that the memory allocation is good upto 5 nodes,

> > > but after that whole linked list is getting filled up with 
> ADC12XYZ 
> > > memory.
> > 
> > 
> > >
> > > IAR KickStart Complier does not give any error with above code, 
> my 
> > > other application runs well without any issue.
> > 
> > > #define .....
> > >
> > > struct Node
> > > {
> > > float data;
> > > struct Node *next;
> > > };
> > > struct Node *root = 0;
> > >
> > > main()
> > > {
> > > //....
> > >  int i;
> > >  root = (struct Node*)malloc(sizeof(struct Node));
> > 
> >  
> > 
> > What is the address you're getting here (use your debugger to
break 
> here and
> > look at the value of 'root'
> > 
> >  
> > 
> > If malloc() fails, the returned value will be 0x0000. - you need 
> to 'handle'
> > this error condition!
> > 
> > 
> > >  root -> data = 0;
> > >  root -> next = 0;
> > >  for(i = 0 ; i < 40 ; i++)
> > >  {
> > >    struct Node *new;
> > >    new = (struct Node*)malloc(sizeof(struct Node));
> > 
> >  
> > 
> > If you had the first malloc() return 0x0000, and this malloc() 
> return a
> > small non-zero value, then you need to change where malloc() is 
> getting
> > memory from. That would be some type of set value in one of your 
> processor's
> > definition files. It tells the compiler where RAM 'starts'.
It 
> should be
> > something like 0x0200. check this out.
> > 
> >  
> > 
> > Oh yeah, again, what if malloc() fails????? You MUST handle error 
> results or
> > you're going to get more problems than just over-writing some ADC

> values.
> > you could have major system failure.
> > 
> > 
> > >    new -> data = 0;
> > >    new -> next = root;
> > >    root = new;
> > >  }
> > >
> > > }
> > 
> > good luck.
> > 
> > 
> > Rachel Adamec
> > Norristown, PA, USA
> > 
> > 
> > 
> >  
> > 
> > 
> > 
> > 
> >
> 
> 
> 
> 
> 
> 
> 
> .
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
> 



Reply by w.se...@... October 19, 20052005-10-19
Malloc is good to steer clear of if possible due to memory fragmentation. 
Is there a reason for the linked list?  It sounded like you were always reading
40 samples  so wouldn't a simple static array work?  

/Bill









Reply by Pranav October 19, 20052005-10-19
The malloc() returns an error. Is there any way I can force malloc() 
or any other technique to allocate a chunk of memory from particular 
address ? 



--- In msp430@msp4..., "Rachel Adamec" <adamec.rachel@v...> 
wrote:
>
> Pranav,
> 
>  
> 
> > Following is the code for the linked list. When I tried single 
> > steping, I found that the memory allocation is good upto 5 nodes, 
> > but after that whole linked list is getting filled up with 
ADC12XYZ 
> > memory.
> 
> 
> >
> > IAR KickStart Complier does not give any error with above code, 
my 
> > other application runs well without any
issue.
> 
> > #define .....
> >
> > struct Node
> > {
> > float data;
> > struct Node *next;
> > };
> > struct Node *root = 0;
> >
> > main()
> > {
> > //....
> >  int i;
> >  root = (struct Node*)malloc(sizeof(struct Node));
> 
>  
> 
> What is the address you're getting here (use your debugger to break 
here and
> look at the value of 'root'
> 
>  
> 
> If malloc() fails, the returned value will be 0x0000. - you need 
to 'handle'
> this error condition!
> 
> 
> >  root -> data = 0;
> >  root -> next = 0;
> >  for(i = 0 ; i < 40 ; i++)
> >  {
> >    struct Node *new;
> >    new = (struct Node*)malloc(sizeof(struct Node));
> 
>  
> 
> If you had the first malloc() return 0x0000, and this malloc() 
return a
> small non-zero value, then you need to change
where malloc() is 
getting
> memory from. That would be some type of set value
in one of your 
processor's
> definition files. It tells the compiler where RAM
'starts'. It 
should be
> something like 0x0200. check this out.
> 
>  
> 
> Oh yeah, again, what if malloc() fails????? You MUST handle error 
results or
> you're going to get more problems than just
over-writing some ADC 
values.
> you could have major system failure.
> 
> 
> >    new -> data = 0;
> >    new -> next = root;
> >    root = new;
> >  }
> >
> > }
> 
> good luck.
> 
> 
> Rachel Adamec
> Norristown, PA, USA
> 
> 
> 
>  
> 
> 
> 
> 
>





Reply by Rachel Adamec October 18, 20052005-10-18
Pranav,

 

> Following is the code for the linked list. When I
tried single 
> steping, I found that the memory allocation is good upto 5 nodes, 
> but after that whole linked list is getting filled up with ADC12XYZ 
> memory.


>
> IAR KickStart Complier does not give any error with above code, my 
> other application runs well without any issue.

> #define .....
>
> struct Node
> {
> float data;
> struct Node *next;
> };
> struct Node *root = 0;
>
> main()
> {
> //....
>  int i;
>  root = (struct Node*)malloc(sizeof(struct Node));

 

What is the address you're getting here (use your debugger to break here
and
look at the value of 'root'

 

If malloc() fails, the returned value will be 0x0000. - you need to
'handle'
this error condition!


>  root -> data = 0;
>  root -> next = 0;
>  for(i = 0 ; i < 40 ; i++)
>  {
>    struct Node *new;
>    new = (struct Node*)malloc(sizeof(struct Node));

 

If you had the first malloc() return 0x0000, and this malloc() return a
small non-zero value, then you need to change where malloc() is getting
memory from. That would be some type of set value in one of your
processor's
definition files. It tells the compiler where RAM 'starts'. It should
be
something like 0x0200. check this out.

 

Oh yeah, again, what if malloc() fails????? You MUST handle error results or
you're going to get more problems than just over-writing some ADC values.
you could have major system failure.


>    new -> data = 0;
>    new -> next = root;
>    root = new;
>  }
>
> }

good luck.


Rachel Adamec
Norristown, PA, USA



 






Reply by Pranav October 18, 20052005-10-18
Hi Rachel,

Following is the code for the linked list. When I tried single 
steping, I found that the memory allocation is good upto 5 nodes, 
but after that whole linked list is getting filled up with ADC12XYZ 
memory.

IAR KickStart Complier does not give any error with above code, my 
other application runs well without any issue.

Regards,

Pranav.


#define .....

struct Node
{
float data;
struct Node *next;
};
struct Node *root = 0;

main()
{
//....
  int i;
  root = (struct Node*)malloc(sizeof(struct Node));
  root -> data = 0;
  root -> next = 0;
  for(i = 0 ; i < 40 ; i++)
  {
    struct Node *new;
    new = (struct Node*)malloc(sizeof(struct Node));
    new -> data = 0;
    new -> next = root;
    root = new;
  }

}





--- In msp430@msp4..., "Rachel Adamec" <adamec.rachel@v...> 
wrote:
>
> My guess is that you have a pointer that's getting set to 0x0000. 
That's
> normally a NULL, so if you're allocating
memory space using malloc
(), you're
> getting a NULL return value (error condition
occurred). 
> 
>  
> 
> If you statically allocate the memory ( int   buf[40];  ), you are 
not
> setting a pointer to the first location of the
buffer (   int 
*pBuf = buf;
> or   int  *pBuf = &buf[0];  )
> 
>  
> 
> That's about all the guessing I'll do without seeing some code.
> 
>  
> 
> Rachel Adamec
> 
> Norristown, PA, USA
> 
>  
> 
>  
> 
>  
> 
> From: msp430@msp4... [mailto:msp430@msp4...] On 
Behalf Of
> Pranav
> Sent: Tuesday, October 18, 2005 6:46 PM
> To: msp430@msp4...
> Subject: [msp430] Circular Linked List to process 40 bytes of data
> 
>  
> 
> *	Hi All,
> 
> I want to implement Circular Linked List with 40 nodes. I tried to 
> create the linked list in main() program, but it does not work, I 
put 
> the break point and tried to see, it gets
overlapped by the memory 
for 
> the control registers. Can any one help me ?
> 
> My application performs ADC at every 50mSec, after 40 samples are 
> acquired the data should be processed after each ADC conversion.
> 
> 
> Regards,
> 
> Pranav.
> 
> 
> 
> 
> 
> 
> 
>





Reply by Rachel Adamec October 18, 20052005-10-18
My guess is that you have a pointer that's getting set to 0x0000.
That's
normally a NULL, so if you're allocating memory space using malloc(),
you're
getting a NULL return value (error condition occurred). 

 

If you statically allocate the memory ( int   buf[40];  ), you are not
setting a pointer to the first location of the buffer (   int *pBuf = buf;
or   int  *pBuf = &buf[0];  )

 

That's about all the guessing I'll do without seeing some code.

 

Rachel Adamec

Norristown, PA, USA

 

 

 

From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of
Pranav
Sent: Tuesday, October 18, 2005 6:46 PM
To: msp430@msp4...
Subject: [msp430] Circular Linked List to process 40 bytes of data

 

*	Hi All,

I want to implement Circular Linked List with 40 nodes. I tried to 
create the linked list in main() program, but it does not work, I put 
the break point and tried to see, it gets overlapped by the memory for 
the control registers. Can any one help me ?

My application performs ADC at every 50mSec, after 40 samples are 
acquired the data should be processed after each ADC conversion.


Regards,

Pranav.









Reply by Pranav October 18, 20052005-10-18
Hi All,

I want to implement Circular Linked List with 40 nodes. I tried to 
create the linked list in main() program, but it does not work, I put 
the break point and tried to see, it gets overlapped by the memory for 
the control registers. Can any one help me ?

My application performs ADC at every 50mSec, after 40 samples are 
acquired the data should be processed after each ADC conversion.


Regards,

Pranav.