]> git.sur5r.net Git - freertos/blobdiff - Demo/ARM7_AT91SAM7S64_IAR/USB/USBSample.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / ARM7_AT91SAM7S64_IAR / USB / USBSample.c
index 90d7a1bbd6766c5e4f5b19b447a0f01015f34ecf..ab575203590227d387c2f2a7f31749e69174b05c 100644 (file)
@@ -1,48 +1,79 @@
 /*\r
-       FreeRTOS.org V4.5.0 - Copyright (C) 2003-2007 Richard Barry.\r
-\r
-       This file is part of the FreeRTOS.org distribution.\r
-\r
-       FreeRTOS.org is free software; you can redistribute it and/or modify\r
-       it under the terms of the GNU General Public License as published by\r
-       the Free Software Foundation; either version 2 of the License, or\r
-       (at your option) any later version.\r
-\r
-       FreeRTOS.org is distributed in the hope that it will be useful,\r
-       but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-       GNU General Public License for more details.\r
-\r
-       You should have received a copy of the GNU General Public License\r
-       along with FreeRTOS.org; if not, write to the Free Software\r
-       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
-\r
-       A special exception to the GPL can be applied should you wish to distribute\r
-       a combined work that includes FreeRTOS.org, without being obliged to provide\r
-       the source code for any proprietary components.  See the licensing section \r
-       of http://www.FreeRTOS.org for full details of how and when the exception\r
-       can be applied.\r
-\r
-       ***************************************************************************\r
-       See http://www.FreeRTOS.org for documentation, latest information, license \r
-       and contact details.  Please ensure to read the configuration and relevant \r
-       port sections of the online documentation.\r
-\r
-       Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
-       with commercial development and support options.\r
-       ***************************************************************************\r
+    FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
+       \r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+\r
+    This file is part of the FreeRTOS distribution.\r
+\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+    by writing to Richard Barry, contact details for whom are available on the\r
+    FreeRTOS WEB site.\r
+\r
+    1 tab == 4 spaces!\r
+    \r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    Having a problem?  Start by reading the FAQ "My application does   *\r
+     *    not run, what could be wrong?                                      *\r
+     *                                                                       *\r
+     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    \r
+    http://www.FreeRTOS.org - Documentation, training, latest information, \r
+    license and contact details.\r
+    \r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool.\r
+\r
+    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
+    the code with commercial support, indemnification, and middleware, under \r
+    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
+    provide a safety engineered and independently SIL3 certified version under \r
+    the SafeRTOS brand: http://www.SafeRTOS.com.\r
 */\r
 \r
 /*\r
-       Sample interrupt driven USB device driver.  This is a minimal implementation \r
+       Sample interrupt driven USB device driver.  This is a minimal implementation\r
        for demonstration only.  Although functional, it is not a full and compliant\r
-       implementation.  \r
+       implementation.\r
        \r
        The USB device enumerates as a simple 3 axis joystick, and once configured\r
        transmits 3 axis of data which can be viewed from the USB host machine.\r
 \r
-       This file implements the USB interrupt service routine, and a demo FreeRTOS \r
-       task.  The interrupt service routine handles the USB hardware - taking a \r
+       This file implements the USB interrupt service routine, and a demo FreeRTOS\r
+       task.  The interrupt service routine handles the USB hardware - taking a\r
        snapshot of the USB status at the point of the interrupt.  The task receives\r
        the status information from the interrupt for processing at the task level.\r
        \r
@@ -53,7 +84,7 @@
        Changes from V2.5.5\r
        \r
        + Descriptors that have a length that is an exact multiple of usbFIFO_LENGTH\r
-         can now be transmitted.  To this end an extra parameter has been \r
+         can now be transmitted.  To this end an extra parameter has been\r
          added to the prvSendControlData() function, and the state\r
          eSENDING_EVEN_DESCRIPTOR has been introduced.  Thanks to Scott Miller for\r
          assisting with this contribution.\r
 #define usbINTERFACE_STRING                                    ( 4 )\r
 \r
 /* Data indexes for reading the request from the xISRStatus.ucFifoData[]\r
-into xUSB_REQUEST.  The data order is designed for speed - so looks a \r
+into xUSB_REQUEST.  The data order is designed for speed - so looks a\r
 little odd. */\r
 #define usbREQUEST_TYPE_INDEX                          ( 7 )\r
 #define usbREQUEST_INDEX                                       ( 6 )\r
@@ -127,7 +158,7 @@ little odd. */
 /* Misc application definitions. */\r
 #define usbINTERRUPT_PRIORITY                          ( 3 )\r
 #define usbQUEUE_LENGTH                                                ( 0x3 ) /* Must have all bits set! */\r
-#define usbFIFO_LENGTH                                         ( ( unsigned portLONG ) 8 )\r
+#define usbFIFO_LENGTH                                         ( ( unsigned long ) 8 )\r
 #define usbEND_POINT_0                                         ( 0 )\r
 #define usbEND_POINT_1                                         ( 1 )\r
 #define usbXUP                                                         ( 1 )\r
@@ -136,14 +167,14 @@ little odd. */
 #define usbYDOWN                                                       ( 4 )\r
 #define usbMAX_COORD                                           ( 120 )\r
 #define usbMAX_TX_MESSAGE_SIZE                         ( 128 )\r
-#define usbRX_COUNT_MASK                                       ( ( unsigned portLONG ) 0x7ff )\r
+#define usbRX_COUNT_MASK                                       ( ( unsigned long ) 0x7ff )\r
 #define AT91C_UDP_STALLSENT                                    AT91C_UDP_ISOERROR\r
 #define usbSHORTEST_DELAY                                      ( ( portTickType ) 1 )\r
 #define usbINIT_DELAY                                          ( ( portTickType ) 500 / portTICK_RATE_MS )\r
 #define usbSHORT_DELAY                                         ( ( portTickType ) 50 / portTICK_RATE_MS )\r
-#define usbEND_POINT_RESET_MASK                                ( ( unsigned portLONG ) 0x0f )\r
-#define usbDATA_INC                                                    ( ( portCHAR ) 5 )\r
-#define usbEXPECTED_NUMBER_OF_BYTES                    ( ( unsigned portLONG ) 8 )\r
+#define usbEND_POINT_RESET_MASK                                ( ( unsigned long ) 0x0f )\r
+#define usbDATA_INC                                                    ( ( char ) 5 )\r
+#define usbEXPECTED_NUMBER_OF_BYTES                    ( ( unsigned long ) 8 )\r
 \r
 /* Control request types. */\r
 #define usbSTANDARD_DEVICE_REQUEST                     ( 0 )\r
@@ -156,19 +187,19 @@ little odd. */
 /* Structure used to take a snapshot of the USB status from within the ISR. */\r
 typedef struct X_ISR_STATUS\r
 {\r
-       unsigned portLONG ulISR;\r
-       unsigned portLONG ulCSR0;\r
-       unsigned portCHAR ucFifoData[ 8 ];\r
+       unsigned long ulISR;\r
+       unsigned long ulCSR0;\r
+       unsigned char ucFifoData[ 8 ];\r
 } xISRStatus;\r
 \r
 /* Structure used to hold the received requests. */\r
-typedef struct \r
+typedef struct\r
 {\r
-       unsigned portCHAR ucReqType;\r
-       unsigned portCHAR ucRequest;\r
-       unsigned portSHORT usValue;\r
-       unsigned portSHORT usIndex;\r
-       unsigned portSHORT usLength;\r
+       unsigned char ucReqType;\r
+       unsigned char ucRequest;\r
+       unsigned short usValue;\r
+       unsigned short usIndex;\r
+       unsigned short usLength;\r
 } xUSB_REQUEST;\r
 \r
 typedef enum\r
@@ -184,14 +215,14 @@ typedef enum
 /* Structure used to control the data being sent to the host. */\r
 typedef struct\r
 {\r
-       unsigned portCHAR ucTxBuffer[ usbMAX_TX_MESSAGE_SIZE ];\r
-       unsigned portLONG ulNextCharIndex;\r
-       unsigned portLONG ulTotalDataLength;\r
+       unsigned char ucTxBuffer[ usbMAX_TX_MESSAGE_SIZE ];\r
+       unsigned long ulNextCharIndex;\r
+       unsigned long ulTotalDataLength;\r
 } xTX_MESSAGE;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* \r
+/*\r
  * The USB interrupt service routine.  This takes a snapshot of the USB\r
  * device at the time of the interrupt, clears the interrupts, and posts\r
  * the data to the USB processing task.\r
@@ -205,7 +236,7 @@ __arm void vUSB_ISR( void );
 static void prvResetEndPoints( void );\r
 \r
 /*\r
- * Setup the USB hardware, install the interrupt service routine and \r
+ * Setup the USB hardware, install the interrupt service routine and\r
  * initialise all the state variables.\r
  */\r
 static void vInitUSBInterface( void );\r
@@ -215,17 +246,17 @@ static void vInitUSBInterface( void );
  */\r
 static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage );\r
 \r
-/* \r
- * For simplicity requests are separated into device, interface, class \r
+/*\r
+ * For simplicity requests are separated into device, interface, class\r
  * interface and end point requests.\r
  *\r
  * Decode and handle standard device requests originating on the control\r
- * end point. \r
+ * end point.\r
  */\r
 static void prvHandleStandardDeviceRequest( xUSB_REQUEST *pxRequest );\r
 \r
 /*\r
- * For simplicity requests are separated into device, interface, class \r
+ * For simplicity requests are separated into device, interface, class\r
  * interface and end point requests.\r
  *\r
  * Decode and handle standard interface requests originating on the control\r
@@ -234,7 +265,7 @@ static void prvHandleStandardDeviceRequest( xUSB_REQUEST *pxRequest );
 static void prvHandleStandardInterfaceRequest( xUSB_REQUEST *pxRequest );\r
 \r
 /*\r
- * For simplicity requests are separated into device, interface, class \r
+ * For simplicity requests are separated into device, interface, class\r
  * interface and end point requests.\r
  *\r
  * Decode and handle standard end point requests originating on the control\r
@@ -243,7 +274,7 @@ static void prvHandleStandardInterfaceRequest( xUSB_REQUEST *pxRequest );
 static void prvHandleStandardEndPointRequest( xUSB_REQUEST *pxRequest );\r
 \r
 /*\r
- * For simplicity requests are separated into device, interface, class \r
+ * For simplicity requests are separated into device, interface, class\r
  * interface and end point requests.\r
  *\r
  * Decode and handle the class interface requests.\r
@@ -259,11 +290,11 @@ static void prvHandleClassInterfaceRequest( xUSB_REQUEST *pxRequest );
  * in response to TXCOMP interrupts until the entire buffer has been\r
  * sent.\r
  */\r
-static void prvSendControlData( unsigned portCHAR *pucData, unsigned portSHORT usRequestedLength, unsigned portLONG ulLengthLeftToSend, portLONG lSendingDescriptor );\r
+static void prvSendControlData( unsigned char *pucData, unsigned short usRequestedLength, unsigned long ulLengthLeftToSend, long lSendingDescriptor );\r
 \r
 /*\r
  * Examine the Tx buffer to see if there is any more data to be transmitted.\r
- * \r
+ *\r
  * If there is data to be transmitted then send the next segment.  A segment\r
  * can have a maximum of 8 bytes (this is defined as the maximum for the end\r
  * point by the descriptor).  The final segment may be less than 8 bytes if\r
@@ -274,36 +305,36 @@ static void prvSendNextSegment( void );
 /*\r
  * A stall condition is forced each time the host makes a request that is not\r
  * supported by this minimal implementation.\r
- * \r
+ *\r
  * A stall is forced by setting the appropriate bit in the end points control\r
- * and status register. \r
+ * and status register.\r
  */\r
 static void prvSendStall( void );\r
 \r
 /*\r
- * A NULL (or zero length packet) is transmitted in acknowledge the reception \r
+ * A NULL (or zero length packet) is transmitted in acknowledge the reception\r
  * of certain events from the host.\r
  */\r
 static void prvUSBTransmitNull( void );\r
 \r
-/* \r
- * When the host requests a descriptor this function is called to determine \r
+/*\r
+ * When the host requests a descriptor this function is called to determine\r
  * which descriptor is being requested and start its transmission.\r
  */\r
 static void prvGetStandardInterfaceDescriptor( xUSB_REQUEST *pxRequest );\r
 \r
 /*\r
- * This demo USB device enumerates as a simple 3 axis joystick.  Once \r
+ * This demo USB device enumerates as a simple 3 axis joystick.  Once\r
  * configured this function is periodically called to generate some sample\r
  * joystick data.\r
  *\r
- * The x and y axis are made to move in a square.  The z axis is made to \r
+ * The x and y axis are made to move in a square.  The z axis is made to\r
  * repeatedly increment up to its maximum.\r
  */\r
 static void prvTransmitSampleValues( void );\r
 \r
 /*\r
- * The created task to handle the USB demo functionality. \r
+ * The created task to handle the USB demo functionality.\r
  */\r
 void vUSBDemoTask( void *pvParameters );\r
 \r
@@ -322,14 +353,14 @@ These take the form:
        Data\r
 }\r
 */\r
-const portCHAR pxLanguageStringDescriptor[] =\r
+const char pxLanguageStringDescriptor[] =\r
 {\r
        4,\r
        usbDESCRIPTOR_TYPE_STRING,\r
        0x09, 0x04\r
 };\r
 \r
-const portCHAR pxManufacturerStringDescriptor[] = \r
+const char pxManufacturerStringDescriptor[] =\r
 {\r
        18,\r
        usbDESCRIPTOR_TYPE_STRING,\r
@@ -344,7 +375,7 @@ const portCHAR pxManufacturerStringDescriptor[] =
        'S', 0x00       \r
 };\r
 \r
-const portCHAR pxProductStringDescriptor[] = \r
+const char pxProductStringDescriptor[] =\r
 {\r
        44,\r
        usbDESCRIPTOR_TYPE_STRING,\r
@@ -372,7 +403,7 @@ const portCHAR pxProductStringDescriptor[] =
        'k', 0x00\r
 };\r
 \r
-const portCHAR pxConfigurationStringDescriptor[] = \r
+const char pxConfigurationStringDescriptor[] =\r
 {\r
        38,\r
        usbDESCRIPTOR_TYPE_STRING,\r
@@ -397,7 +428,7 @@ const portCHAR pxConfigurationStringDescriptor[] =
        'e', 0x00\r
 };\r
 \r
-const portCHAR pxInterfaceStringDescriptor[] = \r
+const char pxInterfaceStringDescriptor[] =\r
 {\r
        30,\r
        usbDESCRIPTOR_TYPE_STRING,\r
@@ -419,7 +450,7 @@ const portCHAR pxInterfaceStringDescriptor[] =
 };\r
 \r
 /* Enumeration descriptors. */\r
-const portCHAR pxReportDescriptor[] =\r
+const char pxReportDescriptor[] =\r
 {\r
         0x05,  0x01,   /* USAGE_PAGE (Generic Desktop)         */\r
         0x09,  0x04,   /* USAGE (Joystick)                                     */\r
@@ -439,7 +470,7 @@ const portCHAR pxReportDescriptor[] =
         0xc0                   /* END_COLLECTION                                       */\r
 };\r
 \r
-const char pxDeviceDescriptor[] = \r
+const char pxDeviceDescriptor[] =\r
 {\r
        /* Device descriptor */\r
        0x12,                                                           /* bLength                              */\r
@@ -501,8 +532,8 @@ const char pxConfigDescriptor[] = {
 /*-----------------------------------------------------------*/\r
 \r
 /* File scope state variables. */\r
-static unsigned portCHAR ucUSBConfig = ( unsigned portCHAR ) 0;\r
-static unsigned portLONG ulReceivedAddress = ( unsigned portLONG ) 0;\r
+static unsigned char ucUSBConfig = ( unsigned char ) 0;\r
+static unsigned long ulReceivedAddress = ( unsigned long ) 0;\r
 static eDRIVER_STATE eDriverState = eNOTHING;\r
 \r
 /* Array in which the USB interrupt status is passed between the ISR and task. */\r
@@ -512,7 +543,7 @@ static xISRStatus xISRMessages[ usbQUEUE_LENGTH + 1 ];
 static xTX_MESSAGE pxCharsForTx;\r
 \r
 /* Queue used to pass messages between the ISR and the task. */\r
-static xQueueHandle xUSBInterruptQueue; \r
+static xQueueHandle xUSBInterruptQueue;\r
 \r
 /* ISR entry has to be written in the asm file as we want a context switch\r
 to occur from within the ISR.  See the port documentation on the FreeRTOS.org\r
@@ -521,9 +552,9 @@ extern void vUSBISREntry( void );
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* Macros to manipulate the control and status registers.  These registers \r
-cannot be accessed using a direct read modify write operation outside of the \r
-ISR as some bits are left unchanged by writing with a 0, and some are left \r
+/* Macros to manipulate the control and status registers.  These registers\r
+cannot be accessed using a direct read modify write operation outside of the\r
+ISR as some bits are left unchanged by writing with a 0, and some are left\r
 unchanged by writing with a 1. */\r
 \r
 #define usbINT_CLEAR_MASK      (AT91C_UDP_TXCOMP | AT91C_UDP_STALLSENT | AT91C_UDP_RXSETUP | AT91C_UDP_RX_DATA_BK0 | AT91C_UDP_RX_DATA_BK1 )\r
@@ -533,14 +564,14 @@ unchanged by writing with a 1. */
        /* Set TXCOMP, RX_DATA_BK0, RXSETUP, */                                                                                         \\r
        /* STALLSENT and RX_DATA_BK1 to 1 so the */                                                                                     \\r
        /* write has no effect. */                                                                                                                      \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) |= ( unsigned portLONG ) 0x4f;            \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) |= ( unsigned long ) 0x4f;            \\r
                                                                                                                                                                                \\r
        /* Clear the FORCE_STALL and TXPKTRDY bits */                                                                           \\r
        /* so the write has no effect. */                                                                                                       \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) &= ( unsigned portLONG ) 0xffffffcf;      \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) &= ( unsigned long ) 0xffffffcf;      \\r
                                                                                                                                                                                \\r
        /* Set whichever bit we want set. */                                                                                            \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) |= ( ulBit );                                                     \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) |= ( ulBit );                                                 \\r
 }\r
 \r
 #define usbCSR_CLEAR_BIT( pulValueNow, ulBit )                                                                                 \\r
@@ -548,24 +579,24 @@ unchanged by writing with a 1. */
        /* Set TXCOMP, RX_DATA_BK0, RXSETUP, */                                                                                         \\r
        /* STALLSENT and RX_DATA_BK1 to 1 so the */                                                                                     \\r
        /* write has no effect. */                                                                                                                      \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) |= ( unsigned portLONG ) 0x4f;            \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) |= ( unsigned long ) 0x4f;            \\r
                                                                                                                                                                                \\r
        /* Clear the FORCE_STALL and TXPKTRDY bits */                                                                           \\r
        /* so the write has no effect. */                                                                                                       \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) &= ( unsigned portLONG ) 0xffffffcf;      \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) &= ( unsigned long ) 0xffffffcf;      \\r
                                                                                                                                                                                \\r
        /* Clear whichever bit we want clear. */                                                                                        \\r
-       ( * ( ( unsigned portLONG * ) pulValueNow ) ) &= ( ~ulBit );                                            \\r
+       ( * ( ( unsigned long * ) pulValueNow ) ) &= ( ~ulBit );                                                \\r
 }\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 __arm void vUSB_ISR( void )\r
 {\r
-portBASE_TYPE xTaskWokenByPost = pdFALSE; \r
-static volatile unsigned portLONG ulNextMessage = 0;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+static volatile unsigned long ulNextMessage = 0;\r
 xISRStatus *pxMessage;\r
-unsigned portLONG ulTemp, ulRxBytes;\r
+unsigned long ulTemp, ulRxBytes;\r
 \r
        /* Take the next message from the queue.  Note that usbQUEUE_LENGTH *must*\r
        be all 1's, as in 0x01, 0x03, 0x07, etc. */\r
@@ -581,7 +612,7 @@ unsigned portLONG ulTemp, ulRxBytes;
        cleared separately as it does not appear in the mask register. */\r
        AT91C_BASE_UDP->UDP_ICR = AT91C_BASE_UDP->UDP_IMR | AT91C_UDP_ENDBUSRES;\r
        \r
-       /* If there are bytes in the FIFO then we have to retrieve them here.  \r
+       /* If there are bytes in the FIFO then we have to retrieve them here.\r
        Ideally this would be done at the task level.  However we need to clear the\r
        RXSETUP interrupt before leaving the ISR, and this may cause the data in\r
        the FIFO to be overwritten.  Also the DIR bit has to be changed before the\r
@@ -592,7 +623,7 @@ unsigned portLONG ulTemp, ulRxBytes;
        ulRxBytes = ulTemp >> 16;\r
        ulRxBytes &= usbRX_COUNT_MASK;\r
        \r
-       /* With this minimal implementation we are only interested in receiving \r
+       /* With this minimal implementation we are only interested in receiving\r
        setup bytes on the control end point. */\r
        if( ( ulRxBytes > 0 ) && ( ulTemp & AT91C_UDP_RXSETUP ) )\r
        {\r
@@ -621,11 +652,11 @@ unsigned portLONG ulTemp, ulRxBytes;
        /* The message now contains the entire state and optional data from\r
        the USB interrupt.  This can now be posted on the Rx queue ready for\r
        processing at the task level. */\r
-       xTaskWokenByPost = xQueueSendFromISR( xUSBInterruptQueue, &pxMessage, xTaskWokenByPost );\r
+       xQueueSendFromISR( xUSBInterruptQueue, &pxMessage, &xHigherPriorityTaskWoken );\r
 \r
        /* We may want to switch to the USB task, if this message has made\r
        it the highest priority task that is ready to execute. */\r
-       portEND_SWITCHING_ISR( xTaskWokenByPost );\r
+       portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
 \r
        /* Clear the AIC ready for the next interrupt. */               \r
        AT91C_BASE_AIC->AIC_EOICR = 0;\r
@@ -644,7 +675,7 @@ xISRStatus *pxMessage;
            vInitUSBInterface();\r
     portEXIT_CRITICAL();\r
 \r
-       /* Process interrupts as they arrive.   The ISR takes a snapshot of the \r
+       /* Process interrupts as they arrive.   The ISR takes a snapshot of the\r
        interrupt status then posts the information on this queue for processing\r
        at the task level.  This simple demo implementation only processes\r
        a few interrupt sources. */\r
@@ -679,11 +710,11 @@ xISRStatus *pxMessage;
 \r
 static void prvTransmitSampleValues( void )\r
 {\r
-unsigned portLONG ulStatus;\r
-static portLONG lState = usbXUP;\r
+unsigned long ulStatus;\r
+static long lState = usbXUP;\r
 \r
 /* Variables to hold dummy x, y and z joystick axis data. */\r
-static signed portCHAR x = 0, y = 0, z = 0;\r
+static signed char x = 0, y = 0, z = 0;\r
 \r
        /* Generate some sample data in the x and y axis - draw a square. */\r
        switch( lState )\r
@@ -742,7 +773,7 @@ static signed portCHAR x = 0, y = 0, z = 0;
 \r
 static void prvUSBTransmitNull( void )\r
 {\r
-unsigned portLONG ulStatus;\r
+unsigned long ulStatus;\r
 \r
        /* Wait until the FIFO is free - even though we are not going to use it.\r
        THERE IS NO TIMEOUT HERE! */\r
@@ -769,7 +800,7 @@ unsigned portLONG ulStatus;
 \r
 static void prvSendStall( void )\r
 {\r
-unsigned portLONG ulStatus;\r
+unsigned long ulStatus;\r
 \r
        portENTER_CRITICAL();\r
        {\r
@@ -784,13 +815,13 @@ unsigned portLONG ulStatus;
 \r
 static void prvResetEndPoints( void )\r
 {\r
-unsigned portLONG ulTemp;\r
+unsigned long ulTemp;\r
 \r
        eDriverState = eJUST_RESET;\r
 \r
        /* Reset all the end points. */\r
        AT91C_BASE_UDP->UDP_RSTEP  = usbEND_POINT_RESET_MASK;\r
-       AT91C_BASE_UDP->UDP_RSTEP  = ( unsigned portLONG ) 0x00;\r
+       AT91C_BASE_UDP->UDP_RSTEP  = ( unsigned long ) 0x00;\r
 \r
        /* Enable data to be sent and received. */\r
        AT91C_BASE_UDP->UDP_FADDR = AT91C_UDP_FEN;\r
@@ -799,7 +830,7 @@ unsigned portLONG ulTemp;
        portENTER_CRITICAL();\r
        {\r
                ulTemp = AT91C_BASE_UDP->UDP_CSR[ usbEND_POINT_0 ];\r
-               usbCSR_SET_BIT( &ulTemp, ( ( unsigned portLONG ) ( AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL ) ) );\r
+               usbCSR_SET_BIT( &ulTemp, ( ( unsigned long ) ( AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL ) ) );\r
                AT91C_BASE_UDP->UDP_CSR[ usbEND_POINT_0 ] = ulTemp;\r
                AT91F_UDP_EnableIt( AT91C_BASE_UDP, AT91C_UDP_EPINT0 );\r
        }\r
@@ -811,7 +842,7 @@ static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
 {\r
        if( pxMessage->ulCSR0 & AT91C_UDP_RX_DATA_BK0 )\r
        {               \r
-               /* We only expect to receive zero length data here as ACK's. \r
+               /* We only expect to receive zero length data here as ACK's.\r
                Set the data pointer to the end of the current Tx packet to\r
                ensure we don't send out any more data. */      \r
                pxCharsForTx.ulNextCharIndex = pxCharsForTx.ulTotalDataLength;\r
@@ -831,7 +862,7 @@ static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
                        /* Read the end point for data transfer. */\r
                        portENTER_CRITICAL();\r
                        {\r
-                               unsigned portLONG ulTemp;\r
+                               unsigned long ulTemp;\r
 \r
                                ulTemp = AT91C_BASE_UDP->UDP_CSR[ usbEND_POINT_1 ];                                     \r
                                usbCSR_SET_BIT( &ulTemp, AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_INT_IN );\r
@@ -846,7 +877,7 @@ static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
                {\r
                        /* We sent an acknowledgement of a SET_ADDRESS request.  Move\r
                        to the addressed state. */\r
-                       if( ulReceivedAddress != ( unsigned portLONG ) 0 )\r
+                       if( ulReceivedAddress != ( unsigned long ) 0 )\r
                        {                       \r
                                AT91C_BASE_UDP->UDP_GLBSTATE = AT91C_UDP_FADDEN;\r
                        }\r
@@ -869,8 +900,8 @@ static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
        if( pxMessage->ulCSR0 & AT91C_UDP_RXSETUP )\r
        {\r
                xUSB_REQUEST xRequest;\r
-               unsigned portCHAR ucRequest;\r
-               unsigned portLONG ulRxBytes;\r
+               unsigned char ucRequest;\r
+               unsigned long ulRxBytes;\r
 \r
                /* A data packet is available. */       \r
                ulRxBytes = pxMessage->ulCSR0 >> 16;\r
@@ -896,9 +927,9 @@ static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
                        xRequest.usLength <<= 8;\r
                        xRequest.usLength |= pxMessage->ucFifoData[ usbLENGTH_LOW_BYTE ];\r
        \r
-                       /* Manipulate the ucRequestType and the ucRequest parameters to \r
-                       generate a zero based request selection.  This is just done to \r
-                       break up the requests into subsections for clarity.  The \r
+                       /* Manipulate the ucRequestType and the ucRequest parameters to\r
+                       generate a zero based request selection.  This is just done to\r
+                       break up the requests into subsections for clarity.  The\r
                        alternative would be to have more huge switch statement that would\r
                        be difficult to optimise. */\r
                        ucRequest = ( ( xRequest.ucReqType & 0x60 ) >> 3 );\r
@@ -940,11 +971,11 @@ static void prvGetStandardDeviceDescriptor( xUSB_REQUEST *pxRequest )
        switch( ( pxRequest->usValue & 0xff00 ) >> 8 )\r
        {\r
            case usbDESCRIPTOR_TYPE_DEVICE:\r
-                       prvSendControlData( ( unsigned portCHAR * ) &pxDeviceDescriptor, pxRequest->usLength, sizeof( pxDeviceDescriptor ), pdTRUE );\r
+                       prvSendControlData( ( unsigned char * ) &pxDeviceDescriptor, pxRequest->usLength, sizeof( pxDeviceDescriptor ), pdTRUE );\r
                    break;\r
        \r
            case usbDESCRIPTOR_TYPE_CONFIGURATION:\r
-                       prvSendControlData( ( unsigned portCHAR * ) &( pxConfigDescriptor ), pxRequest->usLength, sizeof( pxConfigDescriptor ), pdTRUE );\r
+                       prvSendControlData( ( unsigned char * ) &( pxConfigDescriptor ), pxRequest->usLength, sizeof( pxConfigDescriptor ), pdTRUE );\r
                    break;\r
 \r
            case usbDESCRIPTOR_TYPE_STRING:\r
@@ -953,23 +984,23 @@ static void prvGetStandardDeviceDescriptor( xUSB_REQUEST *pxRequest )
                    switch( pxRequest->usValue & 0xff )\r
                        {                       \r
                        case usbLANGUAGE_STRING:\r
-                                       prvSendControlData( ( unsigned portCHAR * ) &pxLanguageStringDescriptor, pxRequest->usLength, sizeof(pxLanguageStringDescriptor), pdTRUE );\r
+                                       prvSendControlData( ( unsigned char * ) &pxLanguageStringDescriptor, pxRequest->usLength, sizeof(pxLanguageStringDescriptor), pdTRUE );\r
                                break;\r
 \r
                        case usbMANUFACTURER_STRING:\r
-                                       prvSendControlData( ( unsigned portCHAR * ) &pxManufacturerStringDescriptor, pxRequest->usLength, sizeof( pxManufacturerStringDescriptor ), pdTRUE );\r
+                                       prvSendControlData( ( unsigned char * ) &pxManufacturerStringDescriptor, pxRequest->usLength, sizeof( pxManufacturerStringDescriptor ), pdTRUE );\r
                                break;\r
 \r
                        case usbPRODUCT_STRING:\r
-                                       prvSendControlData( ( unsigned portCHAR * ) &pxProductStringDescriptor, pxRequest->usLength, sizeof( pxProductStringDescriptor ), pdTRUE );\r
+                                       prvSendControlData( ( unsigned char * ) &pxProductStringDescriptor, pxRequest->usLength, sizeof( pxProductStringDescriptor ), pdTRUE );\r
                                break;\r
 \r
                        case usbCONFIGURATION_STRING:\r
-                                       prvSendControlData( ( unsigned portCHAR * ) &pxConfigurationStringDescriptor, pxRequest->usLength, sizeof( pxConfigurationStringDescriptor ), pdTRUE );\r
+                                       prvSendControlData( ( unsigned char * ) &pxConfigurationStringDescriptor, pxRequest->usLength, sizeof( pxConfigurationStringDescriptor ), pdTRUE );\r
                                break;\r
 \r
                        case usbINTERFACE_STRING:\r
-                                       prvSendControlData( ( unsigned portCHAR * ) &pxInterfaceStringDescriptor, pxRequest->usLength, sizeof( pxInterfaceStringDescriptor ), pdTRUE );\r
+                                       prvSendControlData( ( unsigned char * ) &pxInterfaceStringDescriptor, pxRequest->usLength, sizeof( pxInterfaceStringDescriptor ), pdTRUE );\r
                                break;\r
 \r
                        default:\r
@@ -990,13 +1021,13 @@ static void prvGetStandardDeviceDescriptor( xUSB_REQUEST *pxRequest )
 \r
 static void prvHandleStandardDeviceRequest( xUSB_REQUEST *pxRequest )\r
 {\r
-unsigned portSHORT usStatus = 0;\r
+unsigned short usStatus = 0;\r
 \r
        switch( pxRequest->ucRequest )\r
        {\r
            case usbGET_STATUS_REQUEST:\r
                        /* Just send two byte dummy status. */\r
-                       prvSendControlData( ( unsigned portCHAR * ) &usStatus, sizeof( usStatus ), sizeof( usStatus ), pdFALSE );\r
+                       prvSendControlData( ( unsigned char * ) &usStatus, sizeof( usStatus ), sizeof( usStatus ), pdFALSE );\r
                    break;\r
 \r
            case usbGET_DESCRIPTOR_REQUEST:\r
@@ -1006,7 +1037,7 @@ unsigned portSHORT usStatus = 0;
 \r
            case usbGET_CONFIGURATION_REQUEST:\r
                        /* Send selected device configuration */\r
-                       prvSendControlData( ( unsigned portCHAR * ) &ucUSBConfig, sizeof( ucUSBConfig ), sizeof( ucUSBConfig ), pdFALSE );\r
+                       prvSendControlData( ( unsigned char * ) &ucUSBConfig, sizeof( ucUSBConfig ), sizeof( ucUSBConfig ), pdFALSE );\r
                    break;\r
 \r
                case usbSET_FEATURE_REQUEST:\r
@@ -1021,16 +1052,16 @@ unsigned portSHORT usStatus = 0;
                        address and set our state so we know we have received the address. */\r
                prvUSBTransmitNull();                   \r
                        eDriverState = eJUST_GOT_ADDRESS;               \r
-                       ulReceivedAddress = ( unsigned portLONG ) pxRequest->usValue;\r
+                       ulReceivedAddress = ( unsigned long ) pxRequest->usValue;\r
                    break;\r
 \r
            case usbSET_CONFIGURATION_REQUEST:\r
 \r
-                       /* Acknowledge the SET_CONFIGURATION, but (according to the manual) \r
-                       we cannot actually move to the configured state until we get a \r
+                       /* Acknowledge the SET_CONFIGURATION, but (according to the manual)\r
+                       we cannot actually move to the configured state until we get a\r
                        TXCOMP interrupt from this NULL packet.  Therefore we just remember the\r
                        config and set our state so we know we have received the go ahead. */                   \r
-                       ucUSBConfig = ( unsigned portCHAR ) ( pxRequest->usValue & 0xff );\r
+                       ucUSBConfig = ( unsigned char ) ( pxRequest->usValue & 0xff );\r
                        eDriverState = eJUST_GOT_CONFIG;\r
                        prvUSBTransmitNull();\r
                    break;\r
@@ -1068,10 +1099,10 @@ static void prvHandleClassInterfaceRequest( xUSB_REQUEST *pxRequest )
 \r
 static void prvGetStandardInterfaceDescriptor( xUSB_REQUEST *pxRequest )\r
 {\r
-       switch( ( pxRequest->usValue & ( unsigned portSHORT ) 0xff00 ) >> 8 )\r
+       switch( ( pxRequest->usValue & ( unsigned short ) 0xff00 ) >> 8 )\r
        {\r
            case usbHID_REPORT_DESCRIPTOR:\r
-                       prvSendControlData( ( unsigned portCHAR * ) pxReportDescriptor, pxRequest->usLength, sizeof( pxReportDescriptor ), pdTRUE );\r
+                       prvSendControlData( ( unsigned char * ) pxReportDescriptor, pxRequest->usLength, sizeof( pxReportDescriptor ), pdTRUE );\r
                    break;\r
 \r
            default:\r
@@ -1085,17 +1116,17 @@ static void prvGetStandardInterfaceDescriptor( xUSB_REQUEST *pxRequest )
 \r
 static void prvHandleStandardInterfaceRequest( xUSB_REQUEST *pxRequest )\r
 {\r
-unsigned portSHORT usStatus = 0;\r
+unsigned short usStatus = 0;\r
 \r
        switch( pxRequest->ucRequest )\r
        {\r
            case usbGET_STATUS_REQUEST:\r
                        /* Send dummy 2 bytes. */\r
-                       prvSendControlData( ( unsigned portCHAR * ) &usStatus, sizeof( usStatus ), sizeof( usStatus ), pdFALSE );\r
+                       prvSendControlData( ( unsigned char * ) &usStatus, sizeof( usStatus ), sizeof( usStatus ), pdFALSE );\r
                        break;\r
 \r
            case usbGET_DESCRIPTOR_REQUEST:\r
-                       prvGetStandardInterfaceDescriptor( pxRequest ); \r
+                       prvGetStandardInterfaceDescriptor( pxRequest );\r
                        break;\r
 \r
                /* This minimal implementation does not respond to these. */\r
@@ -1116,7 +1147,7 @@ static void prvHandleStandardEndPointRequest( xUSB_REQUEST *pxRequest )
        {\r
                /* This minimal implementation does not expect to respond to these. */\r
            case usbGET_STATUS_REQUEST:\r
-           case usbCLEAR_FEATURE_REQUEST: \r
+           case usbCLEAR_FEATURE_REQUEST:\r
            case usbSET_FEATURE_REQUEST:\r
 \r
            default:                    \r
@@ -1128,14 +1159,14 @@ static void prvHandleStandardEndPointRequest( xUSB_REQUEST *pxRequest )
 \r
 static void vInitUSBInterface( void )\r
 {\r
-volatile unsigned portLONG ulTemp;\r
+volatile unsigned long ulTemp;\r
 \r
        /* Create the queue used to communicate between the USB ISR and task. */\r
        xUSBInterruptQueue = xQueueCreate( usbQUEUE_LENGTH + 1, sizeof( xISRStatus * ) );\r
 \r
        /* Initialise a few state variables. */\r
-       pxCharsForTx.ulNextCharIndex = ( unsigned portLONG ) 0;\r
-       ucUSBConfig = ( unsigned portCHAR ) 0;\r
+       pxCharsForTx.ulNextCharIndex = ( unsigned long ) 0;\r
+       ucUSBConfig = ( unsigned char ) 0;\r
        eDriverState = eNOTHING;\r
 \r
        /* HARDWARE SETUP */\r
@@ -1150,24 +1181,24 @@ volatile unsigned portLONG ulTemp;
     /* Setup the PIO for the USB pull up resistor. */\r
     AT91F_PIO_CfgOutput(AT91C_BASE_PIOA,AT91C_PIO_PA16);\r
 \r
-    /* Start without the pullup - this will get set at the end of this \r
+    /* Start without the pullup - this will get set at the end of this\r
        function. */\r
     AT91F_PIO_SetOutput( AT91C_BASE_PIOA, AT91C_PIO_PA16 );\r
 \r
        /* When using the USB debugger the peripheral registers do not always get\r
        set to the correct default values.  To make sure set the relevant registers\r
        manually here. */\r
-       AT91C_BASE_UDP->UDP_IDR = ( unsigned portLONG ) 0xffffffff;\r
-       AT91C_BASE_UDP->UDP_ICR = ( unsigned portLONG ) 0xffffffff;\r
-       AT91C_BASE_UDP->UDP_CSR[ 0 ] = ( unsigned portLONG ) 0x00;\r
-       AT91C_BASE_UDP->UDP_CSR[ 1 ] = ( unsigned portLONG ) 0x00;\r
+       AT91C_BASE_UDP->UDP_IDR = ( unsigned long ) 0xffffffff;\r
+       AT91C_BASE_UDP->UDP_ICR = ( unsigned long ) 0xffffffff;\r
+       AT91C_BASE_UDP->UDP_CSR[ 0 ] = ( unsigned long ) 0x00;\r
+       AT91C_BASE_UDP->UDP_CSR[ 1 ] = ( unsigned long ) 0x00;\r
        AT91C_BASE_UDP->UDP_GLBSTATE = 0;\r
        AT91C_BASE_UDP->UDP_FADDR = 0;\r
 \r
        /* Enable the transceiver. */\r
        AT91C_UDP_TRANSCEIVER_ENABLE = 0;\r
 \r
-       /* Enable the USB interrupts - other interrupts get enabled as the \r
+       /* Enable the USB interrupts - other interrupts get enabled as the\r
        enumeration process progresses. */\r
        AT91F_AIC_ConfigureIt( AT91C_BASE_AIC, AT91C_ID_UDP, usbINTERRUPT_PRIORITY, AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, ( void (*)( void ) ) vUSBISREntry );\r
        AT91F_AIC_EnableIt( AT91C_BASE_AIC, AT91C_ID_UDP );\r
@@ -1178,16 +1209,16 @@ volatile unsigned portLONG ulTemp;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvSendControlData( unsigned portCHAR *pucData, unsigned portSHORT usRequestedLength, unsigned portLONG ulLengthToSend, portLONG lSendingDescriptor )\r
+static void prvSendControlData( unsigned char *pucData, unsigned short usRequestedLength, unsigned long ulLengthToSend, long lSendingDescriptor )\r
 {\r
-       if( ( ( unsigned portLONG ) usRequestedLength < ulLengthToSend ) )\r
+       if( ( ( unsigned long ) usRequestedLength < ulLengthToSend ) )\r
        {\r
                /* Cap the data length to that requested. */\r
-               ulLengthToSend = ( unsigned portSHORT ) usRequestedLength;\r
+               ulLengthToSend = ( unsigned short ) usRequestedLength;\r
        }\r
-       else if( ( ulLengthToSend < ( unsigned portLONG ) usRequestedLength ) && lSendingDescriptor )\r
+       else if( ( ulLengthToSend < ( unsigned long ) usRequestedLength ) && lSendingDescriptor )\r
        {\r
-               /* We are sending a descriptor.  If the descriptor is an exact \r
+               /* We are sending a descriptor.  If the descriptor is an exact\r
                multiple of the FIFO length then it will have to be terminated\r
                with a NULL packet.  Set the state to indicate this if\r
                necessary. */\r
@@ -1204,12 +1235,12 @@ static void prvSendControlData( unsigned portCHAR *pucData, unsigned portSHORT u
        (if it is greater than 8 bytes in length). */\r
        memcpy( pxCharsForTx.ucTxBuffer, pucData, ulLengthToSend );\r
 \r
-       /* Reinitialise the buffer index so we start sending from the start of \r
+       /* Reinitialise the buffer index so we start sending from the start of\r
        the data. */\r
        pxCharsForTx.ulTotalDataLength = ulLengthToSend;\r
-       pxCharsForTx.ulNextCharIndex = ( unsigned portLONG ) 0;\r
+       pxCharsForTx.ulNextCharIndex = ( unsigned long ) 0;\r
 \r
-       /* Send the first 8 bytes now.  The rest will get sent in response to \r
+       /* Send the first 8 bytes now.  The rest will get sent in response to\r
        TXCOMP interrupts. */\r
        prvSendNextSegment();\r
 }\r
@@ -1217,7 +1248,7 @@ static void prvSendControlData( unsigned portCHAR *pucData, unsigned portSHORT u
 \r
 static void prvSendNextSegment( void )\r
 {\r
-volatile unsigned portLONG ulNextLength, ulStatus, ulLengthLeftToSend;\r
+volatile unsigned long ulNextLength, ulStatus, ulLengthLeftToSend;\r
 \r
        /* Is there any data to send? */\r
        if( pxCharsForTx.ulTotalDataLength > pxCharsForTx.ulNextCharIndex )\r
@@ -1242,7 +1273,7 @@ volatile unsigned portLONG ulNextLength, ulStatus, ulLengthLeftToSend;
                }\r
 \r
                /* Write the data to the FIFO. */\r
-               while( ulNextLength > ( unsigned portLONG ) 0 )\r
+               while( ulNextLength > ( unsigned long ) 0 )\r
                {\r
                        AT91C_BASE_UDP->UDP_FDR[ usbEND_POINT_0 ] = pxCharsForTx.ucTxBuffer[ pxCharsForTx.ulNextCharIndex ];\r
        \r
@@ -1254,14 +1285,14 @@ volatile unsigned portLONG ulNextLength, ulStatus, ulLengthLeftToSend;
                portENTER_CRITICAL();\r
                {\r
                        ulStatus = AT91C_BASE_UDP->UDP_CSR[ usbEND_POINT_0 ];\r
-                       usbCSR_SET_BIT( &ulStatus, ( ( unsigned portLONG ) 0x10 ) );\r
+                       usbCSR_SET_BIT( &ulStatus, ( ( unsigned long ) 0x10 ) );\r
                        AT91C_BASE_UDP->UDP_CSR[ usbEND_POINT_0 ] = ulStatus;\r
                }\r
                portEXIT_CRITICAL();\r
        }\r
        else\r
        {\r
-               /* There is no data to send.  If we were sending a descriptor and the \r
+               /* There is no data to send.  If we were sending a descriptor and the\r
                descriptor was an exact multiple of the max packet size then we need\r
                to send a null to terminate the transmission. */\r
                if( eDriverState == eSENDING_EVEN_DESCRIPTOR )\r