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

AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 8, 2010
Hi,
with the function uxTaskGetStackHighWaterMark(NULL), I wanted to check the stack of each task running in the system.
Therefore I called this function an the end of each task (there are 3 tasks running, with different priorities).
Unfortunately it doesnt work. The system crashes immediatedly with an exception (_handle_Bus_Error_Instruction_Fetch).
In the function uxTaskGetStackHighWaterMark() and usTaskCheckFreeStackSpace() I cant see why this should not work.

Any suggestions why this fails ?

Best regards
Karsten

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Dave on April 8, 2010
Can you step into the function to see where the error occurs?

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 8, 2010
No, not really. I tried already, but by stepping through the function, it seams to work.
I think it has something to with the taskwitch.
If a task is just inside this function, and a task with higher priority suspends the currently running task, than the exception could happen (but I am not sure).
Regards
Karsten

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by mizer on April 8, 2010
As an experiment surround your stack checking work with vTaskSuspendAll / xTaskResumeAll.

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 8, 2010
Yes I think it would work (I will try it tomorrow morning) because the function vTaskList() works as well and does it in the same way.
But the intention was NOT to suspend all the tasks. I wanted to do the stack checking at the end of each currently running task, in order not to disturb (suspend, block) the other tasks.
But I cant see any reason in the source-code of the function uxTaskGetStackHighWaterMark(NULL) which could be responsable for the exception, even if a task with higher priority suspends the active task which is just inside the uxTaskGetStackHighWaterMark(NULL).

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Richard on April 8, 2010
I don't understand where you are attempting to call uxTaskGetStackHighWaterMark(). What do you mean 'at the end of each currently running task'. Do you mean using something like the traceTASK_SWITCHED_OUT() macro?

Regards.

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 8, 2010
Hi Richard,
thanks for the reply.

Just an example:

void vTaskCode1( void * pvParameters )
{
for( ;; )
{
vTaskDelay( sometime );
// Task code
// ......
// ......
stack_task1 = uxTaskGetStackHighWaterMark(NULL);
}
}
/*************************************************/

void vTaskCode2( void * pvParameters )
{
for( ;; )
{
vTaskDelay( sometime );
// Task code
// ......
// ......
stack_task2 = uxTaskGetStackHighWaterMark(NULL);
}
}

One task has a higher priority than the other.

Best regards
Karsten

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Richard on April 8, 2010
Hmm, I cannot see anything wrong there. Did you try the suggestion of placing the call inside a critical section? I don't think it should need it, but it would be interesting if it cured the problem.

Regards.

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 9, 2010
Hi Richard,
I tried the following for each task.
portENTER_CRITICAL();
stack_task_1= uxTaskGetStackHighWaterMark(xHandleApplicationTask);
portEXIT_CRITICAL();

Afterwards the exception error DID NOT occur, but the program runs not very well, respectively it runs very slow.
-Task 1 normally works every 10ms | usStackDepth = 4000 (16kB) | lower priority
-Task 2 normally works every 1ms | usStackDepth = 256 (1kB) | higher priority

I measured the time for the uxTaskGetStackHighWaterMark(NULL) call:
Inside Task1: about 10ms !!
Inside Task2: about 0,6ms

- During the runtime of uxTaskGetStackHighWaterMark(NULL) in Task1, Task2 is blocked.
- The active-time of Task1 is as double as normal.
==> This result in the loss of speed, which I can observe.

So, without portENTER_CRITICAL()/EXIT the Task1 will be suspended by Task2, definitely during the execution of uxTaskGetStackHighWaterMark(NULL). Task1 then starts uxTaskGetStackHighWaterMark(NULL) again.

But why is this a problem which results in an exception?
Each call of uxTaskGetStackHighWaterMark(NULL) should do its job by itself, without affecting the other running uxTaskGetStackHighWaterMark(NULL) , isnt it ?
It is something like reentrancy ?

I know now that I cant solve the stackchecking in this way, but I want to understand the reason for the exception.

Best regard
Karsten

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Richard on April 9, 2010
I would have to run the code to understand what is causing the problem. Just by looking at the code I would say there should not be a reentrancy problem, but there is obviously something more subtle going on.

Regards.

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Karsten Klein on April 9, 2010
Do you need more information from my side to investigate the problem ?
To send you the whole project does not make sense because you would need the hardware as well to get something to run.
Regards
Karsten

RE: AVR32: uxTaskGetStackHighWaterMark

Posted by Chris on April 15, 2010
Hi Karsten,

Did you resolve your problem? I only ask as I have had a bus_error_data_fetch exception problem with the AVR32's. I would be very interested to know how you fixed your exception problem. In my case it seemed to occur around the time when a context was being switched, but was intermittent and sometimes very hard to make it fail. In all cases the exception (although a data fetch, not instruction fetch) would occur somewhere within one of the "C" libraries. I believe my problem (although I'm not yet fully convinced) was to do with the "C" libraries not being re-entrant. I've created a struct _reent for each task and I point the "C" library's _impure_ptr at the appropriate one each time a context switch is done. I have not seen an the exception since I'd made these changes. I can send you more details if that helps.

Cheers,
Chris.


[ 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