Quality RTOS & Embedded Software

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




Loading

Semaphore release in ISR using NIOS II

Posted by DanyUP on February 13, 2011
Hello to all,
I'm working on measurements over FreeRTOS for a thesis in Computer Engineering. I'm using FreeRTOS over NIOS II processor in an Altera FPGA and a custom made board.
Here is what i'm trying to verify:
A task is blocked on a semaphore, released by an hardware interrupt that fires once every 650us. I want to see if the task keep the same period of the interrupt and what is the latency of using this method (a task waiting for a semaphore) for interrupt management.
When the Interrupt management task is executed alone everything is fine: i can see it starting once every 650 us. If I try it with other lower priority tasks I found that the task is launched once every 2ms, that is the RTOS tick period.
It seems to me that the context switch that should wake the interrupt management task doesn't occur until the intervention of FreeRTOS kernel, instead of being forced by the semaphore release function and the macro portEND_SWITCHING_ISR.
Am I doing something wrong?
Thanks for your help.
Here's my source code:

static void test_irq(void* context){
portBASE_TYPE highPrioWoken = pdFALSE;
IOWR(CONTATORE_AVALON_0_BASE, 6, 0);
xSemaphoreGiveFromISR(semaphore, &highPrioWoken);
portEND_SWITCHING_ISR(highPrioWoken);
}

static portTASK_FUNCTION( vSporadicTask, pvParameters ){
int i;
for(i = 0; ixSemaphoreTake(semaphore, portMAX_DELAY);
m_testBuffer = alt_timestamp();
}
tst_put_open();
tst_put_string("name", "SporadicTest");
tst_put_int("numtest", NUMTEST);
tst_put_int("numtask", NUMTASK);
tst_put_ulong("TickFreq", alt_timestamp_freq());
tst_put_ulongbuffer("data", m_testBuffer, NUMTEST);
tst_put_close();
vTaskSuspend(NULL);
}

static portTASK_FUNCTION( vDummyTask, pvParameters ){
int m_dummyVar = 0;
for(;;){
m_dummyVar++;
}
}


Functions starting with tst_put_ are custom functions used to put the array containing the timestamps on standard output so that i can retrieve and analyse it. However they are called after the test is completed so they should not affect the correct behaviour of the task.

RE: Semaphore release in ISR using NIOS II

Posted by Richard Damon on February 13, 2011
You don't show the code for creating the tasks, but from your description, it sounds like vDummyTask and vSporadicTask are assigned to the same priority level, thus when the semaphore is given, vSporadicTask will not interrupt vDummyTask, but only be scheduled ready and take its turn at the next tick.

RE: Semaphore release in ISR using NIOS II

Posted by DanyUP on February 13, 2011
Uh... sorry for the missing source... However the sporadic task has an higher priority than the dummy task. That's why I can't explain what's happening...

void startSporadicTest(){
xTaskHandle handle=NULL;
int basePrio = tskIDLE_PRIORITY+1;
vSemaphoreCreateBinary(semaphore);
if(semaphore != NULL){
xSemaphoreTake(semaphore, 0);
}
createDummyTasks(NUMTASK, basePrio);
alt_ic_isr_register(SYSID_IRQ_INTERRUPT_CONTROLLER_ID, CONTATORE_AVALON_0_IRQ,test_irq, NULL, NULL); //registering interrupt function
IOWR(CONTATORE_AVALON_0_BASE, 4, 1); //Enabling interrupt
m_testBuffer = pvPortMalloc( NUMTEST * sizeof(alt_u32) );
if(!m_testBuffer){
printf("Errore!! Impossibile creare il buffer m_testBuffer\n");
}
xTaskCreate(vSporadicTask, (signed char *) "Test", configMINIMAL_STACK_SIZE, NULL, basePrio+1, &handle);
}

void createDummyTasks(int numtasks, int prio){
int i;
xTaskHandle m_handle=NULL;
for(i = 0; i < numtasks; i++){
xTaskCreate(vDummyTask, (signed char *) "Dummy", DUMMYSTACK, NULL, prio, &m_handle);
if(!m_handle){
printf("Errore!! Memoria insufficiente per il task %d\n", i); //That is out of memory
}
}
}

RE: Semaphore release in ISR using NIOS II

Posted by DanyUP on February 13, 2011
I forgot the code tag... :(
Why can't I edit the post?
However thanks for your reply

RE: Semaphore release in ISR using NIOS II

Posted by Richard Damon on February 13, 2011
One thought, is configMAX_PRIORITIES (in FreeRTOSConfig.H) at least 3? (Since you have 3 priorities, 0, 1, 2).

RE: Semaphore release in ISR using NIOS II

Posted by DanyUP on February 16, 2011
Yes, it is... configMAX_PRIORITIES is set to 5.
Is there someone else who tried this kind of test? Even with different platform?

RE: Semaphore release in ISR using NIOS II

Posted by Richard Damon on February 17, 2011
I will say that I have a somewhat similar structure in one of my projects, with a task that is woken up via a semaphore connected to a higher speed interrupt than the tick interrupt. and it runs fine. I will admit I don't have the equivalent of your dummy task that is just wasting time.

My only suggestion would be (if possible) to trace with a debugger through the give and switch to see why the task isn't starting.

The only thing I see that looks unusual to me is that the line m_testbuffer = alt_timestamp(); seems to keep setting the same variable each time, I would expect it to be m_testbuffer = alt_timestamp(); or something like that.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists