comtest.c File Reference

#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "serial.h"
#include "comtest.h"
#include "partest.h"

Go to the source code of this file.

Defines

#define comBUFFER_LEN   ( ( unsigned portBASE_TYPE ) ( comLAST_BYTE - comFIRST_BYTE ) + ( unsigned portBASE_TYPE ) 1 )
#define comFIRST_BYTE   ( 'A' )
#define comINITIAL_RX_COUNT_VALUE   ( 0 )
#define comLAST_BYTE   ( 'X' )
#define comNO_BLOCK   ( ( portTickType ) 0 )
#define comOFFSET_TIME   ( ( portTickType ) 3 )
#define comRX_BLOCK_TIME   ( ( portTickType ) 0xffff )
#define comRX_LED_OFFSET   ( 1 )
#define comSTACK_SIZE   configMINIMAL_STACK_SIZE
#define comTOTAL_PERMISSIBLE_ERRORS   ( 2 )
#define comTX_LED_OFFSET   ( 0 )
#define comTX_MAX_BLOCK_TIME   ( ( portTickType ) 0x96 )
#define comTX_MIN_BLOCK_TIME   ( ( portTickType ) 0x32 )

Functions

static portTASK_FUNCTION (vComRxTask, pvParameters)
static portTASK_FUNCTION (vComTxTask, pvParameters)
static portTASK_FUNCTION_PROTO (vComRxTask, pvParameters)
static portTASK_FUNCTION_PROTO (vComTxTask, pvParameters)
void vAltStartComTestTasks (unsigned portBASE_TYPE uxPriority, unsigned long ulBaudRate, unsigned portBASE_TYPE uxLED)
portBASE_TYPE xAreComTestTasksStillRunning (void)

Variables

static unsigned portBASE_TYPE uxBaseLED = 0
static volatile unsigned
portBASE_TYPE 
uxRxLoops = comINITIAL_RX_COUNT_VALUE
static xComPortHandle xPort = NULL


Define Documentation

#define comBUFFER_LEN   ( ( unsigned portBASE_TYPE ) ( comLAST_BYTE - comFIRST_BYTE ) + ( unsigned portBASE_TYPE ) 1 )

Definition at line 118 of file comtest.c.

Referenced by vAltStartComTestTasks().

#define comFIRST_BYTE   ( 'A' )

Definition at line 115 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comINITIAL_RX_COUNT_VALUE   ( 0 )

Definition at line 119 of file comtest.c.

Referenced by xAreComTestTasksStillRunning().

#define comLAST_BYTE   ( 'X' )

Definition at line 116 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comNO_BLOCK   ( ( portTickType ) 0 )

Definition at line 109 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comOFFSET_TIME   ( ( portTickType ) 3 )

Definition at line 105 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comRX_BLOCK_TIME   ( ( portTickType ) 0xffff )

Definition at line 112 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comRX_LED_OFFSET   ( 1 )

Definition at line 98 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comSTACK_SIZE   configMINIMAL_STACK_SIZE

Definition at line 96 of file comtest.c.

Referenced by vAltStartComTestTasks().

#define comTOTAL_PERMISSIBLE_ERRORS   ( 2 )

Definition at line 99 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comTX_LED_OFFSET   ( 0 )

Definition at line 97 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comTX_MAX_BLOCK_TIME   ( ( portTickType ) 0x96 )

Definition at line 103 of file comtest.c.

Referenced by portTASK_FUNCTION().

#define comTX_MIN_BLOCK_TIME   ( ( portTickType ) 0x32 )

Definition at line 104 of file comtest.c.

Referenced by portTASK_FUNCTION().


Function Documentation

static portTASK_FUNCTION ( vComRxTask  ,
pvParameters   
) [static]

Definition at line 196 of file comtest.c.

References comFIRST_BYTE, comLAST_BYTE, comRX_BLOCK_TIME, comRX_LED_OFFSET, comTOTAL_PERMISSIBLE_ERRORS, pdFALSE, pdTRUE, portBASE_TYPE, uxBaseLED, uxRxLoops, vParTestSetLED(), vParTestToggleLED(), xErrorOccurred, xPort, and xSerialGetChar().

00197 {
00198 signed char cExpectedByte, cByteRxed;
00199 portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
00200 
00201     /* Just to stop compiler warnings. */
00202     ( void ) pvParameters;
00203 
00204     for( ;; )
00205     {
00206         /* We expect to receive the characters from comFIRST_BYTE to
00207         comLAST_BYTE in an incrementing order.  Loop to receive each byte. */
00208         for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
00209         {
00210             /* Block on the queue that contains received bytes until a byte is
00211             available. */
00212             if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
00213             {
00214                 /* Was this the byte we were expecting?  If so, toggle the LED,
00215                 otherwise we are out on sync and should break out of the loop
00216                 until the expected character sequence is about to restart. */
00217                 if( cByteRxed == cExpectedByte )
00218                 {
00219                     vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
00220                 }
00221                 else
00222                 {
00223                     xResyncRequired = pdTRUE;
00224                     break; /*lint !e960 Non-switch break allowed. */
00225                 }
00226             }
00227         }
00228 
00229         /* Turn the LED off while we are not doing anything. */
00230         vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
00231 
00232         /* Did we break out of the loop because the characters were received in
00233         an unexpected order?  If so wait here until the character sequence is
00234         about to restart. */
00235         if( xResyncRequired == pdTRUE )
00236         {
00237             while( cByteRxed != comLAST_BYTE )
00238             {
00239                 /* Block until the next char is available. */
00240                 xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
00241             }
00242 
00243             /* Note that an error occurred which caused us to have to resync.
00244             We use this to stop incrementing the loop counter so
00245             sAreComTestTasksStillRunning() will return false - indicating an
00246             error. */
00247             xErrorOccurred++;
00248 
00249             /* We have now resynced with the Tx task and can continue. */
00250             xResyncRequired = pdFALSE;
00251         }
00252         else
00253         {
00254             if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
00255             {
00256                 /* Increment the count of successful loops.  As error
00257                 occurring (i.e. an unexpected character being received) will
00258                 prevent this counter being incremented for the rest of the
00259                 execution.   Don't worry about mutual exclusion on this
00260                 variable - it doesn't really matter as we just want it
00261                 to change. */
00262                 uxRxLoops++;
00263             }
00264         }
00265     }
00266 } /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */

static portTASK_FUNCTION ( vComTxTask  ,
pvParameters   
) [static]

Definition at line 154 of file comtest.c.

References comFIRST_BYTE, comLAST_BYTE, comNO_BLOCK, comOFFSET_TIME, comTX_LED_OFFSET, comTX_MAX_BLOCK_TIME, comTX_MIN_BLOCK_TIME, pdFALSE, pdPASS, uxBaseLED, vParTestSetLED(), vParTestToggleLED(), vTaskDelay(), xPort, xSerialPutChar(), and xTaskGetTickCount().

00155 {
00156 signed char cByteToSend;
00157 portTickType xTimeToWait;
00158 
00159     /* Just to stop compiler warnings. */
00160     ( void ) pvParameters;
00161 
00162     for( ;; )
00163     {
00164         /* Simply transmit a sequence of characters from comFIRST_BYTE to
00165         comLAST_BYTE. */
00166         for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
00167         {
00168             if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
00169             {
00170                 vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
00171             }
00172         }
00173 
00174         /* Turn the LED off while we are not doing anything. */
00175         vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
00176 
00177         /* We have posted all the characters in the string - wait before
00178         re-sending.  Wait a pseudo-random time as this will provide a better
00179         test. */
00180         xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
00181 
00182         /* Make sure we don't wait too long... */
00183         xTimeToWait %= comTX_MAX_BLOCK_TIME;
00184 
00185         /* ...but we do want to wait. */
00186         if( xTimeToWait < comTX_MIN_BLOCK_TIME )
00187         {
00188             xTimeToWait = comTX_MIN_BLOCK_TIME;
00189         }
00190 
00191         vTaskDelay( xTimeToWait );
00192     }
00193 } /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */

static portTASK_FUNCTION_PROTO ( vComRxTask  ,
pvParameters   
) [static]

static portTASK_FUNCTION_PROTO ( vComTxTask  ,
pvParameters   
) [static]

void vAltStartComTestTasks ( unsigned portBASE_TYPE  uxPriority,
unsigned long  ulBaudRate,
unsigned portBASE_TYPE  uxLED 
)

Definition at line 142 of file comtest.c.

References comBUFFER_LEN, comSTACK_SIZE, uxBaseLED, xSerialPortInitMinimal(), and xTaskCreate.

Referenced by main().

00143 {
00144     /* Initialise the com port then spawn the Rx and Tx tasks. */
00145     uxBaseLED = uxLED;
00146     xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
00147 
00148     /* The Tx task is spawned with a lower priority than the Rx task. */
00149     xTaskCreate( vComTxTask, ( signed char * ) "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( xTaskHandle * ) NULL );
00150     xTaskCreate( vComRxTask, ( signed char * ) "COMRx", comSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
00151 }

portBASE_TYPE xAreComTestTasksStillRunning ( void   ) 

Definition at line 269 of file comtest.c.

References comINITIAL_RX_COUNT_VALUE, pdFALSE, pdTRUE, portBASE_TYPE, and uxRxLoops.

Referenced by prvCheckOtherTasksAreStillRunning().

00270 {
00271 portBASE_TYPE xReturn;
00272 
00273     /* If the count of successful reception loops has not changed than at
00274     some time an error occurred (i.e. a character was received out of sequence)
00275     and we will return false. */
00276     if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
00277     {
00278         xReturn = pdFALSE;
00279     }
00280     else
00281     {
00282         xReturn = pdTRUE;
00283     }
00284 
00285     /* Reset the count of successful Rx loops.  When this function is called
00286     again we expect this to have been incremented. */
00287     uxRxLoops = comINITIAL_RX_COUNT_VALUE;
00288 
00289     return xReturn;
00290 }


Variable Documentation

unsigned portBASE_TYPE uxBaseLED = 0 [static]

Definition at line 133 of file comtest.c.

Referenced by portTASK_FUNCTION(), and vAltStartComTestTasks().

volatile unsigned portBASE_TYPE uxRxLoops = comINITIAL_RX_COUNT_VALUE [static]

Definition at line 138 of file comtest.c.

Referenced by portTASK_FUNCTION(), and xAreComTestTasksStillRunning().

xComPortHandle xPort = NULL [static]

Definition at line 122 of file comtest.c.

Referenced by portTASK_FUNCTION().


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