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

extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on August 29, 2006
Hello,

I have idea to ensure additional "watchdog" for FreeRTOS. There is possibility to implement a little memory controller for our tasks. In tasks.c tskTCB structure includes pxTopOfStack, pxStack and usStackDepth. We can add into OS clock code (for example into vTaskIncrement) special function to control stack of every tasks and to generate exceptions...
/*if ((pxTopOfStack-pxStack > usStackDepth) || (pxStack > pxTopOfStack)) call_an_exteption()*/
It could be good for debug mode to estimate needed size of a task stack...

what do you think about?

best regards
Janusz

P.S. My FreeRTOS (currently 4.0.5) is every day more and more stable with lwIP (currently 1.1.1) cooperation. The PPP (with reduced bugs) almost works fine! There is a huge amount of learning...

RE: extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on August 30, 2006
I have used that technique lots of time ;-) I have it compiled in for debug builds only.

RE: extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on August 31, 2006
I was blind:

void vTaskList( portCHAR *pcWriteBuffer );

configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend must all be defined as 1 for this function to be available. See the configuration section for more information.

NOTE: This function will disable interrupts for its duration. It is not intended for normal application runtime use but as a debug aid.

Lists all the current tasks, along with their current state and stack usage high water mark.

Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or suspended ('S').

and writetotracebuffer...

best rgs

RE: extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on September 1, 2006
it works:
tasks.c
/*-----------------------------------------------------------*/

#if 1
// --- JU
extern void kprintfFromISR(const char *format,...);

static void prvListTaskWithinSingleListPrintf(xList *pxList, signed portCHAR cStatus )
{
volatile tskTCB *pxNextTCB, *pxFirstTCB;
unsigned portSHORT usStackRemaining;

/* Write the details of all the TCB's in pxList into the buffer. */
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
do {
listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned portCHAR * ) pxNextTCB->pxStack );
kprintfFromISR("%s\t\t%c\t%u\t%u\t\t%u\r\n",
pxNextTCB->pcTaskName, cStatus,
( unsigned int ) pxNextTCB->uxPriority,
usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber );
} while( pxNextTCB != pxFirstTCB );
}

void vTaskPrintCurrentFromISR()
{
unsigned portBASE_TYPE uxQueue;// vTaskList

if ( pxCurrentTCB == NULL ) {
kprintfFromISR("there is no tasks!\n");
return;
}

kprintfFromISR("current task %s, number 0x%x, priority %d\n",
pxCurrentTCB->pcTaskName,
pxCurrentTCB->uxTCBNumber,
pxCurrentTCB->uxPriority);
kprintfFromISR("top of stack 0x%x, start of stack 0x%x, depth 0x%x\n",
pxCurrentTCB->pxTopOfStack,
pxCurrentTCB->pxStack,
pxCurrentTCB->usStackDepth);

// only for ARM7
kprintfFromISR("R15(PC) = 0x%08x+instr, R14(LR) = 0x%08x\n", *pxCurrentTCB->pxTopOfStack, *(pxCurrentTCB->pxTopOfStack-1));
kprintfFromISR("R13(SP) = 0x%08x, R12 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack-2), *(pxCurrentTCB->pxTopOfStack-3));
kprintfFromISR(" R11 = 0x%08x, R10 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack-4), *(pxCurrentTCB->pxTopOfStack-5));
kprintfFromISR(" R9 = 0x%08x, R8 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack-6), *(pxCurrentTCB->pxTopOfStack-7));
kprintfFromISR(" R7 = 0x%08x, R6 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack-8), *(pxCurrentTCB->pxTopOfStack-9));
kprintfFromISR(" R5 = 0x%08x, R4 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack-10), *(pxCurrentTCB->pxTopOfStack-11));
kprintfFromISR(" R3 = 0x%08x, R2 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack-12), *(pxCurrentTCB->pxTopOfStack-13));
kprintfFromISR(" R1 = 0x%08x, R0 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack-14), *(pxCurrentTCB->pxTopOfStack-15));
kprintfFromISR("SPSR = 0x%08x, critical nesting = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack-16), *(pxCurrentTCB->pxTopOfStack-17));

// vTaskList
/* This is a VERY costly function that should be used for debug only.
It leaves interrupts disabled for a LONG time. */

/* Run through all the lists that could potentially contain a TCB and
report the task name, state and stack high water mark. */

kprintfFromISR("\ntask name\tstatus\tprior\tstack remaining\ttask number\n");

uxQueue = uxTopUsedPriority + 1;

do {
uxQueue--;

if( !listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) )
{
prvListTaskWithinSingleListPrintf(( xList * ) &( pxReadyTasksLists[ uxQueue ] ), tskREADY_CHAR );
}
} while( uxQueue > ( unsigned portSHORT ) tskIDLE_PRIORITY );

if( !listLIST_IS_EMPTY( pxDelayedTaskList ) )
{
prvListTaskWithinSingleListPrintf(( xList * ) pxDelayedTaskList, tskBLOCKED_CHAR );
}

if( !listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) )
{
prvListTaskWithinSingleListPrintf(( xList * ) pxOverflowDelayedTaskList, tskBLOCKED_CHAR );
}

if( !listLIST_IS_EMPTY( &xTasksWaitingTermination ) )
{
prvListTaskWithinSingleListPrintf(( xList * ) &xTasksWaitingTermination, tskDELETED_CHAR );
}

if( !listLIST_IS_EMPTY( &xSuspendedTaskList ) )
{
prvListTaskWithinSingleListPrintf(( xList * ) &xSuspendedTaskList, tskSUSPENDED_CHAR );
}
}
#endif

void vTaskSwitchContext( void )
{
#if 1
// JU - debug
if ((pxCurrentTCB->pxTopOfStack - pxCurrentTCB->pxStack > pxCurrentTCB->usStackDepth) ||
(pxCurrentTCB->pxStack > pxCurrentTCB->pxTopOfStack)) {
portENTER_CRITICAL();
kprintfFromISR("\nKernel panic: stack overflow\n");
vTaskPrintCurrentFromISR();
while(1);// halt
}
#endif

if( uxSchedulerSuspended != ( unsigned portBASE_TYPE ) pdFALSE )
{
/* The scheduler is currently suspended - do not allow a context
switch. */
xMissedYield = pdTRUE;
return;
}

/* Find the highest priority queue that contains ready tasks. */
while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )
{
--uxTopReadyPriority;
}

/* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the
same priority get an equal share of the processor time. */
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );
vWriteTraceToBuffer();
}
/*-----------------------------------------------------------*/

portISR.c
//---------------------------------------------------------------------------------- interrupt exceptions (JU) -------------------------------------------------------------------------
void Undef_Handler( void ) __attribute__((naked));
void PAbt_Handler( void ) __attribute__((naked));
void DAbt_Handler( void ) __attribute__((naked));

void Undef_Handler( void ) {
portENTER_CRITICAL();
kprintfFromISR("\nKernel panic: Undef handler\n");
vTaskPrintCurrentFromISR();
while(1);// halt
}

void PAbt_Handler( void ) {
portENTER_CRITICAL();
kprintfFromISR("\nKernel panic: Program Abort handler\n");
vTaskPrintCurrentFromISR();
while(1);// halt
}

void DAbt_Handler( void ) {
portENTER_CRITICAL();
kprintfFromISR("\nKernel panic: Data Abort handler\n");
vTaskPrintCurrentFromISR();
while(1);// halt
}



maybe it will be useful for you

Janusz

RE: extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on September 1, 2006
there is mistake, sorry:
void vTaskPrintCurrentFromISR()
{
unsigned portBASE_TYPE uxQueue;// vTaskList
#define RAM_MAX0x210000

if ( pxCurrentTCB == NULL ) {
kprintfFromISR("there is no tasks!\n");
return;
}
if ( pxCurrentTCB > RAM_MAX) {// bad pointer protection
kprintfFromISR("pxCurrentTCB failure!\n");
return;
}

kprintfFromISR("current task %s, number 0x%x, priority %d\n",
pxCurrentTCB->pcTaskName,
pxCurrentTCB->uxTCBNumber,
pxCurrentTCB->uxPriority);
kprintfFromISR("top of stack 0x%x, start of stack 0x%x, depth 0x%x\n",
pxCurrentTCB->pxTopOfStack,
pxCurrentTCB->pxStack,
pxCurrentTCB->usStackDepth);

if ( pxCurrentTCB->pxTopOfStack+17 > RAM_MAX) {// bad pointer protection
kprintfFromISR("pxTopOfStack failure!\n");
return;
}

// only for ARM7
kprintfFromISR("critical nesting = 0x%08x, SPSR = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+0), *(pxCurrentTCB->pxTopOfStack+1));
kprintfFromISR(" R0 = 0x%08x, R1 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack+2), *(pxCurrentTCB->pxTopOfStack+3));
kprintfFromISR(" R2 = 0x%08x, R3 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+4), *(pxCurrentTCB->pxTopOfStack+5));
kprintfFromISR(" R4 = 0x%08x, R5 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack+6), *(pxCurrentTCB->pxTopOfStack+7));
kprintfFromISR(" R6 = 0x%08x, R7 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+8), *(pxCurrentTCB->pxTopOfStack+9));
kprintfFromISR(" R8 = 0x%08x, R9 = 0x%08x, ", *(pxCurrentTCB->pxTopOfStack+10), *(pxCurrentTCB->pxTopOfStack+11));
kprintfFromISR(" R10 = 0x%08x, R11 = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+12), *(pxCurrentTCB->pxTopOfStack+13));
kprintfFromISR(" R12 = 0x%08x, R13(SP) = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+14), *(pxCurrentTCB->pxTopOfStack+15));
kprintfFromISR("R14(LR) = 0x%08x+instr, R15(PC) = 0x%08x\n", *(pxCurrentTCB->pxTopOfStack+16), *(pxCurrentTCB->pxTopOfStack+17));

// vTaskList


Janusz

RE: extra stability for FreeRTOS, what about?

Posted by Nobody/Anonymous on September 1, 2006
In addtition portENTER_CRITICAL(); is negligible.


[ 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