]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/AtmelFiles/usb/device/cdc-serial/CDCDSerialDriver.c
SAMA5D3 demo: Add CDC driver code and use CDC to create a simple command console.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D3x_Xplained_IAR / AtmelFiles / usb / device / cdc-serial / CDCDSerialDriver.c
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\file\r
31  *   Title: CDCDSerialDriver implementation\r
32  *\r
33  *   About: Purpose\r
34  *       Implementation of the CDCDSerialDriver class methods.\r
35  */\r
36 \r
37 /** \addtogroup usbd_cdc\r
38  *@{\r
39  */\r
40 \r
41 /*------------------------------------------------------------------------------\r
42  *         Headers\r
43  *------------------------------------------------------------------------------*/\r
44 \r
45 #include "CDCDSerialDriver.h"\r
46 \r
47 #include <USBLib_Trace.h>\r
48 #include <USBDDriver.h>\r
49 #include <USBD_HAL.h>\r
50 \r
51 /*------------------------------------------------------------------------------\r
52  *         Types\r
53  *------------------------------------------------------------------------------*/\r
54 \r
55 /*------------------------------------------------------------------------------\r
56  *         Internal variables\r
57  *------------------------------------------------------------------------------*/\r
58 \r
59 /*------------------------------------------------------------------------------\r
60  *         Internal functions\r
61  *------------------------------------------------------------------------------*/\r
62 \r
63 /*------------------------------------------------------------------------------\r
64  *         Exported functions\r
65  *------------------------------------------------------------------------------*/\r
66 \r
67 /**\r
68  *  Initializes the USB Device CDC serial driver & USBD Driver.\r
69  *  \param  pDescriptors Pointer to Descriptors list for CDC Serial Device.\r
70  */\r
71 void CDCDSerialDriver_Initialize(const USBDDriverDescriptors *pDescriptors)\r
72 {\r
73     USBDDriver *pUsbd = USBD_GetDriver();\r
74 \r
75     /* Initialize the standard driver */\r
76     USBDDriver_Initialize(pUsbd,\r
77                           pDescriptors,\r
78                           0); /* Multiple settings for interfaces not supported */\r
79 \r
80     CDCDSerial_Initialize(pUsbd, CDCDSerialDriver_CC_INTERFACE);\r
81 \r
82     /* Initialize the USB driver */\r
83     USBD_Init();\r
84 }\r
85 \r
86 /**\r
87  * Invoked whenever the active configuration of device is changed by the\r
88  * host.\r
89  * \param cfgnum Configuration number.\r
90  */\r
91 void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum)\r
92 {\r
93     USBDDriver *pUsbd = USBD_GetDriver();\r
94     USBConfigurationDescriptor *pDesc;\r
95     if (cfgnum) {\r
96         pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);\r
97         CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc,\r
98                                       pDesc->wTotalLength);\r
99     }\r
100 }\r
101 \r
102 /**\r
103  * Handles CDC-specific SETUP requests. Should be called from a\r
104  * re-implementation of USBDCallbacks_RequestReceived() method.\r
105  * \param request Pointer to a USBGenericRequest instance.\r
106  */\r
107 void CDCDSerialDriver_RequestHandler(const USBGenericRequest *request)\r
108 {\r
109     USBDDriver *pUsbd = USBD_GetDriver();\r
110     TRACE_INFO_WP("NewReq ");\r
111     if (CDCDSerial_RequestHandler(request))\r
112         USBDDriver_RequestHandler(pUsbd, request);\r
113 }\r
114 \r
115 /**@}*/\r
116 \r