Contiki 2.5
usb_task.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 
3 
4 /*! \file usb_task.h *********************************************************************
5  *
6  * \brief
7  * This file manages the USB task either device/host or both.
8  *
9  * The USB task selects the correct USB task (usb_device task or usb_host task
10  * to be executed depending on the current mode available.
11  *
12  * According to USB_DEVICE_FEATURE and USB_HOST_FEATURE value (located in conf_usb.h file)
13  * The usb_task can be configured to support USB DEVICE mode or USB Host mode or both
14  * for a dual role device application.
15  *
16  * This module also contains the general USB interrupt subroutine. This subroutine is used
17  * to detect asynchronous USB events.
18  *
19  * Note:
20  * - The usb_task belongs to the scheduler, the usb_device_task and usb_host do not, they are called
21  * from the general usb_task
22  * - See conf_usb.h file for more details about the configuration of this module
23  *
24  * \addtogroup usbstick
25  *
26  * \author
27  * Atmel Corporation: http://www.atmel.com \n
28  * Support email: avr@atmel.com
29  *
30  ******************************************************************************/
31 /* Copyright (c) 2008 ATMEL Corporation
32  All rights reserved.
33 
34  Redistribution and use in source and binary forms, with or without
35  modification, are permitted provided that the following conditions are met:
36 
37  * Redistributions of source code must retain the above copyright
38  notice, this list of conditions and the following disclaimer.
39  * Redistributions in binary form must reproduce the above copyright
40  notice, this list of conditions and the following disclaimer in
41  the documentation and/or other materials provided with the
42  distribution.
43  * Neither the name of the copyright holders nor the names of
44  contributors may be used to endorse or promote products derived
45  from this software without specific prior written permission.
46 
47  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
51  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57  POSSIBILITY OF SUCH DAMAGE.
58 */
59 
60 #ifndef _USB_TASK_H_
61 #define _USB_TASK_H_
62 
63 /**
64  \ingroup usbstick
65  \defgroup usbdriver USB Driver
66  @{
67 */
68 
69 //_____ I N C L U D E S ____________________________________________________
70 
71 
72 //_____ M A C R O S ________________________________________________________
73 
74 //! \name USB Events
75 //! @{
76 
77 //! Send event
78 #define Usb_send_event(x) (g_usb_event |= (1<<x))
79 //! Ack event processed
80 #define Usb_ack_event(x) (g_usb_event &= ~(1<<x))
81 //! Clear all events
82 #define Usb_clear_all_event() (g_usb_event = 0)
83 //! Check for USB event
84 #define Is_usb_event(x) ((g_usb_event & (1<<x)) ? TRUE : FALSE)
85 //! Check for USB event NOT occuring
86 #define Is_not_usb_event(x) ((g_usb_event & (1<<x)) ? FALSE: TRUE)
87 //! Check if USB is device
88 #define Is_usb_device() (g_usb_mode==USB_MODE_DEVICE ? TRUE : FALSE)
89 
90 
91 //! USB Event: USB plugged
92 #define EVT_USB_POWERED 1
93 //! USB Event: USB un-plugged
94 #define EVT_USB_UNPOWERED 2
95 //! USB Event: USB in device
96 #define EVT_USB_DEVICE_FUNCTION 3
97 //! USB Event: USB in host
98 #define EVT_USB_HOST_FUNCTION 4
99 //! USB Event: USB suspend
100 #define EVT_USB_SUSPEND 5
101 //! USB Event: USB wake up
102 #define EVT_USB_WAKE_UP 6
103 //! USB Event: USB resume
104 #define EVT_USB_RESUME 7
105 //! USB Event: USB reset
106 #define EVT_USB_RESET 8
107 //! USB Event: USB setup received
108 #define EVT_USB_SETUP_RX 9
109 //! @}
110 
111 //! \name Standard requests defines
112 //! @{
113 
114  #define GET_STATUS 0x00
115  #define GET_DEVICE 0x01
116  #define CLEAR_FEATURE 0x01 //!< see FEATURES below
117  #define GET_STRING 0x03
118  #define SET_FEATURE 0x03 //!< see FEATURES below
119  #define SET_ADDRESS 0x05
120  #define GET_DESCRIPTOR 0x06
121  #define SET_DESCRIPTOR 0x07
122  #define GET_CONFIGURATION 0x08
123  #define SET_CONFIGURATION 0x09
124  #define GET_INTERFACE 0x0A
125  #define SET_INTERFACE 0x0B
126  #define SYNCH_FRAME 0x0C
127 
128  #define GET_DEVICE_DESCRIPTOR 1
129  #define GET_CONFIGURATION_DESCRIPTOR 4
130 
131  #define REQUEST_DEVICE_STATUS 0x80
132  #define REQUEST_INTERFACE_STATUS 0x81
133  #define REQUEST_ENDPOINT_STATUS 0x82
134  #define ZERO_TYPE 0x00
135  #define INTERFACE_TYPE 0x01
136  #define ENDPOINT_TYPE 0x02
137 
138  // Descriptor Types
139  #define DEVICE_DESCRIPTOR 0x01
140  #define CONFIGURATION_DESCRIPTOR 0x02
141  #define STRING_DESCRIPTOR 0x03
142  #define INTERFACE_DESCRIPTOR 0x04
143  #define ENDPOINT_DESCRIPTOR 0x05
144  #define DEVICE_QUALIFIER_DESCRIPTOR 0x06
145  #define OTHER_SPEED_CONFIGURATION_DESCRIPTOR 0x07
146 
147 
148 
149  // Standard Features
150  #define FEATURE_DEVICE_REMOTE_WAKEUP 0x01
151  #define FEATURE_ENDPOINT_HALT 0x00
152 
153  #define TEST_J 0x01
154  #define TEST_K 0x02
155  #define TEST_SEO_NAK 0x03
156  #define TEST_PACKET 0x04
157  #define TEST_FORCE_ENABLE 0x05
158 
159 
160  // Device Status
161  #define BUS_POWERED 0
162  #define SELF_POWERED 1
163 
164  //! @}
165 
166 #define USB_MODE_UNDEFINED 0x00
167 #define USB_MODE_HOST 0x01
168 #define USB_MODE_DEVICE 0x02
169 
170 
171 typedef enum {
172  rndis_only,
173  rndis_debug,
174  mass_storage,
175  eem
176 } usb_mode_t;
177 
178 //_____ D E C L A R A T I O N S ____________________________________________
179 
180 extern volatile uint16_t g_usb_event;
181 extern uint8_t g_usb_mode;
182 
183 
184 PROCESS_NAME(usb_process);
185 
186 extern volatile uint8_t private_sof_counter;
187 
188 void usb_start_device (void);
189 void usb_device_task (void);
190 
191 
192 //! @}
193 
194 #endif /* _USB_TASK_H_ */
195 
196 /** @} */