Reputation: 335
I'm trying to understand why my code get stuck in the for loop of vListInsert from FreeRTOS. I'm implementing FreeRTOS for bfin561 coreb with gcc toolchain compiler.
here are the clue I've got:
I initialise the semaphore this way:
.....
vSemaphoreCreateBinary( LED0_semaphore );
vSemaphoreCreateBinary( LED5_semaphore );
params[0].event = LED0_semaphore;
params[5].event = LED5_semaphore;
....
then in the task function:
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);
.....
}
in the above code the problem hapen in the second while( xSemaphoreTake( sem, portMAX_DELAY ) != pdTRUE ); line.
Debugging through the code, I got stuck in :
void vListInsert( xList *pxList, xListItem *pxNewListItem )
from freeRTOS at the:
....
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. */
}
....
outputting debug messages I've got:
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
....
and it stay in this for loop.
Any one that knw well freeRTOS could tell me what happen? There some comment above this for loop function in the FreeRTOS code about certain reason why it would crash, but it doesn't seem to be that or if it is I don't know how to solve it for the moment.
Thanks,
William
Upvotes: 2
Views: 3873
Reputation: 16812
It appears you're not giving the semaphore back anywhere - that would make the 2nd xSemaphoreTake
hang up
Upvotes: 3