Add in the comtest test tasks to the MicroBlaze demo.

pull/4/head
Richard Barry 14 years ago
parent 7b24b4c30c
commit a4de9fa8f6

@ -161,6 +161,9 @@ size_t xStringLength;
xStringLength = strlen( comTRANSACTED_STRING );
/* Include the null terminator in the string length. */
xStringLength++;
for( ;; )
{
/* Send the string. Setting the last parameter to pdTRUE ensures
@ -192,83 +195,90 @@ size_t xStringLength;
}
/*-----------------------------------------------------------*/
#define comtstWAITING_START_OF_STRING 0
#define comtstWAITING_END_OF_STRING 1
static void vComRxTask( void *pvParameters )
{
#if 0
signed char cExpectedByte, cByteRxed;
portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
portBASE_TYPE xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
char *pcExpectedByte, cRxedChar;
const xComPortHandle xPort = NULL;
/* Just to stop compiler warnings. */
( void ) pvParameters;
pcExpectedByte = comTRANSACTED_STRING;
for( ;; )
{
/* We expect to receive the characters from comFIRST_BYTE to
comLAST_BYTE in an incrementing order. Loop to receive each byte. */
for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
{
/* Block on the queue that contains received bytes until a byte is
available. */
if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
{
/* Was this the byte we were expecting? If so, toggle the LED,
otherwise we are out on sync and should break out of the loop
until the expected character sequence is about to restart. */
if( cByteRxed == cExpectedByte )
/* Wait for the next character. */
if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
{
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
/* A character definitely should have been received by now. As a
character was not received an error must have occurred (which might
just be that the loopback connector is not fitted. */
xErrorOccurred = pdTRUE;
}
else
switch( xState )
{
xResyncRequired = pdTRUE;
break; /*lint !e960 Non-switch break allowed. */
}
}
case comtstWAITING_START_OF_STRING:
if( cRxedChar == *pcExpectedByte )
{
/* The received character was the first character of the
string. Move to the next state to check each character
as it comes in until the entire string has been received. */
xState = comtstWAITING_END_OF_STRING;
pcExpectedByte++;
}
break;
/* Turn the LED off while we are not doing anything. */
vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
/* Did we break out of the loop because the characters were received in
an unexpected order? If so wait here until the character sequence is
about to restart. */
if( xResyncRequired == pdTRUE )
case comtstWAITING_END_OF_STRING:
if( cRxedChar == *pcExpectedByte )
{
while( cByteRxed != comLAST_BYTE )
/* The received character was the expected character. Was
it the last character in the string - i.e. the null
terminator? */
if( cRxedChar == 0x00 )
{
/* Block until the next char is available. */
xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
}
/* The entire string has been received. If no errors
have been latched, then increment the loop counter to
show that this task is still healthy. */
if( xErrorOccurred == pdFALSE )
{
uxRxLoops++;
/* Note that an error occurred which caused us to have to resync.
We use this to stop incrementing the loop counter so
sAreComTestTasksStillRunning() will return false - indicating an
error. */
xErrorOccurred++;
/* Toggle an LED to give a visible sign that a
complete string has been received. */
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
}
/* We have now resynced with the Tx task and can continue. */
xResyncRequired = pdFALSE;
/* Go back to wait for the start of the next string. */
pcExpectedByte = comTRANSACTED_STRING;
xState = comtstWAITING_START_OF_STRING;
}
else
{
if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
{
/* Increment the count of successful loops. As error
occurring (i.e. an unexpected character being received) will
prevent this counter being incremented for the rest of the
execution. Don't worry about mutual exclusion on this
variable - it doesn't really matter as we just want it
to change. */
uxRxLoops++;
/* Wait for the next character in the string. */
pcExpectedByte++;
}
}
}
#else
for( ;; )
else
{
vTaskDelay( 10000 );
/* The character received was not that expected. */
xErrorOccurred = pdTRUE;
}
break;
default:
/* Should not get here. Stop the Rx loop counter from
incrementing to latch the error. */
xErrorOccurred = pdTRUE;
break;
}
}
#endif
}
/*-----------------------------------------------------------*/
@ -289,7 +299,7 @@ portBASE_TYPE xReturn;
}
/* Reset the count of successful Rx loops. When this function is called
again we expect this to have been incremented. */
again it should have been incremented. */
uxRxLoops = comINITIAL_RX_COUNT_VALUE;
return xReturn;

@ -114,7 +114,7 @@ typedef enum
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength );
xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength );
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength );
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime );
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime );
portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort );

@ -130,7 +130,7 @@ void vPortYield( void );
#define portYIELD() vPortYield()
void vTaskSwitchContext();
#define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) vTaskSwitchContext()
#define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) vTaskSwitchContext() //_RB_ This needs re-implementing so it does not get called multiple times as multiple peripherals are servied in a single ISR. */
/*-----------------------------------------------------------*/
/* Hardware specifics. */

@ -388,6 +388,13 @@ static long lErrorAlreadyLatched = pdFALSE;
pcStatusMessage = "Error: Flop\r\n";
xPrintf( pcStatusMessage );
}
if( xAreComTestTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Comtest\r\n";
xPrintf( pcStatusMessage );
}
/* Check the reg test tasks are still cycling. They will stop incrementing
their loop counters if they encounter an error. */
if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )

@ -67,7 +67,6 @@
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "task.h" /*_RB_ remove this when the file is working. */
#include "comtest_strings.h"
@ -79,42 +78,34 @@
#include "serial.h"
/*-----------------------------------------------------------*/
/* Misc defines. */
#define serINVALID_QUEUE ( ( xQueueHandle ) 0 )
#define serNO_BLOCK ( ( portTickType ) 0 )
static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
/*-----------------------------------------------------------*/
static XUartLite xUartLiteInstance;
/* The queue used to hold received characters. */
static xQueueHandle xRxedChars;
static xQueueHandle xCharsForTx;
static XUartLite xUartLiteInstance;
static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
/*-----------------------------------------------------------*/
/*
* See the serial2.h header file.
*/
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
portBASE_TYPE xStatus;
/* Create the queues used to hold Rx/Tx characters. */
/* Create the queue used to hold Rx characters. */
xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
/* If the queues were created correctly then setup the serial port
/* If the queue was created correctly then setup the serial port
hardware. */
if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
if( xRxedChars != NULL )
{
xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
if( xStatus == XST_SUCCESS )
{
/* Complete initialisation of the UART and its associated
interrupts. */
XUartLite_ResetFifos( &xUartLiteInstance );
XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
@ -134,13 +125,6 @@ portBASE_TYPE xStatus;
portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
{
extern u8 XUartLite_RecvByte(u32 BaseAddress);
// *pcRxedChar = XUartLite_RecvByte( xUartLiteInstance.RegBaseAddress );
vTaskDelay( 1000 );
return pdTRUE;
#if 0
/* The port handle is not required as this driver only supports one port. */
( void ) pxPort;
@ -154,66 +138,23 @@ extern u8 XUartLite_RecvByte(u32 BaseAddress);
{
return pdFALSE;
}
#endif
}
/*-----------------------------------------------------------*/
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength )
{
XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( unsigned portBASE_TYPE ) usStringLength );
#if 0
unsigned portBASE_TYPE uxReturn = 0U;
char *pc = pc;
extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);
/* Just to avoid compiler warnings. */
( void ) pxPort;
while( uxReturn != usStringLength )
{
XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, *pc );
pc++;
uxReturn++;
// uxReturn += XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( ( unsigned portBASE_TYPE ) usStringLength ) - uxReturn );
while( XUartLite_IsSending( &xUartLiteInstance ) != pdFALSE )
{
/*_RB_ This function is not yet written to make use of the RTOS. */
}
}
#endif
XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, uxStringLength );
}
/*-----------------------------------------------------------*/
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
{
#if 1
extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);
// for( ;; )
// {
XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, cOutChar );
// }
// vTaskDelay( 2 );
return 1;
#else
signed portBASE_TYPE xReturn;
if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )
{
xReturn = pdPASS;
/* Enable the UART Tx interrupt. */
XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
}
else
{
xReturn = pdFAIL;
}
/* Only vSerialPutString() is used in this demo. */
( void ) pxPort;
( void ) cOutChar;
( void ) xBlockTime;
return xReturn;
#endif
return pdFALSE;
}
/*-----------------------------------------------------------*/
@ -225,7 +166,16 @@ void vSerialClose( xComPortHandle xPort )
static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
{
portNOP();
signed char cRxedChar;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
{
cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); //_RB_ This needs re-implementing so it does not get called multiple times as multiple peripherals are servied in a single ISR. */
}
/*-----------------------------------------------------------*/
@ -239,3 +189,6 @@ static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )

Loading…
Cancel
Save