SAMV71 Xplained Ultra Software Package 1.5

CDCDEEM.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /**\file
00031  * Implementation of a single CDC EEM port function for USB device.
00032  */
00033 
00034 /** \addtogroup usbd_cdc
00035  *@{
00036  */
00037 
00038 /*------------------------------------------------------------------------------
00039  *         Headers
00040  *------------------------------------------------------------------------------*/
00041 
00042 #include "CDCDEEM.h"
00043 
00044 #include <USBLib_Trace.h>
00045 #include <USBDDriver.h>
00046 #include <USBD_HAL.h>
00047 
00048 /*------------------------------------------------------------------------------
00049  *         Types
00050  *------------------------------------------------------------------------------*/
00051 
00052 /*------------------------------------------------------------------------------
00053  *         Internal variables
00054  *------------------------------------------------------------------------------*/
00055 
00056 /** EEM Port instance list */
00057 static CDCDEEMPort cdcdEEM;
00058 
00059 /*------------------------------------------------------------------------------
00060  *         Internal functions
00061  *------------------------------------------------------------------------------*/
00062 
00063 /*------------------------------------------------------------------------------
00064  *         Exported functions
00065  *------------------------------------------------------------------------------*/
00066 
00067 /**
00068  *  Initializes the USB Device CDC serial driver & USBD Driver.
00069  * \param pUsbd         Pointer to USBDDriver instance.
00070  * \param bInterfaceNb  Interface number for the function.
00071  */
00072 void CDCDEEM_Initialize(
00073     USBDDriver *pUsbd, uint8_t bInterfaceNb)
00074 {
00075     CDCDEEMPort *pCdcd = &cdcdEEM;
00076 
00077     TRACE_INFO("CDCDEEM_Initialize\n\r");
00078 
00079     /* Initialize serial port function */
00080     CDCDEEMPort_Initialize(
00081         pCdcd, pUsbd,
00082         bInterfaceNb, 2);
00083 }
00084 
00085 /**
00086  * Invoked whenever the device is changed by the
00087  * host.
00088  * \pDescriptors Pointer to the descriptors for function configure.
00089  * \wLength      Length of descriptors in number of bytes.
00090  */
00091 void CDCDEEM_ConfigureFunction(USBGenericDescriptor *pDescriptors,
00092                                uint16_t wLength)
00093 {
00094     CDCDEEMPort *pCdcd = &cdcdEEM;
00095     CDCDEEMPort_ParseInterfaces(pCdcd,
00096                                 (USBGenericDescriptor *)pDescriptors,
00097                                 wLength);
00098 }
00099 
00100 /**
00101  * Handles CDC-specific SETUP requests. Should be called from a
00102  * re-implementation of USBDCallbacks_RequestReceived() method.
00103  * \param request Pointer to a USBGenericRequest instance.
00104  */
00105 uint32_t CDCDEEM_RequestHandler(const USBGenericRequest *request)
00106 {
00107     CDCDEEMPort *pCdcd = &cdcdEEM;
00108 
00109     TRACE_INFO_WP("Cdcf ");
00110     return CDCDEEMPort_RequestHandler(pCdcd, request);
00111 }
00112 
00113 /**
00114  * Receives data from the host through the virtual COM port created by
00115  * the CDC device serial driver. This function behaves like USBD_Read.
00116  * \param data Pointer to the data buffer to put received data.
00117  * \param size Size of the data buffer in bytes.
00118  * \param callback Optional callback function to invoke when the transfer
00119  *                 finishes.
00120  * \param argument Optional argument to the callback function.
00121  * \return USBD_STATUS_SUCCESS if the read operation has been started normally;
00122  *         otherwise, the corresponding error code.
00123  */
00124 uint32_t CDCDEEM_Read(void *data,
00125                       uint32_t size,
00126                       TransferCallback callback,
00127                       void *argument)
00128 {
00129     CDCDEEMPort *pCdcd = &cdcdEEM;
00130     return CDCDEEMPort_Read(pCdcd, data, size, callback, argument);
00131 }
00132 
00133 /**
00134  * Sends a data buffer through the virtual COM port created by the CDC
00135  * device serial driver. This function behaves exactly like USBD_Write.
00136  * \param data Pointer to the data buffer to send.
00137  * \param size Size of the data buffer in bytes.
00138  * \param callback Optional callback function to invoke when the transfer
00139  *                 finishes.
00140  * \param argument Optional argument to the callback function.
00141  * \return USBD_STATUS_SUCCESS if the read operation has been started normally;
00142  *         otherwise, the corresponding error code.
00143  */
00144 uint32_t CDCDEEM_Write(void *data,
00145                        uint32_t size,
00146                        TransferCallback callback,
00147                        void *argument)
00148 {
00149     CDCDEEMPort *pCdcd = &cdcdEEM;
00150     return CDCDEEMPort_Write(pCdcd, data, size, callback, argument);
00151 }
00152 
00153 /**@}*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines