Quality RTOS & Embedded Software

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




Loading

about using interrupts ..

Posted by Teratux on May 13, 2010
Hi I'm using FreeRtos 5.2.0 , MPLAB 8.02 and the C30 compiler. I created a main() function with the following code:

xTaskHandle Handle;

T1CONbits.TON = 1;
/* Inicializo Hardware. */
vPortInitialiseBlocks();

xTaskCreate( vTarea, ( const portCHAR * const ) "Prueba1", configMINIMAL_STACK_SIZE, &cProcId1, tskIDLE_PRIORITY, NULL );

portBASE_TYPE xYieldRequired;

// Resume the suspended task.
xYieldRequired = xTaskResumeFromISR( Handle );

if( xYieldRequired == pdTRUE )
{
// We should switch context so the ISR returns to a different task.
// NOTE: How this is done depends on the port you are using. Check
// the documentation and examples for your port.
printf("B");
portYIELD();
}

vTaskStartScheduler();
return 0;

The task I create only prints out a text message. According to the Freertos API the xTaskResumeFromISR() function resumes a task when an interrupt occurs. I'm using a ds33FJ256GP710 device. The T1CONbits.TON = 1 activates de T1 timer from the dspic but it seems as if the rtos doesn't capture the interrupt. What could be happening ?

Thanks ...

RE: about using interrupts ..

Posted by Dave on May 13, 2010
Its not obvious from your code what is main() and what is the interrupt, it seems mixed up, but a few quick points.

1 Are you enabling the timer interrupt before the kernel is executing? If so then an interrupt being executed will cause a crash when you attempt to yield.

2 Never call printf() from an interrupt.

3 You might consider using a semaphore to wake a task instead of xTaskResumeFromISR().

RE: about using interrupts ..

Posted by Teratux on May 13, 2010
Yes sorry ... the code earlier was only for the main() function. I didn't put the code for the task. The task's code only has a printf("") function followed by a vTaskSuspend( NULL ); All of that inside a loop. Regarding the questions you asked me. I think I am enabling the timer before de kernel execution:

T1CONbits.TON = 1;

This the first line before vTaskStartScheduler();

You said using a semaphore to wake a task. Umm I'm a newbie here, is there an available documentation anywhere regarding this ??

RE: about using interrupts ..

Posted by Richard Damon on May 13, 2010
teratux,
please note that the code you have listed from xtarskResumeFromISR to the } after portYIELD() should be int the ISR not the mainline!! (and printf() shouldn't be called from the ISR).

RE: about using interrupts ..

Posted by Teratux on May 13, 2010
Oh, ok so I get the idea. After you request a context switch from a function handler the task resumes. I guess this isn't what I'm looking for. My main concern is after an interrupt occurs how can I treat it within a function. The API reference isn't very explicit in this aspect

Thanks for your reply ...

RE: about using interrupts ..

Posted by Richard Damon on May 13, 2010
the question comes, what does the function need from the interrupt? If it needs just a bit of data, then perhaps a queue would work to store the data (insert data in ISR, retrieve data in task), if it needs a bigger chunk of data, then sending a pointer to a buffer may work better (and have some code to figure out which buffers are free for the interrupt to use). If the task just needs to be notified that something changed (but isn't being sent any specific data) then the task can wait on a semaphore which is set by the ISR. In each of these cases, the task is calling a routine to get something that the interrupt is sending for the task to get.

Since the interrupt is a timer, it probably isn't sending data, but just indicating a time period, you are most apt to want to use the semaphore.

A couple of thought as a look at things. One issue is that FreeRTOS may be already using T1 for its timebase, and this will interfere with you doing something special with it. The second is that if you are just looking for the task to run periodically, you may want to look at vTaskDelay and vTaskDelayUntil as these may be all that you really need.

Have you read the documentation on FreeRTOS.org? It really is quite good and does provide simple examples for how things work.


[ 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