FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [April 2014 Threads] Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 25, 2014 I create an array of semaphore (in my case is two elements).
xSemaphoreHandle sigPulse[NUMBERCHANNEL];
and then initiate and take it
vSemaphoreCreateBinary(sigPulse[CHANNEL1]);
xSemaphoreTake(sigPulse[CHANNEL1],0);
but the problem is that when the interrupt sending semaphore
xSemaphoreGiveFromISR(sigPulse[CHANNEL1], &higherprioritytaskwoken);
portENDSWITCHINGISR(higherprioritytaskwoken);
it not enable the other task, which is waiting for this semaphore
xSemaphoreTake(sigPulse[channel],portMAX_DELAY);
but if I use the normal way with if..else then it work correctly
if (channel == 0)
{
xSemaphoreTake(sigPulse1,portMAXDELAY);
}
else
{
xSemaphoreTake(sigPulse2,portMAXDELAY);
}
This is both semaphore in 1 array.
CHANNEL1 and CHANNEL2 are only the predefined keyword for number 0 and 1 and NUMBER_CHANNEL is equal to 2.
My board is sam3u4e-ek with atmel studio 6.2 beta compiler. and the kernel is free rtos 7.3.0
please tell me where the problems is???
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by davedoors on April 25, 2014 Is this the case for both semaphores in the array or just one? What is CHANNEL1 defined to?
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 25, 2014 hello Dave,
This is both semaphore in 1 array.
CHANNEL1 and CHANNEL2 are only the predefined keyword for number 0 and 1.
and NUMBER_CHANNEL is equal to 2.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 25, 2014 in the normal situation, i use sigPulse1 and sigPulse2 instead of sigPulse[channel1] and sigPulse[channel2]
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by rtel on April 25, 2014 I just put together and tried the following tiny application that gives two semaphores that reside in an array in the tick hook (which is called from an interrupt) and everything executed in the expected sequence. I'm not sure what your problem is, but maybe it is not the way you are using the semaphores, but how your interrupt priorities are defined (which is what probably 95% of support requests on Cortex-M devices, especially STM32 parts, turn out to be). If you were using FreeRTOS V8.0.0 (or maybe even V7.6.0) then you could defined configASSERT() and it would automatically call assert if you had the interrupt priorities wrong.
http://www.freertos.org/a00110.html#configASSERT
http://www.freertos.org/FAQHelp.html
http://www.freertos.org/RTOS-Cortex-M3-M4.html
As an aside, xSemaphoreCreateBinary() is preferred over vSemaphoreCreateBinary() now:
http://www.freertos.org/xSemaphoreCreateBinary.html
My test code follows:
<!-- HTML generated using hilite.me --> SemaphoreHandlet xSemaphores[ 2 ];
volatile uint32t ulTask1 = 0, ulTask2 = 0;
void main_blinky( void )
{
/* Create and take the semaphores. */
vSemaphoreCreateBinary( xSemaphores[ 0 ] );
vSemaphoreCreateBinary( xSemaphores[ 1 ] );
xSemaphoreTake( xSemaphores[ 0 ], 0 );
xSemaphoreTake( xSemaphores[ 1 ], 0 );
<span style="color: #888888">/* Create the tasks. */</span>
xTaskCreate( vTask1, <span style="background-color: #fff0f0">"Task1"</span>, configMINIMAL_STACK_SIZE, <span style="color: #007020">NULL</span>, tskIDLE_PRIORITY, <span style="color: #007020">NULL</span> );
xTaskCreate( vTask2, <span style="background-color: #fff0f0">"Task2"</span>, configMINIMAL_STACK_SIZE, <span style="color: #007020">NULL</span>, tskIDLE_PRIORITY, <span style="color: #007020">NULL</span> );
<span style="color: #888888">/* Start the tasks and timer running. */</span>
vTaskStartScheduler();
<span style="color: #008800; font-weight: bold">for</span>( ;; );
}
/-----------------------------------------------------------/
void vApplicationTickHook( void )
{
static volatile uint32_t uxCallCount = 0;
<span style="color: #888888">/* Increment call count, then give one semaphore when the call count</span>
reaches 100, and the other when the call count reaches 200. */
uxCallCount++;
<span style="color: #008800; font-weight: bold">if</span>( uxCallCount <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">100</span> )
{
xSemaphoreGiveFromISR( xSemaphores[ <span style="color: #0000DD; font-weight: bold">0</span> ], <span style="color: #007020">NULL</span> );
}
<span style="color: #008800; font-weight: bold">if</span>( uxCallCount <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">200</span> )
{
xSemaphoreGiveFromISR( xSemaphores[ <span style="color: #0000DD; font-weight: bold">1</span> ], <span style="color: #007020">NULL</span> );
<span style="color: #888888">/* Start again. */</span>
uxCallCount <span style="color: #333333">=</span> <span style="color: #0000DD; font-weight: bold">0</span>;
}
}
/-----------------------------------------------------------/
void vTask1( void pvParameters )
{
for( ;; )
{
/ Wait for the semaphore, and increment the counter when
it is received. /
xSemaphoreTake( xSemaphores[ 0 ], portMAX_DELAY );
ulTask1++;
}
}
/-----------------------------------------------------------*/
void vTask2( void pvParameters )
{
for( ;; )
{
/ Wait for the semaphore, and increment the counter when
it is received. */
xSemaphoreTake( xSemaphores[ 1 ], portMAX_DELAY );
ulTask2++;
}
}
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 26, 2014 thank you Real Time Engineers ltd very much for the fast support.
I do define the same configASSERT() and set my hardware interrupt priority as configMAXSYSCALLINTERRUPT_PRIORITY as already mentioned in Freertos page. But the error triggered hardfault problem instead of configASSERT().
Could you add the "portENDSWITCHINGISR" or taskyield() to the function to check that again?
It is really weird because there must not be any difference between the 2 independent semaphore and those in an array. I would change to version 8.0 to check that again.
Thank you very much.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 26, 2014 I forgot one important thing.
The created task take the argument as the number of semarphore. I mean:
<!-- HTML generated using hilite.me -->
void vTask2( void pvParameters )
{
uint8t channel = (uint8t) pvParameters
for (;;)
{
xSemaphoreTake(sigPulse[channel],portMAXDELAY);
...
}
}
and the created function is:
xTaskCreate( vTask2, "Task2", STACK_SIZE, (void) channel, PRIORITY, &task_id );
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by woops_ on April 26, 2014 Did you check the value of channel in vTask2 then? If it is wrong for some reason then it will break.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 26, 2014 yes I do check it, and it does correctly (with warning in compiler) but the task take it correctly.
(if it goes wrong then the 2 separate semaphore will going wrong too but it actually does right).
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by rtel on April 26, 2014
I do define the same configASSERT() and set my hardware interrupt priority as
You would need to be using FreeRTOS V7.6.0 or later for that to catch a priority misconfigurtion.
Could you add the "portENDSWITCHINGISR" or taskyield() to the function to check that
again?
If the problem is related to the access of the semaphore then that would not make any difference, but I tried it all the same and it didn't change the behaviour or my test application.
In your case I can only assume either an interrupt priority problem, a problem indexing into the array, or a problem creating the semaphores in the first place - although I understand you have checked those already.
But the error triggered hardfault problem instead of configASSERT().
That has to be the biggest clue as to what the issue is. I would recommend stepping through the code until you see the hardfault occur, then look at what was being accessed immediately before the hardware (what triggered the hard fault). The following link may also help - but just stepping through the code would be easier:
http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html
Regards.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 29, 2014 Thanks for your fast reply.
But the error triggered hardfault problem instead of configASSERT().
I'm sorry about this, I misremembered. I already fix this problem (before I post this quesion).
I change the OS to version 8.0.0 and it does not make any difference at all. (I already change the to xSemaphoreCreateBinary() instead of vSemaphoreCreateBinary() too)
I mean the two separate semaphore does work as normal but the semaphore in array does not work, no assert trigger found.
The problem is that it does send semaphore but the other task can not take it and thus nothing work.
the waiting task, named Calculate1, does in ready status at the time the semaphore give but cannot take it. The waiting command is:
xSemaphoreTake(sigCalculate[channel],portMAXDELAY);
I observe the semaphore via the function vQueueAddToRegistry().
any hint for me please!
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by rtel on April 29, 2014 Create a small a project as you can that still exhibits the problem, check it builds correctly on any machine (it does not rely on any absolute paths to tools, source files, linker scripts, etc), zip it up and send it to the 'business contact' email address on the http://www.freertos.org/contact web page.
Regards.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on April 30, 2014 I recheck my project and realize that the semaphore does send and receive but the problem is that it seem the array of semaphore make the "semaphore get" slower. And thus missing more than half of the semaphore give.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by davedoors on April 30, 2014
it seem the array of semaphore make the "semaphore get" slower
How could it do that? Inside the function it just has a pointer to a semaphore, if the semaphore is stored in the same kind or RAM (rather than external RAM in one case and internal RAM in the other) it can't make any difference to the speed.
Sounds like you should be using a counting semaphore.
Array of Semaphore cannot receive semaphore from semaphoregivefromisr()Posted by thegracious on May 7, 2014 thanks all for your support. Things now running as expected. The array of semaphore run as the two separate semaphore now. The reason is that some mistake in my code (I still dont know where), when I re-code it, step by step, everything goes right. Problem solved!
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|