integer.c File Reference

#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "integer.h"

Go to the source code of this file.

Defines

#define intgCONST1   ( ( long ) 123 )
#define intgCONST2   ( ( long ) 234567 )
#define intgCONST3   ( ( long ) -3 )
#define intgCONST4   ( ( long ) 7 )
#define intgEXPECTED_ANSWER   ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
#define intgNUMBER_OF_TASKS   ( 1 )
#define intgSTACK_SIZE   configMINIMAL_STACK_SIZE

Functions

static portTASK_FUNCTION (vCompeteingIntMathTask, pvParameters)
static portTASK_FUNCTION_PROTO (vCompeteingIntMathTask, pvParameters)
void vStartIntegerMathTasks (unsigned portBASE_TYPE uxPriority)
portBASE_TYPE xAreIntegerMathsTaskStillRunning (void)

Variables

static volatile signed
portBASE_TYPE 
xTaskCheck [intgNUMBER_OF_TASKS] = { ( signed portBASE_TYPE ) pdFALSE }


Define Documentation

#define intgCONST1   ( ( long ) 123 )

Definition at line 94 of file integer.c.

Referenced by portTASK_FUNCTION().

#define intgCONST2   ( ( long ) 234567 )

Definition at line 95 of file integer.c.

Referenced by portTASK_FUNCTION().

#define intgCONST3   ( ( long ) -3 )

Definition at line 96 of file integer.c.

Referenced by portTASK_FUNCTION().

#define intgCONST4   ( ( long ) 7 )

Definition at line 97 of file integer.c.

Referenced by portTASK_FUNCTION().

#define intgEXPECTED_ANSWER   ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )

Definition at line 98 of file integer.c.

Referenced by portTASK_FUNCTION().

#define intgNUMBER_OF_TASKS   ( 1 )

Definition at line 103 of file integer.c.

Referenced by vStartIntegerMathTasks(), and xAreIntegerMathsTaskStillRunning().

#define intgSTACK_SIZE   configMINIMAL_STACK_SIZE

Definition at line 100 of file integer.c.

Referenced by vStartIntegerMathTasks().


Function Documentation

static portTASK_FUNCTION ( vCompeteingIntMathTask  ,
pvParameters   
) [static]

Definition at line 129 of file integer.c.

References intgCONST1, intgCONST2, intgCONST3, intgCONST4, intgEXPECTED_ANSWER, pdFALSE, pdTRUE, portBASE_TYPE, portENTER_CRITICAL, portEXIT_CRITICAL, and taskYIELD.

00130 {
00131 /* These variables are all effectively set to constants so they are volatile to
00132 ensure the compiler does not just get rid of them. */
00133 volatile long lValue;
00134 short sError = pdFALSE;
00135 volatile signed portBASE_TYPE *pxTaskHasExecuted;
00136 
00137     /* Set a pointer to the variable we are going to set to true each
00138     iteration.  This is also a good test of the parameter passing mechanism
00139     within each port. */
00140     pxTaskHasExecuted = ( volatile signed portBASE_TYPE * ) pvParameters;
00141 
00142     /* Keep performing a calculation and checking the result against a constant. */
00143     for( ;; )
00144     {
00145         /* Perform the calculation.  This will store partial value in
00146         registers, resulting in a good test of the context switch mechanism. */
00147         lValue = intgCONST1;
00148         lValue += intgCONST2;
00149 
00150         /* Yield in case cooperative scheduling is being used. */
00151         #if configUSE_PREEMPTION == 0
00152         {
00153             taskYIELD();
00154         }
00155         #endif
00156 
00157         /* Finish off the calculation. */
00158         lValue *= intgCONST3;
00159         lValue /= intgCONST4;
00160 
00161         /* If the calculation is found to be incorrect we stop setting the 
00162         TaskHasExecuted variable so the check task can see an error has 
00163         occurred. */
00164         if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
00165         {
00166             sError = pdTRUE;
00167         }
00168 
00169         if( sError == pdFALSE )
00170         {
00171             /* We have not encountered any errors, so set the flag that show
00172             we are still executing.  This will be periodically cleared by
00173             the check task. */
00174             portENTER_CRITICAL();
00175                 *pxTaskHasExecuted = pdTRUE;
00176             portEXIT_CRITICAL();
00177         }
00178 
00179         /* Yield in case cooperative scheduling is being used. */
00180         #if configUSE_PREEMPTION == 0
00181         {
00182             taskYIELD();
00183         }
00184         #endif
00185     }
00186 }

static portTASK_FUNCTION_PROTO ( vCompeteingIntMathTask  ,
pvParameters   
) [static]

void vStartIntegerMathTasks ( unsigned portBASE_TYPE  uxPriority  ) 

Definition at line 118 of file integer.c.

References intgNUMBER_OF_TASKS, intgSTACK_SIZE, xTaskCheck, and xTaskCreate.

Referenced by main().

00119 {
00120 short sTask;
00121 
00122     for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
00123     {
00124         xTaskCreate( vCompeteingIntMathTask, ( signed char * ) "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( xTaskHandle * ) NULL );
00125     }
00126 }

portBASE_TYPE xAreIntegerMathsTaskStillRunning ( void   ) 

Definition at line 190 of file integer.c.

References intgNUMBER_OF_TASKS, pdFALSE, pdTRUE, portBASE_TYPE, and xTaskCheck.

Referenced by prvCheckOtherTasksAreStillRunning().

00191 {
00192 portBASE_TYPE xReturn = pdTRUE;
00193 short sTask;
00194 
00195     /* Check the maths tasks are still running by ensuring their check variables 
00196     are still being set to true. */
00197     for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
00198     {
00199         if( xTaskCheck[ sTask ] == pdFALSE )
00200         {
00201             /* The check has not incremented so an error exists. */
00202             xReturn = pdFALSE;
00203         }
00204 
00205         /* Reset the check variable so we can tell if it has been set by
00206         the next time around. */
00207         xTaskCheck[ sTask ] = pdFALSE;
00208     }
00209 
00210     return xReturn;
00211 }


Variable Documentation

volatile signed portBASE_TYPE xTaskCheck[intgNUMBER_OF_TASKS] = { ( signed portBASE_TYPE ) pdFALSE } [static]

Definition at line 114 of file integer.c.

Referenced by vStartIntegerMathTasks(), and xAreIntegerMathsTaskStillRunning().


Generated on Thu Dec 17 20:02:01 2009 for AVR32 UC3 - FreeRTOS Real Time Kernel by  doxygen 1.5.5