SAMV71 Xplained Ultra Software Package 1.5

CDCDSerialDriver.h

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 /**
00031  * \file
00032  *
00033  * \section Purpose
00034  *
00035  * Definition of a class for implementing a USB device CDC serial driver.
00036  *
00037  * \section Usage
00038  *
00039  * -# Re-implement the USBDCallbacks_RequestReceived method to pass
00040  *    received requests to CDCDSerialDriver_RequestHandler. *This is
00041  *    automatically done unless the NOAUTOCALLBACK symbol is defined*.
00042  * -# Initialize the CDC serial and USB drivers using
00043  *    CDCDSerialDriver_Initialize.
00044  * -# Logically connect the device to the host using USBD_Connect.
00045  * -# Send serial data to the USB host using CDCDSerialDriver_Write.
00046  * -# Receive serial data from the USB host using CDCDSerialDriver_Read.
00047  */
00048 
00049 #ifndef CDCDSERIALDRIVER_H
00050 #define CDCDSERIALDRIVER_H
00051 
00052 /** \addtogroup usbd_cdc
00053  *@{
00054  */
00055 
00056 /*------------------------------------------------------------------------------
00057  *         Headers
00058  *------------------------------------------------------------------------------*/
00059 
00060 /* These headers were introduced in C99
00061    by working group ISO/IEC JTC1/SC22/WG14. */
00062 #include <stdint.h>
00063 
00064 #include <USBRequests.h>
00065 #include <CDCRequests.h>
00066 #include <CDCDescriptors.h>
00067 #include <CDCNotifications.h>
00068 
00069 #include <CDCDSerial.h>
00070 
00071 /*------------------------------------------------------------------------------
00072  *         Definitions
00073  *------------------------------------------------------------------------------*/
00074 
00075 /** \addtogroup usbd_cdc_if USB Device CDC Serial Interface IDs
00076  *      @{
00077  */
00078 /** Communication Class Interface ID */
00079 #define CDCDSerialDriver_CC_INTERFACE           0
00080 /** Data Class Interface ID */
00081 #define CDCDSerialDriver_DC_INTERFACE           1
00082 /**     @}*/
00083 
00084 /*------------------------------------------------------------------------------
00085  *         Types
00086  *------------------------------------------------------------------------------*/
00087 #pragma pack(1)
00088 #if defined   ( __CC_ARM   ) /* Keil ¦̀Vision 4 */
00089 #elif defined ( __ICCARM__ ) /* IAR Ewarm */
00090 #define __attribute__(...)
00091 #define __packed__  packed
00092 #elif defined (  __GNUC__  ) /* GCC CS3 */
00093 #define __packed__  aligned(1)
00094 #endif
00095 
00096 /**
00097  * \typedef CDCDSerialDriverConfigurationDescriptors
00098  * \brief Configuration descriptor list for a device implementing a
00099  *        CDC serial driver.
00100  */
00101 typedef struct _CDCDSerialDriverConfigurationDescriptors {
00102 
00103     /** Standard configuration descriptor. */
00104     USBConfigurationDescriptor configuration;
00105     /** Communication interface descriptor. */
00106     USBInterfaceDescriptor  communication;
00107     /** CDC header functional descriptor. */
00108     CDCHeaderDescriptor header;
00109     /** CDC call management functional descriptor. */
00110     CDCCallManagementDescriptor callManagement;
00111     /** CDC abstract control management functional descriptor. */
00112     CDCAbstractControlManagementDescriptor abstractControlManagement;
00113     /** CDC union functional descriptor (with one slave interface). */
00114     CDCUnionDescriptor union1;
00115     /** Notification endpoint descriptor. */
00116     USBEndpointDescriptor notification;
00117     /** Data interface descriptor. */
00118     USBInterfaceDescriptor data;
00119     /** Data OUT endpoint descriptor. */
00120     USBEndpointDescriptor dataOut;
00121     /** Data IN endpoint descriptor. */
00122     USBEndpointDescriptor dataIn;
00123 
00124 } __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptors;
00125 
00126 /**
00127  * \typedef CDCDSerialDriverConfigurationDescriptorsOTG
00128  * \brief Configuration descriptor list for a device implementing a
00129  *        CDC serial OTG driver.
00130  */
00131 typedef struct _CDCDSerialDriverConfigurationDescriptorsOTG {
00132 
00133     /** Standard configuration descriptor. */
00134     USBConfigurationDescriptor configuration;
00135     /* OTG descriptor */
00136     USBOtgDescriptor otgDescriptor;
00137     /** Communication interface descriptor. */
00138     USBInterfaceDescriptor  communication;
00139     /** CDC header functional descriptor. */
00140     CDCHeaderDescriptor header;
00141     /** CDC call management functional descriptor. */
00142     CDCCallManagementDescriptor callManagement;
00143     /** CDC abstract control management functional descriptor. */
00144     CDCAbstractControlManagementDescriptor abstractControlManagement;
00145     /** CDC union functional descriptor (with one slave interface). */
00146     CDCUnionDescriptor union1;
00147     /** Notification endpoint descriptor. */
00148     USBEndpointDescriptor notification;
00149     /** Data interface descriptor. */
00150     USBInterfaceDescriptor data;
00151     /** Data OUT endpoint descriptor. */
00152     USBEndpointDescriptor dataOut;
00153     /** Data IN endpoint descriptor. */
00154     USBEndpointDescriptor dataIn;
00155 
00156 } __attribute__ ((__packed__)) CDCDSerialDriverConfigurationDescriptorsOTG;
00157 
00158 #pragma pack()
00159 
00160 /*------------------------------------------------------------------------------
00161  *      Exported functions
00162  *------------------------------------------------------------------------------*/
00163 
00164 extern void CDCDSerialDriver_Initialize(
00165     const USBDDriverDescriptors *pDescriptors);
00166 
00167 extern void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum);
00168 
00169 extern void CDCDSerialDriver_RequestHandler(
00170     const USBGenericRequest *request);
00171 
00172 /**
00173  * Sends a data buffer through the virtual COM port created by the CDC
00174  * device serial driver. This function behaves exactly like USBD_Write.
00175  * \param data Pointer to the data buffer to send.
00176  * \param size Size of the data buffer in bytes.
00177  * \param callback Optional callback function to invoke when the transfer
00178  *                 finishes.
00179  * \param argument Optional argument to the callback function.
00180  * \return USBD_STATUS_SUCCESS if the read operation has been started normally;
00181  *         otherwise, the corresponding error code.
00182  */
00183 static inline uint32_t CDCDSerialDriver_Write(
00184     void *data,
00185     uint32_t size,
00186     TransferCallback callback,
00187     void *argument)
00188 {
00189     return CDCDSerial_Write(data, size, callback, argument);
00190 }
00191 
00192 /**
00193  * Receives data from the host through the virtual COM port created by
00194  * the CDC device serial driver. This function behaves like USBD_Read.
00195  * \param data Pointer to the data buffer to put received data.
00196  * \param size Size of the data buffer in bytes.
00197  * \param callback Optional callback function to invoke when the transfer
00198  *                 finishes.
00199  * \param argument Optional argument to the callback function.
00200  * \return USBD_STATUS_SUCCESS if the read operation has been started normally;
00201  *         otherwise, the corresponding error code.
00202  */
00203 static inline uint32_t CDCDSerialDriver_Read(
00204     void *data,
00205     uint32_t size,
00206     TransferCallback callback,
00207     void *argument)
00208 {
00209     return CDCDSerial_Read(data, size, callback, argument);
00210 }
00211 
00212 /**
00213  * Copy current line coding settings to pointed space.
00214  * \param pLineCoding Pointer to CDCLineCoding instance.
00215  */
00216 static inline void CDCDSerialDriver_GetLineCoding(CDCLineCoding * pLineCoding)
00217 {
00218     CDCDSerial_GetLineCoding(pLineCoding);
00219 }
00220 
00221 /**
00222  * Returns the current control line state of the RS-232 line.
00223  */
00224 static inline uint8_t CDCDSerialDriver_GetControlLineState(void)
00225 {
00226     return CDCDSerial_GetControlLineState();
00227 }
00228 
00229 /**
00230  * Returns the current status of the RS-232 line.
00231  */
00232 static inline uint16_t CDCDSerialDriver_GetSerialState(void)
00233 {
00234     return CDCDSerial_GetSerialState();
00235 }
00236 
00237 /**
00238  * Sets the current serial state of the device to the given value.
00239  * \param serialState  New device state.
00240  */
00241 static inline void CDCDSerialDriver_SetSerialState(uint16_t serialState)
00242 {
00243     CDCDSerial_SetSerialState(serialState);
00244 }
00245 
00246 /**@}*/
00247 
00248 #endif /*#ifndef CDCSERIALDRIVER_H*/
00249 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines