Removed new Start of Frame event from the library; performance suffered far too much...
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / USBTask.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #include "USBMode.h"
32
33 #define INCLUDE_FROM_USBTASK_C
34 #include "USBTask.h"
35
36 volatile bool USB_IsSuspended;
37 volatile bool USB_IsConnected;
38 volatile bool USB_IsInitialized;
39 USB_Request_Header_t USB_ControlRequest;
40
41 #if defined(USB_CAN_BE_HOST)
42 volatile uint8_t USB_HostState;
43 #endif
44
45 void USB_USBTask(void)
46 {
47 #if defined(USB_HOST_ONLY)
48 USB_HostTask();
49 #elif defined(USB_DEVICE_ONLY)
50 USB_DeviceTask();
51 #else
52 if (USB_CurrentMode == USB_MODE_DEVICE)
53 USB_DeviceTask();
54 else if (USB_CurrentMode == USB_MODE_HOST)
55 USB_HostTask();
56 #endif
57 }
58
59 #if defined(USB_CAN_BE_DEVICE)
60 static void USB_DeviceTask(void)
61 {
62 if (USB_IsConnected)
63 {
64 uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
65
66 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
67
68 if (Endpoint_IsSETUPReceived())
69 {
70 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
71 {
72 USB_Device_ProcessControlPacket();
73 }
74 }
75
76 Endpoint_SelectEndpoint(PrevEndpoint);
77 }
78 }
79 #endif
80
81 #if defined(USB_CAN_BE_HOST)
82 static void USB_HostTask(void)
83 {
84 uint8_t PrevPipe = Pipe_GetCurrentPipe();
85
86 Pipe_SelectPipe(PIPE_CONTROLPIPE);
87
88 USB_Host_ProcessNextHostState();
89
90 Pipe_SelectPipe(PrevPipe);
91 }
92 #endif