]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LPC1768_IAR/LPCUSB/usbinit.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_LPC1768_IAR / LPCUSB / usbinit.c
1 /*\r
2         LPCUSB, an USB device driver for LPC microcontrollers   \r
3         Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)\r
4 \r
5         Redistribution and use in source and binary forms, with or without\r
6         modification, are permitted provided that the following conditions are met:\r
7 \r
8         1. Redistributions of source code must retain the above copyright\r
9            notice, this list of conditions and the following disclaimer.\r
10         2. Redistributions in binary form must reproduce the above copyright\r
11            notice, this list of conditions and the following disclaimer in the\r
12            documentation and/or other materials provided with the distribution.\r
13         3. The name of the author may not be used to endorse or promote products\r
14            derived from this software without specific prior written permission.\r
15 \r
16         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
17         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
18         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
19         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
20         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
21         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
22         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
23         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
24         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
25         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
26 */\r
27 \r
28 \r
29 /** @file\r
30         USB stack initialisation\r
31  */\r
32 \r
33 \r
34 #include "usbdebug.h"\r
35 #include "usbapi.h"\r
36 \r
37 \r
38 /** data storage area for standard requests */\r
39 static unsigned char    abStdReqData[8];\r
40 \r
41 \r
42 /**\r
43         USB reset handler\r
44         \r
45         @param [in] bDevStatus  Device status\r
46  */\r
47 static void HandleUsbReset(unsigned char bDevStatus)\r
48 {\r
49         if (bDevStatus & DEV_STATUS_RESET) {\r
50                 DBG("\n!");\r
51         }\r
52 }\r
53 \r
54 \r
55 /**\r
56         Initialises the USB hardware and sets up the USB stack by\r
57         installing default callbacks.\r
58         \r
59         @return TRUE if initialisation was successful\r
60  */\r
61 BOOL USBInit(void)\r
62 {\r
63         // init hardware\r
64         USBHwInit();\r
65         \r
66         // register bus reset handler\r
67         USBHwRegisterDevIntHandler(HandleUsbReset);\r
68         \r
69         // register control transfer handler on EP0\r
70         USBHwRegisterEPIntHandler(0x00, USBHandleControlTransfer);\r
71         USBHwRegisterEPIntHandler(0x80, USBHandleControlTransfer);\r
72         \r
73         // setup control endpoints\r
74         USBHwEPConfig(0x00, MAX_PACKET_SIZE0);\r
75         USBHwEPConfig(0x80, MAX_PACKET_SIZE0);\r
76         \r
77         // register standard request handler\r
78         USBRegisterRequestHandler(REQTYPE_TYPE_STANDARD, USBHandleStandardRequest, abStdReqData);\r
79 \r
80         return TRUE;\r
81 }\r
82 \r