Fixed CDCHost demo unfreezing IN pipes during configuration, rather than during use.
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 23 Jun 2009 07:55:18 +0000 (07:55 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 23 Jun 2009 07:55:18 +0000 (07:55 +0000)
Changed Pipe stream functions to automatically set the pipe token, allowing them to be used on bidirectional pipes without having to explicitly call Pipe_SetPipeToken() beforehand.

Demos/Host/LowLevel/CDCHost/CDCHost.c
Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c
LUFA/Drivers/USB/LowLevel/Pipe.c
LUFA/Drivers/USB/LowLevel/Pipe.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/FutureChanges.txt

index e00332f..b3e0674 100644 (file)
@@ -176,10 +176,14 @@ void CDC_Host_Task(void)
                case HOST_STATE_Ready:\r
                        /* Select and the data IN pipe */\r
                        Pipe_SelectPipe(CDC_DATAPIPE_IN);\r
+                       Pipe_Unfreeze();\r
 \r
                        /* Check to see if a packet has been received */\r
                        if (Pipe_IsINReceived())\r
                        {\r
+                               /* Re-freeze IN pipe after the packet has been received */\r
+                               Pipe_Freeze();\r
+\r
                                /* Check if data is in the pipe */\r
                                if (Pipe_IsReadWriteAllowed())\r
                                {\r
@@ -199,6 +203,9 @@ void CDC_Host_Task(void)
                                Pipe_ClearIN();\r
                        }\r
 \r
+                       /* Re-freeze IN pipe after use */\r
+                       Pipe_Freeze();\r
+\r
                        /* Select and unfreeze the notification pipe */\r
                        Pipe_SelectPipe(CDC_NOTIFICATIONPIPE);\r
                        Pipe_Unfreeze();\r
index 57d7ec0..33234e4 100644 (file)
@@ -155,7 +155,6 @@ uint8_t ProcessConfigurationDescriptor(void)
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
 \r
                                Pipe_SetInfiniteINRequests();\r
-                               Pipe_Unfreeze();\r
                                \r
                                /* Set the flag indicating that the data IN pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_IN);\r
@@ -166,8 +165,6 @@ uint8_t ProcessConfigurationDescriptor(void)
                                Pipe_ConfigurePipe(CDC_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
                                \r
-                               Pipe_Unfreeze();\r
-                               \r
                                /* Set the flag indicating that the data OUT pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_OUT);\r
                        }\r
index 189aaa6..35ba480 100644 (file)
@@ -113,6 +113,8 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length
        uint8_t* DataStream = (uint8_t*)Data;\r
        uint8_t  ErrorCode;\r
        \r
+       Pipe_SetToken(PIPE_TOKEN_OUT);\r
+\r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
@@ -149,6 +151,8 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length
        uint8_t* DataStream = (uint8_t*)(Data + Length - 1);\r
        uint8_t  ErrorCode;\r
        \r
+       Pipe_SetToken(PIPE_TOKEN_OUT);\r
+\r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
@@ -184,6 +188,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length
 {\r
        uint8_t  ErrorCode;\r
        \r
+       Pipe_SetToken(PIPE_TOKEN_IN);\r
+\r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
@@ -220,6 +226,8 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length
        uint8_t* DataStream = (uint8_t*)Buffer;\r
        uint8_t  ErrorCode;\r
        \r
+       Pipe_SetToken(PIPE_TOKEN_IN);\r
+\r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
@@ -256,6 +264,8 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length
        uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
        uint8_t  ErrorCode;\r
        \r
+       Pipe_SetToken(PIPE_TOKEN_IN);\r
+\r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
index 82d9b69..30f2d38 100644 (file)
                         *\r
                         *  The banking mode may be either \ref PIPE_BANK_SINGLE or \ref PIPE_BANK_DOUBLE.\r
                         *\r
-                        *  A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze() macro.\r
+                        *  A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()\r
+                        *  before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or\r
+                        *  sending data to the device in OUT mode.\r
                         *\r
                         *  \note The default control pipe does not have to be manually configured, as it is automatically\r
                         *  configured by the library internally.\r
                         *  If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are\r
                         *  disabled and this function has the Callback parameter omitted.\r
                         *\r
+                        *  The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
+                        *  having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
+                        *\r
                         *  \ingroup Group_PipeRW\r
                         *\r
                         *  \param Buffer    Pointer to the source data buffer to read from.\r
                         *  If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are\r
                         *  disabled and this function has the Callback parameter omitted.\r
                         *\r
+                        *  The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
+                        *  having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
+                        *\r
                         *  \ingroup Group_PipeRW\r
                         *\r
                         *  \param Buffer    Pointer to the source data buffer to read from.\r
                         *  If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are\r
                         *  disabled and this function has the Callback parameter omitted.\r
                         *\r
+                        *  The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
+                        *  having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
+                        *\r
                         *  \ingroup Group_PipeRW\r
                         *\r
                         *  \param Length  Number of bytes to send via the currently selected pipe.\r
                         *  If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are\r
                         *  disabled and this function has the Callback parameter omitted.\r
                         *\r
+                        *  The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
+                        *  having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
+                        *\r
                         *  \ingroup Group_PipeRW\r
                         *\r
                         *  \param Buffer    Pointer to the source data buffer to write to.\r
                         *  If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are\r
                         *  disabled and this function has the Callback parameter omitted.\r
                         *\r
+                        *  The pipe token is set automatically, thus this can be used on bi-directional pipes directly without\r
+                        *  having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().\r
+                        *\r
                         *  \ingroup Group_PipeRW\r
                         *\r
                         *  \param Buffer    Pointer to the source data buffer to write to.\r
index 81fb515..b80fa4d 100644 (file)
@@ -31,6 +31,7 @@
   *  - Added new USE_INTERNAL_SERIAL define for using the unique serial numbers in some AVR models as the USB device's serial number,\r
   *    added NO_INTERNAL_SERIAL compile time option to turn off new serial number reading code\r
   *  - Fixed ADC driver for the ATMEGA32U4 and ATMEGA16U4 (thanks to Opendous Inc.)\r
+  *  - Pipe stream functions now automatically set the correct pipe token, so that bidirectional pipes can be used\r
   *\r
   *\r
   *  \section Sec_ChangeLog090605 Version 090605\r
index 9704131..7c6e4ee 100644 (file)
@@ -25,4 +25,5 @@
   *  - Debug mode for pipe/endpoint calls\r
   *  - Add hub support to match Atmel's stack\r
   *  - Update Host mode Class Driver demo .txt files\r
+  *  - Stream reads - return number of bytes not read?\r
   */\r