]> git.sur5r.net Git - freertos/commitdiff
Comment the peripheral helper files for the new MicroBlaze demo application.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Thu, 30 Jun 2011 14:42:07 +0000 (14:42 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Thu, 30 Jun 2011 14:42:07 +0000 (14:42 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1477 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/ParTest.c
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/RegisterTests.c
Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/serial.c

index 495804d43eb2b5b641c8a1a220dd9ff603d0e047..40371814db363c9e7ef2c063ffdaa92f568bacef 100644 (file)
@@ -52,7 +52,7 @@
 */\r
 \r
 /*-----------------------------------------------------------\r
- * Simple parallel port IO routines.\r
+ * Simple digital IO routines.\r
  *-----------------------------------------------------------*/\r
 \r
 /* Kernel includes. */\r
 /* Library includes. */\r
 #include "xgpio.h"\r
 \r
+/* The hardware design that accompanies this demo project has four LED \r
+outputs. */\r
 #define partstMAX_LED  4\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
+/* A hardware specific constant required to use the Xilinx driver library. */\r
 static const unsigned portBASE_TYPE uxGPIOOutputChannel = 1UL;\r
+\r
+/* The current state of the output port. */\r
 static unsigned char ucGPIOState = 0U;\r
 \r
+/* Structure that hold the state of the ouptut peripheral used by this demo.\r
+This is used by the Xilinx peripheral driver API functions. */\r
 static XGpio xOutputGPIOInstance;\r
 \r
 /*\r
@@ -101,6 +108,7 @@ void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
 {\r
 unsigned char ucLED = 1U;\r
 \r
+       /* Only attempt to set the LED if it is in range. */\r
        if( uxLED < partstMAX_LED )\r
        {\r
                ucLED <<= ( unsigned char ) uxLED;\r
@@ -126,6 +134,7 @@ void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
 {\r
 unsigned char ucLED = 1U;\r
 \r
+       /* Only attempt to toggle the LED if it is in range. */\r
        if( uxLED < partstMAX_LED )\r
        {\r
                ucLED <<= ( unsigned char ) uxLED;\r
index 906e306db221db7289eadead0eed5922a38771d8..1aa696a939ad138e8c3c4548320caca5fc014faa 100644 (file)
 #include "task.h"\r
 \r
 /*\r
- * The register test task as described at the top of this file.\r
+ * The register test task as described in the comments at the top of main-full.c.\r
  */\r
 void vRegisterTest1( void *pvParameters );\r
 void vRegisterTest2( void *pvParameters );\r
 \r
 /* Variables that are incremented on each iteration of the reg test tasks -\r
-provided the tasks have not reported any errors.  The check task inspects these\r
+provided the tasks have not reported any errors.  The check timer inspects these\r
 variables to ensure they are still incrementing as expected.  If a variable\r
-stops incrementing then it is likely that its associate task has stalled. */\r
+stops incrementing then it is likely that its associate task has stalled or\r
+detected an error. */\r
 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 void vRegisterTest1( void *pvParameters )\r
 {\r
-//_RB_ Why can R5 not be used in this test?\r
-\r
        /* This task uses an infinite loop that is implemented in the assembly \r
        code.\r
        \r
-       First fill the registers with known values. */\r
+       First fill the relevant registers with known values. */\r
        asm volatile (  "       addi r3, r0, 3          \n\t" \\r
                                        "       addi r4, r0, 4          \n\t" \\r
                                        "       addi r6, r0, 6          \n\t" \\r
@@ -105,7 +104,10 @@ void vRegisterTest1( void *pvParameters )
        /* Now test the register values to ensure they contain the same value that\r
        was written to them above.       This task will get preempted frequently so \r
        other tasks are likely to have executed since the register values were \r
-       written. */\r
+       written.  If any register contains an unexpected value then the task will\r
+       branch to Error_Loop_1, which in turn prevents it from incrementing its\r
+       loop counter, enabling the check timer to determine that all is not as it\r
+       should be. */\r
 \r
        asm volatile (  "Loop_Start_1:                          \n\t" \\r
                                        "       xori r18, r3, 3                 \n\t" \\r
@@ -157,9 +159,9 @@ void vRegisterTest1( void *pvParameters )
                                 );\r
 \r
        /* If this task has not branched to the error loop, then everything is ok,\r
-       and the check variable should be incremented to indicate that this task\r
-       is still running.  Then, brach back to the top to check the registers\r
-       again. */\r
+       and the check variable can be incremented to indicate that this task\r
+       is still running.  Then, brach back to the top to check the register\r
+       contents again. */\r
        asm volatile (  "       lwi r18, r0, ulRegTest1CycleCount       \n\t" \\r
                                        "       addik r18, r18, 1                                       \n\t" \\r
                                        "       swi r18, r0, ulRegTest1CycleCount       \n\t" \\r
@@ -202,8 +204,13 @@ void vRegisterTest2( void *pvParameters )
                                        "Loop_Start_2:                          "\r
                                );\r
 \r
+       /* Unlike vRegisterTest1, vRegisterTest2 performs a yield.  This increases\r
+       the test coverage, but does mean volatile registers need re-loading with \r
+       their exepcted values. */\r
        taskYIELD();\r
 \r
+       /* taskYIELD() could have changed temporaries - set them back to those\r
+       expected by the reg test task. */\r
        asm volatile (  "       addi r3, r0, 103        \n\t" \\r
                                        "       addi r4, r0, 104        \n\t" \\r
                                        "       addi r6, r0, 106        \n\t" \\r
@@ -215,8 +222,6 @@ void vRegisterTest2( void *pvParameters )
                                        "       addi r12, r0, 1012      \n\t" \\r
                                );\r
 \r
-       /* taskYIELD() could have changed temporaries - set them back to those\r
-       expected by the reg test task. */\r
 \r
        /* Now test the register values to ensure they contain the same value that\r
        was written to them above.       This task will get preempted frequently so \r
index fc67d9b0f40d64013375f7f613e51b46187414f6..66df57eb71bd307e8ff0b1dfa49ecb6b20958493 100644 (file)
 */\r
 \r
 /*\r
-       BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0.\r
-       \r
-       ***Note*** This example uses queues to send each character into an interrupt\r
-       service routine and out of an interrupt service routine individually.  This\r
-       is done to demonstrate queues being used in an interrupt, and to deliberately\r
-       load the system to test the FreeRTOS port.  It is *NOT* meant to be an\r
-       example of an efficient implementation.  An efficient implementation should\r
-       use FIFOs or DMA if available, and only use FreeRTOS API functions when\r
-       enough has been received to warrant a task being unblocked to process the\r
-       data.\r
+       BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.\r
 */\r
 \r
 /* Scheduler includes. */\r
 #include "FreeRTOS.h"\r
 #include "queue.h"\r
-#include "task.h" /*_RB_ remove this when the file is working. */\r
 #include "comtest_strings.h"\r
 \r
 /* Library includes. */\r
 \r
 /* Demo application includes. */\r
 #include "serial.h"\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
+/* Functions that are installed as the handler for interrupts that are caused by\r
+Rx and Tx events respectively. */\r
 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
 \r
+/* Structure that hold the state of the UARTLite peripheral used by this demo.\r
+This is used by the Xilinx peripheral driver API functions. */\r
 static XUartLite xUartLiteInstance;\r
 \r
 /* The queue used to hold received characters. */\r
 static xQueueHandle xRxedChars;\r
 \r
-\r
 /*-----------------------------------------------------------*/\r
 \r
 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
 {\r
 portBASE_TYPE xStatus;\r
 \r
+       /* The standard demo header file requires a baud rate to be passed into this\r
+       function.  However, in this case the baud rate is configured when the\r
+       hardware is generated, leaving the ulWantedBaud parameter redundant. */\r
+       ( void ) ulWantedBaud;\r
+\r
        /* Create the queue used to hold Rx characters. */\r
        xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
 \r
-       /* If the queue was created correctly then setup the serial port\r
+       /* If the queue was created correctly, then setup the serial port\r
        hardware. */\r
        if( xRxedChars != NULL )\r
        {\r
@@ -107,10 +106,24 @@ portBASE_TYPE xStatus;
                        /* Complete initialisation of the UART and its associated\r
                        interrupts. */\r
                        XUartLite_ResetFifos( &xUartLiteInstance );\r
+                       \r
+                       /* Install the handlers that the standard Xilinx library interrupt\r
+                       service routine will call when Rx and Tx events occur \r
+                       respectively. */\r
                        XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
                        XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
+                       \r
+                       /* Install the standard Xilinx library interrupt handler itself.\r
+                       *NOTE* The xPortInstallInterruptHandler() API function must be used \r
+                       for     this purpose. */                        \r
                        xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );\r
+                       \r
+                       /* Enable the interrupt in the peripheral. */\r
                        XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
+                       \r
+                       /* Enable the interrupt in the interrupt controller.\r
+                       *NOTE* The vPortEnableInterrupt() API function must be used for this\r
+                       purpose. */\r
                        vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
                }\r
 \r
@@ -128,8 +141,8 @@ portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, po
        /* The port handle is not required as this driver only supports one port. */\r
        ( void ) pxPort;\r
 \r
-       /* Get the next character from the buffer.  Return false if no characters\r
-       are available, or arrive before xBlockTime expires. */\r
+       /* Get the next character from the receive queue.  Return false if no \r
+       characters are available, or arrive before xBlockTime expires. */\r
        if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
        {\r
                return pdTRUE;\r
@@ -143,44 +156,38 @@ portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, po
 \r
 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength )\r
 {\r
+       /* Output uxStringLength bytes starting from pcString. */\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
-       /* Only vSerialPutString() is used in this demo. */\r
-       ( void ) pxPort;\r
-       ( void ) cOutChar;\r
-       ( void ) xBlockTime;\r
-\r
-       return pdFALSE;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vSerialClose( xComPortHandle xPort )\r
-{\r
-       /* Not supported as not required by the demo application. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
 {\r
 signed char cRxedChar;\r
 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
 \r
+       /* Place any received characters into the receive queue. */\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
+       /* If calling xQueueSendFromISR() caused a task to unblock, and the task \r
+       that unblocked has a priority equal to or greater than the task currently\r
+       in the Running state (the task that was interrupted), then \r
+       xHigherPriorityTaskWoken will have been set to pdTRUE internally within the\r
+       xQueueSendFromISR() API function.  If xHigherPriorityTaskWoken is equal to\r
+       pdTRUE then a context switch should be requested to ensure that the \r
+       interrupt returns to the highest priority task that is able     to run. */\r
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
 {\r
+       /* Nothing to do here.  The Xilinx library function takes care of the\r
+       transmission. */\r
        portNOP();\r
 }\r
 \r