Author Topic: Checking Amount Of Free Memory  (Read 4264 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
Checking Amount Of Free Memory
« on: December 15, 2008, 08:22:56 PM »
Hi Mark,
 Is there a way within utasker to check the amount of free RAM, and even code size during Run Time. I would like to  display amount of free Ram, and size of code at startup.

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3021
    • View Profile
    • uTasker
Re: Checking Amount Of Free Memory
« Reply #1 on: December 15, 2008, 09:07:40 PM »
Hi Neil

You can use fnHeapFree(), fnHeapAvailable() and fnStackFree() to get the RAM details (see fnDisplaySystemMemory() in debug.c which displays them).

In the map file you should see the program size including consts (.text and .rodata). There may be a variable which is available from the linker with the value that you are looking for - if not ask in the Freescale CW forum.

I just checked: It looks as though the standard linker file creates the variable ___DATA_ROM. It is also appears in the map at the end of the consts. If you use something like the following in your code it may work:

extern unsigned char *___DATA_ROM;

and the &___DATA_ROM may be the last FLASH location used by the code. Since the FLASH starts at 0 it is also equal to the code size.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
Re: Checking Amount Of Free Memory
« Reply #2 on: December 15, 2008, 10:13:10 PM »
Hi Mark,
  Thanks for that, cheers

Neil

Offline neil

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
Re: Checking Amount Of Free Memory
« Reply #3 on: December 15, 2008, 10:19:22 PM »
Hi mark,
  Just had a look at my code. And doesnt seem to be much free Ram left. How much does the standard utasker use?

On the ethernet side, I only have TCP/IP, no ftp,DNS etc..

Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3021
    • View Profile
    • uTasker
Re: Checking Amount Of Free Memory
« Reply #4 on: December 16, 2008, 12:54:46 AM »
Hi Neil

That depends also on the processor used.

As long as remaining heap is >0 it is fine. After everything has been initialised (and used), any remaining heap can be removed from the value of OUR_HEAP_SIZE (in config.h) and then becomes stack space. As long as the stack value never reduces to zero it is also OK.

To see what is using heap set break points in uMalloc() and uMallocAlign() - in uMalloc.c. Note the caller and the chunk size to know exactly where it is being used and you can decide whether some settings can be adjusted to reduce it (eg. the Ethernet tx and rx buffers are often set there and the number is definable). The UART buffers are there . also user definable. This is easier in the simulator.

The project only uses a handful of variables which are not on heap (20..100 or so depending on the configuration).

Regards

Mark