Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

is the function"eTaskGetStateFromISR"exist?

Posted by yukunduan on August 21, 2015

Now,we are writing a project upon FreeRTOS. I wrote a function suspend one task using vTaskSuspend(task1),then when DMA interrupt occur,I resume the task in interrupt using function TaskResumeFromISR(task1 ); but i met some problem: sometimes DMA interrupt won't occur(transmission broken) ,so the task won't be resume. I plan to write one timeout check in TIM interrupt,like: void TIM interrupt(void)// 0.1 second { if(eTaskGetState(task1hadle) == eSuspended)
{ if( //check 100 times ) { vTaskDelete(task1) xTaskCreate(task1) } } } but now it's halt in eTaskGetState : configASSERT( ( portNVICINTCTRLREG & portVECTACTIVE_MASK ) == 0 ); so like xTaskResumeFromISR and xTaskResume don't we have a function called eTaskGetStateFromISR?


is the function"eTaskGetStateFromISR"exist?

Posted by yukunduan on August 21, 2015

oh no,when i saw the function "vTaskDelete(task1),xTaskCreate(task1)",they all have the assert "configASSERT( ( portNVICINTCTRLREG & portVECTACTIVEMASK ) == 0 );" so ,is it impossible to execute according to my thought?


is the function"eTaskGetStateFromISR"exist?

Posted by yukunduan on August 21, 2015

well,now ,I think i have two solutions: 1.I set a global variable to receive the TIM interrupt times,and create a task that check the state of the task. like this: xTaskCreate(taskcheckfunctioin...) void TIM interrupt(void)// 0.1 second { givtimecount++; } void taskcheckfunctioin() { check according givtimecount;
if(eTaskGetState(task1hadle) == eSuspended) { if( //check 100 times ) { vTaskDelete(task1) xTaskCreate(task1) } } } 2.using Blocked state.I saw function like xQueueSendToBack or xSemaphoreTake. I can set number of timeout . when the interrupt occur ,release the semaphore.otherwise, timeout i will restart this task; like this: xSemaphore = xSemaphoreCreateBinary(); void DMA interrupt(void)// dma receive over { xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
} void task() { xSemaphoreTake( xSemaphore, portMAXDELAY ); }


is the function"eTaskGetStateFromISR"exist?

Posted by richard_damon on August 21, 2015

Normally suspending/resuming a task like this is really the wrong thing to be doing. If the task wants to wait for a DMA interrupt then wait for a semaphore that is set by that interrupt. That way you can add a timeout on the wait and the task can handle its own cleanup. (You can also use the task notification system as a lightweight version of this).

Also killing and restarting a task is a good way to mess up your program enviroment. Maybe you know that task doesn't hold any resources in this case, but in general it can be very bad. On "Big" OSes, you can kill a PROCESS and restart it, as the OS knows what resources a process owns and can clean those up. Tasks are much more light weight.


is the function"eTaskGetStateFromISR"exist?

Posted by rtel on August 21, 2015

Just to re-iterate and emphasise Richard Damon's point - using task suspend/resume as a synchronisation method in this way is dangerous and can lead to missed interrupts if there is a chance an interrupt arrived before the task has suspended. Suspending and resuming had no method of latching that an interrupt occured. I would also second the suggestion that the correct way to do this is with a semahore, because a semaphore does latch that an interrupt has occurred - better still use a direct to task notification as that is faster and has no RAM overhead.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS