crhook.c File Reference

#include "FreeRTOS.h"
#include "croutine.h"
#include "queue.h"
#include "crhook.h"

Go to the source code of this file.

Defines

#define hookHOOK_QUEUE_LENGTH   ( 1 )
#define hookNO_BLOCK_TIME   ( 0 )
#define hookNUM_HOOK_CO_ROUTINES   ( 4 )
#define hookTICK_CALLS_BEFORE_POST   ( 500 )
#define mainHOOK_CR_PRIORITY   ( 1 )

Functions

static void prvHookCoRoutine (xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex)
void vApplicationTickHook (void)
void vStartHookCoRoutines (void)
portBASE_TYPE xAreHookCoRoutinesStillRunning (void)

Variables

static unsigned portBASE_TYPE uxCallCounter = 0
static unsigned portBASE_TYPE uxNumberToPost = 0
static portBASE_TYPE xCoRoutineErrorDetected = pdFALSE
static xQueueHandle xHookRxQueues [hookNUM_HOOK_CO_ROUTINES]
static xQueueHandle xHookTxQueues [hookNUM_HOOK_CO_ROUTINES]


Define Documentation

#define hookHOOK_QUEUE_LENGTH   ( 1 )

Definition at line 93 of file crhook.c.

Referenced by vStartHookCoRoutines().

#define hookNO_BLOCK_TIME   ( 0 )

Definition at line 96 of file crhook.c.

Referenced by prvHookCoRoutine(), and vStartHookCoRoutines().

#define hookNUM_HOOK_CO_ROUTINES   ( 4 )

Definition at line 86 of file crhook.c.

Referenced by prvHookCoRoutine(), vApplicationTickHook(), and vStartHookCoRoutines().

#define hookTICK_CALLS_BEFORE_POST   ( 500 )

Definition at line 90 of file crhook.c.

Referenced by vApplicationTickHook().

#define mainHOOK_CR_PRIORITY   ( 1 )

Definition at line 100 of file crhook.c.

Referenced by vStartHookCoRoutines().


Function Documentation

static void prvHookCoRoutine ( xCoRoutineHandle  xHandle,
unsigned portBASE_TYPE  uxIndex 
) [static]

Definition at line 208 of file crhook.c.

References crEND, crQUEUE_RECEIVE, crQUEUE_SEND, crSTART, hookNO_BLOCK_TIME, hookNUM_HOOK_CO_ROUTINES, pdFAIL, pdPASS, pdTRUE, portBASE_TYPE, portMAX_DELAY, xCoRoutineErrorDetected, xHookRxQueues, and xHookTxQueues.

Referenced by vStartHookCoRoutines().

00209 {
00210 static unsigned portBASE_TYPE uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
00211 portBASE_TYPE xResult;
00212 
00213     /* Each co-routine MUST start with a call to crSTART(); */
00214     crSTART( xHandle );
00215 
00216     for( ;; )
00217     {
00218         /* Wait to receive a value from the tick hook. */
00219         xResult = pdFAIL;
00220         crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );
00221 
00222         /* There is no reason why we should not have received something on
00223         the queue. */
00224         if( xResult != pdPASS )
00225         {
00226             xCoRoutineErrorDetected = pdTRUE;
00227         }
00228 
00229         /* Send the same number back to the idle hook so it can verify it. */
00230         xResult = pdFAIL;
00231         crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult );
00232         if( xResult != pdPASS )
00233         {
00234             /* There is no reason why we should not have been able to post to 
00235             the queue. */
00236             xCoRoutineErrorDetected = pdTRUE;
00237         }
00238     }
00239 
00240     /* Each co-routine MUST end with a call to crEND(). */
00241     crEND();
00242 }

void vApplicationTickHook ( void   ) 

Definition at line 155 of file crhook.c.

References crQUEUE_RECEIVE_FROM_ISR, crQUEUE_SEND_FROM_ISR, hookNUM_HOOK_CO_ROUTINES, hookTICK_CALLS_BEFORE_POST, pdFALSE, pdPASS, pdTRUE, portBASE_TYPE, uxCallCounter, uxNumberToPost, xCoRoutineErrorDetected, xHookRxQueues, and xHookTxQueues.

Referenced by vTaskIncrementTick().

00156 {
00157 unsigned portBASE_TYPE uxReceivedNumber;
00158 signed portBASE_TYPE xIndex, xCoRoutineWoken;
00159 
00160     /* Is it time to talk to the 'hook' co-routines again? */
00161     uxCallCounter++;
00162     if( uxCallCounter >= hookTICK_CALLS_BEFORE_POST )
00163     {
00164         uxCallCounter = 0;
00165 
00166         for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
00167         {
00168             xCoRoutineWoken = pdFALSE;
00169             if( crQUEUE_RECEIVE_FROM_ISR( xHookRxQueues[ xIndex ], &uxReceivedNumber, &xCoRoutineWoken ) != pdPASS )
00170             {
00171                 /* There is no reason why we would not expect the queue to 
00172                 contain a value. */
00173                 xCoRoutineErrorDetected = pdTRUE;
00174             }
00175             else
00176             {
00177                 /* Each queue used to receive data from the 'hook' co-routines 
00178                 should contain the number we last posted to the same co-routine. */
00179                 if( uxReceivedNumber != uxNumberToPost )
00180                 {
00181                     xCoRoutineErrorDetected = pdTRUE;
00182                 }
00183 
00184                 /* Nothing should be blocked waiting to post to the queue. */
00185                 if( xCoRoutineWoken != pdFALSE )
00186                 {
00187                     xCoRoutineErrorDetected = pdTRUE;
00188                 }
00189             }
00190         }
00191 
00192         /* Start the next cycle by posting the next number onto each Tx queue. */
00193         uxNumberToPost++;
00194 
00195         for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
00196         {
00197             if( crQUEUE_SEND_FROM_ISR( xHookTxQueues[ xIndex ], &uxNumberToPost, pdFALSE ) != pdTRUE )
00198             {
00199                 /* Posting to the queue should have woken the co-routine that 
00200                 was blocked on the queue. */
00201                 xCoRoutineErrorDetected = pdTRUE;
00202             }
00203         }
00204     }
00205 }

void vStartHookCoRoutines ( void   ) 

Definition at line 133 of file crhook.c.

References hookHOOK_QUEUE_LENGTH, hookNO_BLOCK_TIME, hookNUM_HOOK_CO_ROUTINES, mainHOOK_CR_PRIORITY, portBASE_TYPE, prvHookCoRoutine(), xCoRoutineCreate(), xHookRxQueues, xHookTxQueues, xQueueCreate(), and xQueueSend.

00134 {
00135 unsigned portBASE_TYPE uxIndex, uxValueToPost = 0;
00136 
00137     for( uxIndex = 0; uxIndex < hookNUM_HOOK_CO_ROUTINES; uxIndex++ )
00138     {
00139         /* Create a queue to transmit to and receive from each 'hook' 
00140         co-routine. */
00141         xHookRxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );
00142         xHookTxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );
00143 
00144         /* To start things off the tick hook function expects the queue it 
00145         uses to receive data to contain a value.  */
00146         xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
00147 
00148         /* Create the 'hook' co-routine itself. */
00149         xCoRoutineCreate( prvHookCoRoutine, mainHOOK_CR_PRIORITY, uxIndex );
00150     }
00151 }

portBASE_TYPE xAreHookCoRoutinesStillRunning ( void   ) 

Definition at line 245 of file crhook.c.

References pdFALSE, pdTRUE, and xCoRoutineErrorDetected.

00246 {
00247     if( xCoRoutineErrorDetected )
00248     {
00249         return pdFALSE;
00250     }
00251     else
00252     {
00253         return pdTRUE;
00254     }
00255 }


Variable Documentation

unsigned portBASE_TYPE uxCallCounter = 0 [static]

Definition at line 154 of file crhook.c.

Referenced by vApplicationTickHook().

unsigned portBASE_TYPE uxNumberToPost = 0 [static]

Definition at line 154 of file crhook.c.

Referenced by vApplicationTickHook().

portBASE_TYPE xCoRoutineErrorDetected = pdFALSE [static]

xQueueHandle xHookRxQueues[hookNUM_HOOK_CO_ROUTINES] [static]

Definition at line 121 of file crhook.c.

Referenced by prvHookCoRoutine(), vApplicationTickHook(), and vStartHookCoRoutines().

xQueueHandle xHookTxQueues[hookNUM_HOOK_CO_ROUTINES] [static]

Definition at line 126 of file crhook.c.

Referenced by prvHookCoRoutine(), vApplicationTickHook(), and vStartHookCoRoutines().


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