alloc task stack in mqx

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

alloc task stack in mqx

跳至解决方案
2,283 次查看
master_szumi
Contributor III

when i'm using _mem_alloc(size)

mqx allocates memory over tasks stacks

 

I want allocate memory from secify task stack (task with _mem_alloc execute). Is it possible?

 

How check how many free ram memory left in IAR using MQX TAD plugin?

 

 

0 项奖励
回复
1 解答
1,684 次查看
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

Declaring the variable within the task will use the task stack.

Using the _mem_alloc() get memory from the heap.

Declaring a variable "static" will place it in the BSS space.

 

Note that the Kinetis family with 128KB SRAM actually has that memory in two 64KB blocks.  The architecture doesn't let you allocate variable across the 0x2000_0000 boundary.  So to declare a 64KB or larger memory block needs to be parsed/divided into smaller blocks.  I've attached ".gif" to show the heap used for two big buffers.  I've also attached the source file I used to play around on the TWRK60.

 

Hope this helps.

Regards,

David

在原帖中查看解决方案

0 项奖励
回复
5 回复数
1,684 次查看
PhilH
Contributor II

_mem_alloc() should not alloc over your task stacks.  One possibility is that the task that is calling _mem_alloc() to allocate the memory for the task stacks might be exiting.  The MQX behavior on a task exiting is to free all memory it has allocated.  Find out what task is initializing your other tasks and make sure it is not exiting.

0 项奖励
回复
1,684 次查看
master_szumi
Contributor III

my task is very simply:

 

void Easy_Task(uint_32 dummy)

{

  void * mem = _mem_alloc(32);
  _mem_free(mem);

}

 

In stack usage I see that stack for this task is from 0x...d490 ti 0x...d590 (256 bytes)

and my local variable address is 0x...d5ac so its over stack!

 

 

 

0 项奖励
回复
1,684 次查看
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

The _mem_alloc() function call is getting space from the system heap and not from the task stack.

Hope this helps.

Regards,

David

 

0 项奖励
回复
1,684 次查看
master_szumi
Contributor III

Ok.

 

But is any chance (method) to get it from task stack?

 

 

Other problem:

 

Im using k60n512 with 128kB ram. I'm using _mem_alloc() to alloc memory but when I try alloc more than 64kB function gives me NULL (so mqx can not allocate) - I dont know why? I think that simple task can not takes other 64kb! Where problem is?

 

 

0 项奖励
回复
1,685 次查看
DavidS
NXP Employee
NXP Employee

Hi Master_szumi,

Declaring the variable within the task will use the task stack.

Using the _mem_alloc() get memory from the heap.

Declaring a variable "static" will place it in the BSS space.

 

Note that the Kinetis family with 128KB SRAM actually has that memory in two 64KB blocks.  The architecture doesn't let you allocate variable across the 0x2000_0000 boundary.  So to declare a 64KB or larger memory block needs to be parsed/divided into smaller blocks.  I've attached ".gif" to show the heap used for two big buffers.  I've also attached the source file I used to play around on the TWRK60.

 

Hope this helps.

Regards,

David

0 项奖励
回复