SAMV71 Xplained Ultra Software Package 1.5

CDCDSerialPort.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 /** \file
00031  *  Definition of a class for implementing a USB device
00032  *  CDC serial port function.
00033  */
00034 
00035 #ifndef _CDCDSERIALPORT_H_
00036 #define _CDCDSERIALPORT_H_
00037 
00038 /*------------------------------------------------------------------------------
00039  *         Headers
00040  *------------------------------------------------------------------------------*/
00041  
00042 /* These headers were introduced in C99
00043    by working group ISO/IEC JTC1/SC22/WG14. */
00044 #include <stdint.h>
00045 
00046 #include <USBRequests.h>
00047 #include <CDCRequests.h>
00048 #include <CDCNotifications.h>
00049 #include "USBD.h"
00050 #include <USBDDriver.h>
00051 /** \addtogroup usbd_cdc
00052  *@{
00053  */
00054 
00055 /*------------------------------------------------------------------------------
00056  *         Defines
00057  *------------------------------------------------------------------------------*/
00058 
00059 /** \addtogroup usbd_cdc_serial_desc USB Device Serial Port Descriptor Values
00060  *      @{
00061  */
00062 /** Default CDC interrupt endpoints max packat size (8). */
00063 #define CDCDSerialPort_INTERRUPT_MAXPACKETSIZE          8
00064 /** Default CDC interrupt endpoint polling rate of High Speed (16ms). */
00065 #define CDCDSerialPort_INTERRUPT_INTERVAL_HS            8
00066 /** Default CDC interrupt endpoint polling rate of Full Speed (16ms). */
00067 #define CDCDSerialPort_INTERRUPT_INTERVAL_FS            16
00068 /** Default CDC bulk endpoints max packat size (512, for HS actually). */
00069 #define CDCDSerialPort_BULK_MAXPACKETSIZE_HS            512
00070 /** Default CDC bulk endpoints max packat size (64, for FS actually). */
00071 #define CDCDSerialPort_BULK_MAXPACKETSIZE_FS            64
00072 /**     @}*/
00073 
00074 /** \addtogroup usbd_cdc_serial_events USB Device Serial Port Events
00075  *      @{
00076  */
00077 /** SetControlLineState event, value is changed */
00078 #define CDCDSerialPortEvent_SETCONTROLLINESTATE         0
00079 /** SetLineCoding event, value is to changed according to return value */
00080 #define CDCDSerialPortEvent_SETLINECODING               1
00081 /**     @}*/
00082 
00083 /*------------------------------------------------------------------------------
00084  *         Types
00085  *------------------------------------------------------------------------------*/
00086 
00087 /** Callback function for serial port events */
00088 typedef uint32_t (*CDCDSerialPortEventHandler)(uint32_t dwEvent,
00089                                                uint32_t dwParam,
00090                                                void * pArguments);
00091 
00092 /**
00093  * Struct for USB CDC virtual COM serial port function.
00094  */
00095 typedef struct _CDCDSerialPort {
00096     /** USB Driver for the %device */
00097     USBDDriver *pUsbd;
00098     /** Callback for serial port events */
00099     CDCDSerialPortEventHandler fEventHandler;
00100     /** Serial port events Callback arguments */
00101     void *pEventArg;
00102     /** Callback for CDC transfer */
00103     TransferCallback fTransCLK;
00104     /** Transfer callback arguments */
00105     void *pTansArg;
00106     /** USB starting interface index */
00107     uint8_t bInterfaceNdx;
00108     /** USB number of interfaces */
00109     uint8_t bNumInterface;
00110     /** USB interrupt IN endpoint address */
00111     uint8_t bIntInPIPE;
00112     /** USB bulk IN endpoint address */
00113     uint8_t bBulkInPIPE;
00114     /** USB bulk OUT endpoint address */
00115     uint8_t bBulkOutPIPE;
00116 
00117     /** Serial port ControlLineState */
00118     uint8_t        bControlLineState;
00119     /** Serial port SerialState */
00120     uint16_t       wSerialState;
00121     /** Serial port linecoding */
00122     CDCLineCoding  lineCoding;
00123 
00124     uint8_t  bReserved;
00125 } CDCDSerialPort;
00126 
00127 /*------------------------------------------------------------------------------
00128  *         Functions
00129  *------------------------------------------------------------------------------*/
00130 
00131 extern void CDCDSerialPort_Initialize(CDCDSerialPort *pCdcd,
00132                                       USBDDriver *pUsbd,
00133                                       CDCDSerialPortEventHandler fCallback,
00134                                       void *pArg,
00135                                       uint8_t firstInterface,
00136                                       uint8_t numInterface);
00137 
00138 extern USBGenericDescriptor * CDCDSerialPort_ParseInterfaces(
00139     CDCDSerialPort * pCdcd,
00140     USBGenericDescriptor * pDescriptors, uint32_t dwLength);
00141 
00142 extern uint32_t CDCDSerialPort_RequestHandler(
00143     CDCDSerialPort *pCdcd,
00144     const USBGenericRequest *pRequest);
00145 
00146 extern uint32_t CDCDSerialPort_Write(
00147     CDCDSerialPort *pCdcd,
00148     void *pData, uint32_t dwSize,
00149     TransferCallback fCallback, void* pArg);
00150 
00151 extern uint32_t CDCDSerialPort_Read(
00152     const CDCDSerialPort *pCdcd,
00153     void *pData, uint32_t dwSize,
00154     TransferCallback fCallback, void* pArg);
00155 
00156 extern uint16_t CDCDSerialPort_GetSerialState(
00157     const CDCDSerialPort *pCdcd);
00158 
00159 extern void CDCDSerialPort_SetSerialState(
00160     CDCDSerialPort *pCdcd,
00161     uint16_t wSerialState);
00162 
00163 extern uint8_t CDCDSerialPort_GetControlLineState(
00164     const CDCDSerialPort * pCdcd);
00165 
00166 extern void CDCDSerialPort_GetLineCoding(
00167     const CDCDSerialPort * pCdcd,
00168     CDCLineCoding * pLineCoding);
00169 
00170 /**@}*/
00171 #endif /* #ifndef _CDCDSERIALPORT_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines