Lighweight memory pool

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lighweight memory pool

Jump to solution
694 Views
vines
Contributor III

Hi All,

This might seem basic to everyone. But what can cause the problem LWMEM_POOL_INVALID? Eg memory not enough in heap, stack, etc. I hope I don't get a reply "read the manual". I did, I guess my comprehension is not that good (sorry). Anyway, I will appreciate it if you could explain this.

Thanks.

0 Kudos
1 Solution
360 Views
Martin_
NXP Employee
NXP Employee

Hi vines,

The source code for this can be found in:

${MQX_ROOT}\mqx\source\kernel\lwmem.c

LWMEM_POOL_INVALID is returned from _lwmem_alloc_ functions() or from _lwmem_test(). Condition looks like this:

if (mem_pool_ptr->VALID != LWMEM_POOL_VALID)

    {

        _task_set_error(MQX_LWMEM_POOL_INVALID);

        return (NULL);

    } /* Endif */

So the VALID bit in the LWMEM_POOL_STRUCT is not correct. You don't indicate which function would cause this. (during allocation, either from the system pool or from a private pool ? or is this during runtime call to lwmem_test() ?)

If this occurs in runtime, in order to debug this, you can put data watchpoint to the address of the pool_ptr->VALID. CPU would enter debug mode upon a CPU write access to this address. This is important note - only if CPU store instruction writes to this address. As there exist more crossbar switch master ports on Kinetis (like usb controller, DMA) it is also possible, that one of these masters writes data to the address of pool_ptr->VALID. For example, you schedule a usb transaction, for which you have allocated statically an application buffer of size 100 bytes, but the usb will receive 200 bytes. As it is 100 bytes off it is overwriting some other memory.

View solution in original post

0 Kudos
2 Replies
361 Views
Martin_
NXP Employee
NXP Employee

Hi vines,

The source code for this can be found in:

${MQX_ROOT}\mqx\source\kernel\lwmem.c

LWMEM_POOL_INVALID is returned from _lwmem_alloc_ functions() or from _lwmem_test(). Condition looks like this:

if (mem_pool_ptr->VALID != LWMEM_POOL_VALID)

    {

        _task_set_error(MQX_LWMEM_POOL_INVALID);

        return (NULL);

    } /* Endif */

So the VALID bit in the LWMEM_POOL_STRUCT is not correct. You don't indicate which function would cause this. (during allocation, either from the system pool or from a private pool ? or is this during runtime call to lwmem_test() ?)

If this occurs in runtime, in order to debug this, you can put data watchpoint to the address of the pool_ptr->VALID. CPU would enter debug mode upon a CPU write access to this address. This is important note - only if CPU store instruction writes to this address. As there exist more crossbar switch master ports on Kinetis (like usb controller, DMA) it is also possible, that one of these masters writes data to the address of pool_ptr->VALID. For example, you schedule a usb transaction, for which you have allocated statically an application buffer of size 100 bytes, but the usb will receive 200 bytes. As it is 100 bytes off it is overwriting some other memory.

0 Kudos
360 Views
vines
Contributor III

Thanks Martin.

Just for info

The problem was I forgot to remove a free() function where as the malloc was already remove. Thus it is trying to free up memory to a space that is not even allocated.

0 Kudos