gpt4 book ai didi

list - FreeRTOS 在列表插入函数中为信号量无限地停留在 for 循环中

转载 作者:行者123 更新时间:2023-12-04 05:53:35 26 4
gpt4 key购买 nike

我试图理解为什么我的代码卡在 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_thread\n");

task_params_list_t *p = (task_params_list_t *)Param;

coreb_msg("got parameters\n");

int lite = p->LED;
xSemaphoreHandle sem = p->event;
if (sem != (xSemaphoreHandle)0) // is t\
he semaphore pointer is valid
{
coreb_msg("semaphore pointer is valid\n");

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 LED\n");

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 LED\n");

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
....

它停留在这个 for 循环中。

任何了解 freeRTOS 的人都可以告诉我会发生什么吗?在 FreeRTOS 代码中的 for 循环函数上方有一些关于它崩溃的某些原因的评论,但似乎并非如此,或者我暂时不知道如何解决它。

谢谢,

威廉

最佳答案

看来您没有在任何地方返回信号量 - 这将使第二个 xSemaphoreTake挂断

关于list - FreeRTOS 在列表插入函数中为信号量无限地停留在 for 循环中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9782018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com