| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBTask.c
Go to the documentation of this file.
1 /*
2 * @brief Main USB service task management
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * Copyright(C) Dean Camera, 2011, 2012
7 * All rights reserved.
8 *
9 * @par
10 * Software that is described herein is for illustrative purposes only
11 * which provides customers with programming information regarding the
12 * LPC products. This software is supplied "AS IS" without any warranties of
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
14 * all warranties, express or implied, including all implied warranties of
15 * merchantability, fitness for a particular purpose and non-infringement of
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
17 * or liability for the use of the software, conveys no license or rights under any
18 * patent, copyright, mask work right, or any other intellectual property rights in
19 * or to any products. NXP Semiconductors reserves the right to make changes
20 * in the software without notification. NXP Semiconductors also makes no
21 * representation or warranty that such application will be suitable for the
22 * specified use without further testing or modification.
23 *
24 * @par
25 * Permission to use, copy, modify, and distribute this software and its
26 * documentation is hereby granted, under NXP Semiconductors' and its
27 * licensor's relevant copyrights in the software, without fee, provided that it
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
29 * copyright, permission, and disclaimer notice must appear in all copies of
30 * this code.
31 */
32
33
34 #define __INCLUDE_FROM_USBTASK_C
35 #define __INCLUDE_FROM_USB_DRIVER
36 #include "USBTask.h"
37
38 volatile bool USB_IsInitialized;
39
40 /* This structure must be 4 bytes aligned */
41 PRAGMA_ALIGN_4
42 USB_Request_Header_t USB_ControlRequest ATTR_ALIGNED(4) __BSS(USBRAM_SECTION);
43
44 #if defined(USB_CAN_BE_HOST) && !defined(HOST_STATE_AS_GPIOR)
45 volatile uint8_t USB_HostState[MAX_USB_CORE];
46 #endif
47
48 #if defined(USB_CAN_BE_DEVICE) && !defined(DEVICE_STATE_AS_GPIOR)
49 volatile uint8_t USB_DeviceState[MAX_USB_CORE];
50 #endif
51
52 void USB_USBTask(uint8_t corenum, uint8_t mode)
53 {
54 #if defined(USB_HOST_ONLY)
55 USB_HostTask(corenum);
56 #elif defined(USB_DEVICE_ONLY)
57 USB_DeviceTask(corenum);
58 #else
59 if (mode == USB_MODE_Device)
60 USB_DeviceTask(corenum);
61 else if (mode == USB_MODE_Host)
62 USB_HostTask(corenum);
63 #endif
64 }
65
66 #if defined(USB_CAN_BE_DEVICE)
67 static void USB_DeviceTask(uint8_t corenum)
68 {
69 if (USB_DeviceState[corenum] != DEVICE_STATE_Unattached)
70 {
71 uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint(corenum);
72
73 Endpoint_SelectEndpoint(corenum, ENDPOINT_CONTROLEP);
74
75 if (Endpoint_IsSETUPReceived(corenum))
76 USB_Device_ProcessControlRequest(corenum);
77
78 Endpoint_SelectEndpoint(corenum, PrevEndpoint);
79 }
80 }
81 #endif
82
83 #if defined(USB_CAN_BE_HOST)
84 static void USB_HostTask(uint8_t corenum)
85 {
86
87 uint8_t PrevPipe;
88
89 PrevPipe = Pipe_GetCurrentPipe(corenum);
90 Pipe_SelectPipe(corenum,PIPE_CONTROLPIPE);
91 USB_Host_ProcessNextHostState(corenum);
92 Pipe_SelectPipe(corenum,PrevPipe);
93 }
94 #endif
95