Author Topic: Max number of new Tasks  (Read 3041 times)

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Max number of new Tasks
« on: May 09, 2020, 04:47:38 PM »
Hi,
is there a max number of new tasks that can be added to the project?

Apparently if I write more than 6 new tasks and add them to TaskConfig.h, even if I execute only 1 of them (as I always do) then my microcontroller (KL03) doesn't work any more.
I'm not sure if it is a matter of memory since this happens even when the 7th task is an empty function. As I remove the 7th task things go back to normal

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Max number of new Tasks
« Reply #1 on: May 09, 2020, 05:04:48 PM »
Hi

Each time you add a task it needs memory for its operation (for its entry in the task table, for its input queue (if used) and timer queue (if used)). The input queue size if definable and so each task's memory requirement is not necessarily fixed.
Tasks and their queues are located in HEAP.

This means that limits are probably due to memory constraints. The KL03 is one of the smallest chips in terms of memory resources so it fairly limited - you need to observe the amount of HEAP needed by each new task and ensure that the HEAP size can accept it (ex. set breakpoints in uMalloc() to see all allocations and sizes). Also you need to be aware of the memory use by static system variables (eg. see in map file), whereby the end of variable space is where the HEAP starts. This gives you the HEAP end (end of variables + heap size [adequate for all system use]) and finally you need to ensure that the processor's working stack space is adequate. That is, the space from the top of RAM and the end of heap is not so small that the processor's stack doesn't have space to do what it needs without clobbering variables towards the end of HEAP.

Therefore when using low memory parts (and generally too) it is very important to always have a very clear picture of RAM usage so that the effects of adding further variables or HEAP consumers is known and the limits of possibilities are also clearly understood. This way you can get the most out of designs (and keep operation safe) but resources need to be used carefully and there are physical limits that may well be hit that restrict the ability to add further functionality.

Regards

Mark

Offline Raffaele

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Max number of new Tasks
« Reply #2 on: May 09, 2020, 05:17:56 PM »
Thanks Mark,

very helpful!