使用二值信号量过程中,刚开始程序还是正常运行,一段时间后出现了死机。通过仿真发现程序卡在了 xQueueSemaphoreTake 函数的 configASSERT( ( pxQueue ) )中。
通过查看 xQueueSemaphoreTake 函数可知, configASSERT( ( pxQueue ) )主要是用于断言QueueHandle_t xQueue是否为NULL,卡死在这里说明程序运行中传入了NULL句柄。
BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )
{
BaseType_t xEntryTimeSet = pdFALSE;
TimeOut_t xTimeOut;
Queue_t * const pxQueue = xQueue;
#if( configUSE_MUTEXES == 1 )
BaseType_t xInheritanceOccurred = pdFALSE;
#endif
/* Check the queue pointer is not NULL. */
configASSERT( ( pxQueue ) );
/* Check this really is a semaphore, in which case the item size will be
0. */
configASSERT( pxQueue->uxItemSize == 0 );
/* Cannot block if the scheduler is suspended. */
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTic

程序在运行一段时间后因xQueueSemaphoreTake函数卡死导致死机,问题出在传入了NULL信号量句柄。经过分析,发现原因在于设备低功耗模式下反复初始化信号量,造成内存资源耗尽,解决方案是检查并避免重复创建信号量,或者在不再使用时正确删除信号量,防止内存泄漏。

180

被折叠的 条评论
为什么被折叠?



