对于vListInsert函数中的信号量,FreeRTOS无限期地停留在for循环中



我正在努力理解为什么我的代码会卡在FreeRTOS的vListInsert的for循环中。我正在用gcc工具链编译器为bfin561 coreb实现FreeRTOS。

这是我得到的线索:

我用这种方式初始化信号量:

.....
 vSemaphoreCreateBinary( LED0_semaphore );
        vSemaphoreCreateBinary( LED5_semaphore );
    params[0].event = LED0_semaphore;
        params[5].event = LED5_semaphore;
....

然后在任务函数中:

static portTASK_FUNCTION(LED_blink_thread, Param)
{
        coreb_msg("start LED_blink_threadn");
    task_params_list_t *p = (task_params_list_t *)Param;
        coreb_msg("got parametersn");
        int lite = p->LED;
        xSemaphoreHandle sem = p->event;
   if (sem != (xSemaphoreHandle)0)                                     // is t
he semaphore pointer is valid                                                   
        {
            coreb_msg("semaphore pointer is validn");
                while(1)
                {
                  // Button task: sem is non-NULL, pend on it for ever        
                    while( xSemaphoreTake( sem, portMAX_DELAY ) != pdTRUE ); 
                    coreb_msg("semaphore is non-NULL SET LEDn");
                    EZKit_Set_LED(lite); // turn on a single LED passed as arg.                                 
                    while( xSemaphoreTake( sem, portMAX_DELAY ) != pdTRUE );
                    coreb_msg("semaphore is non-NULL CLEAR LEDn");
                    EZKit_Clear_LED(lite);   
.....
}

在上面的代码中,问题发生在第二个while(xSemaphoreTake(sem,portMAX_DELAY)!=pdTRUE);线

通过代码调试,我陷入了:

void vListInsert( xList *pxList, xListItem *pxNewListItem )

来自freeRTOS的:

....
for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIter ator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
                {
                    coreb_msg("iterate");
                    coreb_msg("pxIterator = %x",pxIterator);
                    coreb_msg("pxIterator->pxNext->xItemValue = %x",pxIterator->pxNext->xItemValue);
                    coreb_msg("pxIterator->pxNext = %x",pxIterator->pxNext);

            /* There is nothing to do here, we are just iterating to the                                                                           
                        wanted insertion position. */
                }
  ....

输出我得到的调试消息:

COREB: get owner of next entry:                                                 
COREB: current TCB 3d24000                                                      
COREB: pxReadyTasksLists[ uxTopReadyPriority ] = 1                              
COREB: TCB content:                                                             
COREB: top of stack: 3d25588                                                    
COREB: GenericListItem: 0                                                       
COREB: Event ListItem: 4                                                        
COREB: Priority: 6                                                              
COREB: start of stack: 3d25000                                                  
COREB: Task Name: LED tas                                                       
COREB: TCB number: 7                                                            
COREB: Task Tag: 3c06a88                                                        
COREB: trace switched in:LED tas                                                
COREB: write trace to buffer                                                    
COREB: call task hook                                                           
COREB: Task call app hook called    
COREB: Task call app hook called                                                
COREB: start LED_blink_thread                                                   
COREB: got parameters                                                           
COREB: semaphore pointer is valid                                               
COREB: start xQueueGenericReceive                                               
COREB: addr pxQueue = 3d18000                                                   
COREB: addr pxQueue->msgWait = 3d18038                                          
COREB: pxQueue Is Not Null                                                      
COREB: pxQueue->MsgW Is Not Null                                                
COREB: queue message waiting                                                    
COREB: pxQueue->pcReadFrom = 3d19000                                            
COREB: BUG dst 00000000 src 03d19000                                            
COREB: copy data from queue                                                     
COREB: just peaking is false                                                    
COREB: removing data                                                            
COREB: exit critical                                                            
COREB: semaphore is non-NULL SET LED                                            
COREB: start xQueueGenericReceive                                               
COREB: addr pxQueue = 3d18000                                                   
COREB: addr pxQueue->msgWait = 3d18038                                          
COREB: pxQueue Is Not Null         
COREB: pxQueue->MsgW Is Null                                                    
COREB: there is no data in queue                                                
COREB: The queue was empty and a block time specified                           
COREB: set timout out 0                                                         
COREB: all task suspended                                                       
COREB: prvLockQueue called                                                      
COREB: check timeout = false                                                    
COREB: queue is empty                                                           
COREB: before TaskPlaceOnEventList                                              
COREB: call vListInsert       
COREB: start list insert                                                        
COREB: xValueOfInsertion = 4                                                    
COREB: portMAX_DELAY = ffff                                                     
COREB: xValueOfInsertion != portMAX_DELAY                                       
COREB: pxNewListItem->pxNext = 3d1802c                                          
COREB: pxNewListItem->pxNext->pxPrevious = 3d24018                              
COREB: pxNewListItem->pxPrevious = 3d1802c                                      
COREB: pxIterator->pxNext = pxNewListItem                                       
COREB: pxNewListItem->pvContainer = pxList                                      
COREB: pxList->uxNumberOfItems = 1                                              
COREB: call vListRemove                                                         
COREB: list_rem px prev: 3c0cea0                                                
COREB: list_rem px next: 3d24004                                                
COREB: vTaskSuspend == 1                                                        
COREB: xTicksToWait == portMAX_DELAY             
COREB: call  vListInsertEnd                                                     
COREB: before unlock queue                                                      
COREB: task resume all failed                                                   
COREB: there is no data in queue                                                
COREB: all task suspended                                                       
COREB: prvLockQueue called                                                      
COREB: check timeout = false                                                    
COREB: queue is empty                                                           
COREB: before TaskPlaceOnEventList                                              
COREB: call vListInsert                                                         
COREB: start list insert                                                        
COREB: xValueOfInsertion = 4                                                    
COREB: portMAX_DELAY = ffff                                                     
COREB: xValueOfInsertion != portMAX_DELAY                                       
COREB: iterate                  
COREB: pxIterator = 3d1802c                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: pxNewListItem->pxNext = 3d1802c                                          
COREB: pxNewListItem->pxNext->pxPrevious = 3d24018                              
COREB: pxNewListItem->pxPrevious = 3d24018                                      
COREB: pxIterator->pxNext = pxNewListItem                                       
COREB: pxNewListItem->pvContainer = pxList                                      
COREB: pxList->uxNumberOfItems = 2                                              
COREB: call vListRemove                                                         
COREB: list_rem px prev: 3c0cf48                                                
COREB: list_rem px next: 3d24004                                                
COREB: vTaskSuspend == 1                                                        
COREB: xTicksToWait == portMAX_DELAY                                            
COREB: call  vListInsertEnd                                                     
COREB: before unlock queue                                                      
COREB: task resume all failed                                                   
COREB: there is no data in queue                                                
COREB: all task suspended                                                       
COREB: prvLockQueue called     
COREB: check timeout = false                                                    
COREB: queue is empty                                                           
COREB: before TaskPlaceOnEventList                                              
COREB: call vListInsert                                                         
COREB: start list insert                                                        
COREB: xValueOfInsertion = 4                                                    
COREB: portMAX_DELAY = ffff                                                     
COREB: xValueOfInsertion != portMAX_DELAY                                       
COREB: iterate                                                                  
COREB: pxIterator = 3d1802c                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: pxNewListItem->pxNext = 3d1802c                                          
COREB: pxNewListItem->pxNext->pxPrevious = 3d24018
COREB: pxNewListItem->pxPrevious = 3d24018                                      
COREB: pxIterator->pxNext = pxNewListItem                                       
COREB: pxNewListItem->pvContainer = pxList                                      
COREB: pxList->uxNumberOfItems = 2                                              
COREB: call vListRemove                                                         
COREB: list_rem px prev: 3c0cf48                                                
COREB: list_rem px next: 3d24004                                                
COREB: vTaskSuspend == 1                                                        
COREB: xTicksToWait == portMAX_DELAY                                            
COREB: call  vListInsertEnd                                                     
COREB: before unlock queue                                                      
COREB: task resume all failed                                                   
COREB: there is no data in queue                                                
COREB: all task suspended                                                       
COREB: prvLockQueue called                                                      
COREB: check timeout = false                                                    
COREB: queue is empty                                                           
COREB: before TaskPlaceOnEventList                                              
COREB: call vListInsert                                                         
COREB: start list insert                           
COREB: xValueOfInsertion = 4                                                    
COREB: portMAX_DELAY = ffff                                                     
COREB: xValueOfInsertion != portMAX_DELAY                                       
COREB: iterate                                                                  
COREB: pxIterator = 3d1802c                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: iterate                                                                  
COREB: pxIterator = 3d24018                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: iterate                                                                  
COREB: pxIterator = 3d24018                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: iterate                                                                  
COREB: pxIterator = 3d24018                                                     
COREB: pxIterator->pxNext->xItemValue = 4                                       
COREB: pxIterator->pxNext = 3d24018                                             
COREB: iterate                         
....

并且它一直停留在这个循环中。

有谁能告诉我发生了什么?在FreeRTOS代码中,有一些关于循环函数崩溃的原因的评论,但似乎不是这样,或者如果是这样,我暂时不知道如何解决。

谢谢,

William

您似乎没有将信号量返回到任何位置,这将使第二个xSemaphoreTake挂起

最新更新