如何在FreeRTOS中更改任务的最大可用堆大小? [英] How can I change maximum available heap size for a task in FreeRTOS?

查看:746
本文介绍了如何在FreeRTOS中更改任务的最大可用堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式在任务内创建元素列表:

I'm creating a list of elements inside a task in the following way:

        l = (dllist*)pvPortMalloc(sizeof(dllist));

dllist是32字节大. 我的嵌入式系统具有60kB SRAM,因此我希望系统可以轻松处理我的200个元素列表.我发现为8个元素分配空间后,系统在第9个malloc函数调用(256byte +)时崩溃.

dllist is 32 byte big. My embedded system has 60kB SRAM so I expected my 200 element list can be handled easily by the system. I found out that after allocating space for 8 elements the system is crashing on the 9th malloc function call (256byte+).

如果可能的话,在哪里可以更改freeRTOS内的堆大小? 我可以以某种方式请求堆大小的当前状态吗? 我在文档中找不到此信息,因此希望有人可以对此提供一些见识. 预先感谢!

If possible, where can I change the heap size inside freeRTOS? Can I somehow request the current status of heap size? I couldn't find this information in the documentation so I hope somebody can provide some insight in this matter. Thanks in advance!

推荐答案

(是-FreeRTOS pvPortMalloc()返回void *.)

(Yes - FreeRTOS pvPortMalloc() returns void*.)

如果您有60K的SRAM,并且configTOTAL_HEAP_SIZE很大,那么分配256个字节后除非您几乎没有剩余的堆,否则不太可能会用完堆.许多FreeRTOS演示程序将一直创建对象,直到使用完所有堆为止,因此,如果您的应用程序基于其中之一,那么在执行代码之前,您的堆就很贫乏了.您可能还通过创建具有大量堆栈的任务来完成诸如耗尽堆空间负载之类的事情.

If you have 60K of SRAM, and configTOTAL_HEAP_SIZE is large, then it is unlikely you are going to run out of heap after allocating 256 bytes unless you had hardly any heap remaining before hand. Many FreeRTOS demos will just keep creating objects until all the heap is used, so if your application is based on one of those, then you would be low on heap before your code executed. You may have also done something like use up loads of heap space by creating tasks with huge stacks.

heap_4和heap_5将合并相邻的块,这将在实际中最大程度地减少碎片,但是我认为这不是您的问题-尤其是因为您没有提到在任何地方释放任何东西.

heap_4 and heap_5 will combine adjacent blocks, which will minimise fragmentation as far as practical, but I don't think that will be your problem - especially as you don't mention freeing anything anywhere.

除非使用的是heap_3.c(这只会使标准C库的malloc和空闲线程安全),否则可以调用xPortGetFreeHeapSize()来查看有多少空闲堆.您可能还可以使用xPortGetMinimumEverFreeHeapSize()来查询您耗尽堆的距离.详细信息: http://www.freertos.org/a00111.html

Unless you are using heap_3.c (which just makes the standard C library malloc and free thread safe) you can call xPortGetFreeHeapSize() to see how much free heap you have. You may also have xPortGetMinimumEverFreeHeapSize() available to query how close you have ever come to running out of heap. More information: http://www.freertos.org/a00111.html

您还可以定义一个失败的malloc()挂钩( http://www.freertos.org/a00016 .html )以获取pvPortMalloc()返回NULL的即时通知.

You could also define a malloc() failed hook (http://www.freertos.org/a00016.html) to get instant notification of pvPortMalloc() returning NULL.

这篇关于如何在FreeRTOS中更改任务的最大可用堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆