]> git.sur5r.net Git - freertos/commitdiff
Add in the comtest test tasks to the MicroBlaze demo.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 19 Jun 2011 21:19:33 +0000 (21:19 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 19 Jun 2011 21:19:33 +0000 (21:19 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1468 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/Demo_Source/comtest_strings.c
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/Demo_Source/include/serial.h
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/FreeRTOS_Source/portable/GCC/MicroBlaze/portmacro.h
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/main-full.c
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/serial.c

index 7a84768fb1dfee4cd6295d8298b34a0531fe1491..c1354e986c14cc58736ab591cbcb94adde840206 100644 (file)
@@ -161,6 +161,9 @@ size_t xStringLength;
 \r
        xStringLength = strlen( comTRANSACTED_STRING );\r
 \r
+       /* Include the null terminator in the string length. */\r
+       xStringLength++;\r
+\r
        for( ;; )\r
        {\r
                /* Send the string.  Setting the last parameter to pdTRUE ensures\r
@@ -192,83 +195,90 @@ size_t xStringLength;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+#define comtstWAITING_START_OF_STRING  0\r
+#define comtstWAITING_END_OF_STRING            1\r
+\r
+\r
 static void vComRxTask( void *pvParameters )\r
 {\r
-#if 0\r
-signed char cExpectedByte, cByteRxed;\r
-portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;\r
+portBASE_TYPE xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;\r
+char *pcExpectedByte, cRxedChar;\r
+const xComPortHandle xPort = NULL;\r
+\r
 \r
        /* Just to stop compiler warnings. */\r
        ( void ) pvParameters;\r
 \r
+       pcExpectedByte = comTRANSACTED_STRING;\r
+\r
        for( ;; )\r
        {\r
-               /* We expect to receive the characters from comFIRST_BYTE to\r
-               comLAST_BYTE in an incrementing order.  Loop to receive each byte. */\r
-               for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )\r
+               /* Wait for the next character. */\r
+               if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )\r
                {\r
-                       /* Block on the queue that contains received bytes until a byte is\r
-                       available. */\r
-                       if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )\r
-                       {\r
-                               /* Was this the byte we were expecting?  If so, toggle the LED,\r
-                               otherwise we are out on sync and should break out of the loop\r
-                               until the expected character sequence is about to restart. */\r
-                               if( cByteRxed == cExpectedByte )\r
+                       /* A character definitely should have been received by now.  As a\r
+                       character was not received an error must have occurred (which might\r
+                       just be that the loopback connector is not fitted. */\r
+                       xErrorOccurred = pdTRUE;
+               }\r
+\r
+               switch( xState )\r
+               {\r
+                       case comtstWAITING_START_OF_STRING:\r
+                               if( cRxedChar == *pcExpectedByte )\r
                                {\r
-                                       vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );\r
+                                       /* The received character was the first character of the\r
+                                       string.  Move to the next state to check each character\r
+                                       as it comes in until the entire string has been received. */\r
+                                       xState = comtstWAITING_END_OF_STRING;\r
+                                       pcExpectedByte++;\r
+                               }\r
+                               break;\r
+\r
+                       case comtstWAITING_END_OF_STRING:\r
+                               if( cRxedChar == *pcExpectedByte )\r
+                               {\r
+                                       /* The received character was the expected character.  Was\r
+                                       it the last character in the string - i.e. the null\r
+                                       terminator? */\r
+                                       if( cRxedChar == 0x00 )\r
+                                       {\r
+                                               /* The entire string has been received.  If no errors\r
+                                               have been latched, then increment the loop counter to\r
+                                               show that this task is still healthy. */
+                                               if( xErrorOccurred == pdFALSE )\r
+                                               {\r
+                                                       uxRxLoops++;\r
+\r
+                                                       /* Toggle an LED to give a visible sign that a\r
+                                                       complete string has been received. */
+                                                       vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );\r
+                                               }\r
+\r
+                                               /* Go back to wait for the start of the next string. */\r
+                                               pcExpectedByte = comTRANSACTED_STRING;\r
+                                               xState = comtstWAITING_START_OF_STRING;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               /* Wait for the next character in the string. */\r
+                                               pcExpectedByte++;\r
+                                       }\r
                                }\r
                                else\r
                                {\r
-                                       xResyncRequired = pdTRUE;\r
-                                       break; /*lint !e960 Non-switch break allowed. */\r
+                                       /* The character received was not that expected. */\r
+                                       xErrorOccurred = pdTRUE;\r
                                }\r
-                       }\r
-               }\r
-\r
-               /* Turn the LED off while we are not doing anything. */\r
-               vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );\r
+                               break;\r
 \r
-               /* Did we break out of the loop because the characters were received in\r
-               an unexpected order?  If so wait here until the character sequence is\r
-               about to restart. */\r
-               if( xResyncRequired == pdTRUE )\r
-               {\r
-                       while( cByteRxed != comLAST_BYTE )\r
-                       {\r
-                               /* Block until the next char is available. */\r
-                               xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );\r
-                       }\r
-\r
-                       /* Note that an error occurred which caused us to have to resync.\r
-                       We use this to stop incrementing the loop counter so\r
-                       sAreComTestTasksStillRunning() will return false - indicating an\r
-                       error. */\r
-                       xErrorOccurred++;\r
-\r
-                       /* We have now resynced with the Tx task and can continue. */\r
-                       xResyncRequired = pdFALSE;\r
+                       default:\r
+                               /* Should not get here.  Stop the Rx loop counter from\r
+                               incrementing to latch the error. */\r
+                               xErrorOccurred = pdTRUE;\r
+                               break;\r
                }\r
-               else\r
-               {\r
-                       if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )\r
-                       {\r
-                               /* Increment the count of successful loops.  As error\r
-                               occurring (i.e. an unexpected character being received) will\r
-                               prevent this counter being incremented for the rest of the\r
-                               execution.   Don't worry about mutual exclusion on this\r
-                               variable - it doesn't really matter as we just want it\r
-                               to change. */\r
-                               uxRxLoops++;\r
-                       }\r
-               }\r
-       }\r
-#else\r
-       for( ;; )\r
-       {\r
-               vTaskDelay( 10000 );\r
        }\r
-#endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -289,7 +299,7 @@ portBASE_TYPE xReturn;
        }\r
 \r
        /* Reset the count of successful Rx loops.  When this function is called\r
-       again we expect this to have been incremented. */\r
+       again it should have been incremented. */\r
        uxRxLoops = comINITIAL_RX_COUNT_VALUE;\r
 \r
        return xReturn;\r
index b7d27f90d7159bc6dadbcfa342e43c5c7b22c9f4..71433b81ec8a9c79ceee682442261c7fadf7f791 100644 (file)
@@ -114,7 +114,7 @@ typedef enum
 \r
 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength );\r
 xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );\r
-void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength );\r
+void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength );\r
 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime );\r
 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime );\r
 portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort );\r
index 37aa3d60727a075573b702b167cd4c1e48da25a7..15d9a0202d46c815d3a3a52a69efc6384ad7609c 100644 (file)
@@ -130,7 +130,7 @@ void vPortYield( void );
 #define portYIELD() vPortYield()\r
 \r
 void vTaskSwitchContext();\r
-#define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) vTaskSwitchContext()\r
+#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. */\r
 /*-----------------------------------------------------------*/\r
 \r
 /* Hardware specifics. */\r
index 9833ea7db9e9c8a77d9c8e3164def4f9c694faca..ed0792e809af6fdf4c9cdb317e25bc45150bfa86 100644 (file)
@@ -388,6 +388,13 @@ static long lErrorAlreadyLatched = pdFALSE;
                pcStatusMessage = "Error: Flop\r\n";\r
                xPrintf( pcStatusMessage );\r
        }\r
+\r
+       if( xAreComTestTasksStillRunning() != pdPASS )\r
+       {\r
+               pcStatusMessage = "Error: Comtest\r\n";\r
+               xPrintf( pcStatusMessage );\r
+       }\r
+\r
        /* Check the reg test tasks are still cycling.  They will stop incrementing\r
        their loop counters if they encounter an error. */\r
        if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
index bf3d36dbad03b31cc5132cd0c96b3212269017d4..605da484a9c22f9f9d9a648a411b7a88291c4f08 100644 (file)
@@ -67,7 +67,6 @@
 /* Scheduler includes. */\r
 #include "FreeRTOS.h"\r
 #include "queue.h"\r
-#include "semphr.h"\r
 #include "task.h" /*_RB_ remove this when the file is working. */\r
 #include "comtest_strings.h"\r
 \r
 #include "serial.h"\r
 /*-----------------------------------------------------------*/\r
 \r
-/* Misc defines. */\r
-#define serINVALID_QUEUE                               ( ( xQueueHandle ) 0 )\r
-#define serNO_BLOCK                                            ( ( portTickType ) 0 )\r
+static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
+static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
 \r
-/*-----------------------------------------------------------*/\r
+static XUartLite xUartLiteInstance;\r
 \r
 /* The queue used to hold received characters. */\r
 static xQueueHandle xRxedChars;\r
-static xQueueHandle xCharsForTx;\r
 \r
-static XUartLite xUartLiteInstance;\r
-\r
-static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
-static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/*\r
- * See the serial2.h header file.\r
- */\r
 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
 {\r
 portBASE_TYPE xStatus;\r
 \r
-       /* Create the queues used to hold Rx/Tx characters. */\r
+       /* Create the queue used to hold Rx characters. */\r
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
-       xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
-       \r
-       /* If the queues were created correctly then setup the serial port\r
+\r
+       /* If the queue was created correctly then setup the serial port\r
        hardware. */\r
-       if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )\r
+       if( xRxedChars != NULL )\r
        {\r
                xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );\r
 \r
                if( xStatus == XST_SUCCESS )\r
                {\r
+                       /* Complete initialisation of the UART and its associated\r
+                       interrupts. */\r
                        XUartLite_ResetFifos( &xUartLiteInstance );\r
                        XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
                        XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
@@ -134,13 +125,6 @@ portBASE_TYPE xStatus;
 \r
 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
 {\r
-extern u8 XUartLite_RecvByte(u32 BaseAddress);\r
-\r
-//     *pcRxedChar = XUartLite_RecvByte( xUartLiteInstance.RegBaseAddress );\r
-\r
-       vTaskDelay( 1000 );\r
-       return pdTRUE;\r
-#if 0\r
        /* The port handle is not required as this driver only supports one port. */\r
        ( void ) pxPort;\r
 \r
@@ -154,66 +138,23 @@ extern u8 XUartLite_RecvByte(u32 BaseAddress);
        {\r
                return pdFALSE;\r
        }\r
-#endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
+void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength )\r
 {\r
-       XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( unsigned portBASE_TYPE ) usStringLength );\r
-\r
-#if 0\r
-unsigned portBASE_TYPE uxReturn = 0U;\r
-\r
-char *pc = pc;\r
-extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);\r
-\r
-       /* Just to avoid compiler warnings. */\r
-       ( void ) pxPort;\r
-\r
-       while( uxReturn != usStringLength )\r
-       {\r
-               XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, *pc );\r
-               pc++;\r
-               uxReturn++;\r
-//             uxReturn += XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( ( unsigned portBASE_TYPE ) usStringLength ) - uxReturn );\r
-               while( XUartLite_IsSending( &xUartLiteInstance ) != pdFALSE )\r
-               {\r
-                       /*_RB_ This function is not yet written to make use of the RTOS. */\r
-               }\r
-       }\r
-#endif\r
+       XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, uxStringLength );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )\r
 {\r
-#if 1\r
-       extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);\r
-\r
-//     for( ;; )\r
-//     {\r
-               XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, cOutChar );\r
-//     }\r
-//     vTaskDelay( 2 );\r
-       return 1;\r
-#else\r
-signed portBASE_TYPE xReturn;\r
-\r
-       if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )\r
-       {\r
-               xReturn = pdPASS;\r
-               \r
-               /* Enable the UART Tx interrupt. */\r
-               XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
-       }\r
-       else\r
-       {\r
-               xReturn = pdFAIL;\r
-       }\r
+       /* Only vSerialPutString() is used in this demo. */\r
+       ( void ) pxPort;\r
+       ( void ) cOutChar;\r
+       ( void ) xBlockTime;\r
 \r
-       return xReturn;\r
-#endif\r
+       return pdFALSE;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -225,7 +166,16 @@ void vSerialClose( xComPortHandle xPort )
 \r
 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
 {\r
-       portNOP();\r
+signed char cRxedChar;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+       while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )\r
+       {\r
+               cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);\r
+               xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );\r
+       }\r
+\r
+       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. */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -238,4 +188,7 @@ static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
 \r
 \r
 \r
+\r
+\r
+\r
        \r