Thread does not run

elham wrote on Sunday, September 02, 2018:

I have created three threads. One of them has the higher priority than two others and I use a binary semaphore to synchronize it with an ISR. ISR releases semaphore and wakes up the highest priority thread. Other two threads run while the highest priority thread is blocked for acquiring semaphore.

The problem is after a while the higher priority thread does not run at all. I use LED blinking test and found every time it does not run, the semaphore has been released by the ISR, but the thread does not stuck in acquiring semaphore. It does not run completely. Other two threads run normally while the highest one does not.

I use the empty body loops for all three threads but the problem persists.

I use cortexM3(LPC1788) and freeRTOS ver 6.1.0

Your help would be greatly appreciated,
Elham

void TIMER0_IRQHandler(void) //2 ms interrupt
{
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(hADCSemaphore, &xHigherPriorityTaskWoken);
}

int main(void)
{

NVIC_SetPriority(TIMER0_IRQn, 33);
LPC_TIM0->MR0 = ((((SystemCoreClock / 1000) / 40) - 1)40); / 2 ms? */
LPC_TIM0->MCR = (3 << 0);
NVIC_EnableIRQ(TIMER0_IRQn);
LPC_TIM0->TCR = (1 << 0);

xTaskCreate( MyTask1, “TaskCore”, 1200 , NULL, tskIDLE_PRIORITY+1 , NULL );
xTaskCreate( MyTask2 , “TaskGraphics”, 1500, NULL, tskIDLE_PRIORITY+1, NULL );
xTaskCreate( MyTask3, “TaskTouchScreen”, 3000, NULL, tskIDLE_PRIORITY+2, NULL );

vSemaphoreCreateBinary(hADCSemaphore);

vTaskStartScheduler();
while(1);
}

static void MyTask1(void* pvParameters)
{
while(1)
{

    }

}

static void MyTask2(void* pvParameters)
{
while(1)
{
}
}

static void MyTask3(void* pvParameters)
{
while(1)
{
if( xSemaphoreTake( hADCSemaphore, portMAX_DELAY ) == pdTRUE )
{

      }
    }

}

rtel wrote on Monday, September 03, 2018:

I don’t fully understand the description of the problem.

The problem is after a while the higher priority thread does not run at
all. I use LED blinking test and found every time it does not run,

I’m not sure if you are saying it never runs (“ever time it does not
run”) or that it starts of ok, but after a while it stops running
(“after a while the higher priority thread does not run”).

I use cortexM3(LPC1788) and freeRTOS ver 6.1.0

Yikes - that is very, very old.

void TIMER0_IRQHandler(void) //2 ms interrupt
{
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(hADCSemaphore, &xHigherPriorityTaskWoken);
}

If you want the high priority task to run immediately the semaphore is
given then you need to call portYIELD_FROM_IS( xHigherPriorityTaskWoken
) - or possibley portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ) - at
the end of the ISR - I can’t remember for that version but look at the
examples that come with that version to determine which.

int main(void)
{

NVIC_SetPriority(TIMER0_IRQn, 33);

Make sure you read RTOS for ARM Cortex-M as
setting the priorities is complex on a Cortex-M. If you were using
FreeRTOS V10 then you could defined configASSERT() and that would tell
you if you had any of the configuration wrong - it will be much harder
in V6.

static void MyTask3(void* pvParameters)
{
while(1)
{
if( xSemaphoreTake( hADCSemaphore, portMAX_DELAY ) == pdTRUE )
{

   }
 }

}

Looks ok.