xTaskCreate in an interrupt

malcolmsmc wrote on Tuesday, October 10, 2017:

I am currently using the FreeRTOS in a project using a PIC32MX. It all
worked properly until I added an xTaskCreate from inside an interrupt
routine. The system crashed!.

The created task started with an xTaskDelay and although it reached this
function it never returned but failed on an address problem.

/* Task started. */

static void download_task( void *param )
{
uint8_t result;
BFR_HANDLE bfr;
uint16_t cChr;
uint8_t retry;
uint8_t schar = 0;

 vTaskDelay( DOWNLOAD_DELAY_TO_START );
 fileClean( 1 );
 .............

I WILL find a way round my problem but it would be interesting to know
if there is a known problem.


Regards Malcolm

Technical Manager (R&D)
ENS Group
Orpheus House
Calleva Park
Aldermaston
Berks RG7 8TA
UK

Email: xxxx@xxxx
Web: www.smc-electronics.co.uk
Web: www.ens-group.co.uk

rtel wrote on Tuesday, October 10, 2017:

There is a simple rule of thumb (which doesn’t hold in all cases, but is
easy to state and follow): Do not call any API function that doesn’t
end if ‘FromISR’ from an interrupt.

That is particularly true of xTaskCreate(), which will allocate memory.

If you want to create a task from an interrupt then use one of the
deferred interrupt handling techniques, or use
xTimerPendFunctionCallFromISR()
http://www.freertos.org/xTimerPendFunctionCallFromISR.html

I would recommend reading the book, its free, and won’t take long:
http://www.freertos.org/Documentation/RTOS_book.html

malcolmsmc wrote on Wednesday, October 11, 2017:

Many thanks.
My problem was using the taskENTER_CRITICAL/taskEXIT_CRITICAL inside an interrupt.

I noted your comments and changed to starting the task then suspended it. Whan I wanted to use it I just did an xTaskResumeFromISR to activate it.