This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SYSBIOS 软中断中 malloc 失败

Other Parts Discussed in Thread: SYSBIOS

在sysbios调试时,在Task 中进行动态内存分配,程序运行正常,而当我将同样的模块放入软中断中调用时,程序运行到malloc (or  Memory_alloc())时,程序就死了,提示:ti.sysbios.gates.GateMutex:line 97 assertion failure:A badcontext: bad calling context. See gateMutex API doc for detail 。

不知何解?麻烦专家指导一下,谢谢

这里系统默认的heap开的挺大,肯定足够一次malloc的分配

  • Heapmem默认会使用GateMutex,这样允许多个task同时使用一个heap。但是在SWI及HWI中不允许调用GateMutex,所以只有在task中电压memory alloc才是安全的。

    具体可以参考如下帖子的解释:

    sysbios heap:http://e2e.ti.com/support/embedded/tirtos/f/355/p/224914/791851.aspx#791851

    http://e2e.ti.com/support/embedded/tirtos/f/355/t/238059.aspx

  • 谢谢。之前测试时也就的task中可以malloc.

    bios 在默认的情况下,打开 GateMutex,后来我将其设置成 NoBlocking  这样在软中断中malloc成功了。这样做的话,有啥弊端 ?

  • 你为何一定要在swi中分配内存呢,起始完全可以在swi中触发一个任务然后在执行相应的操作。