00001
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #ifndef _USB_TASK_H_
00064 #define _USB_TASK_H_
00065
00066
00069
00070
00071
00072 #include "compiler.h"
00073 #include "preprocessor.h"
00074 #include "conf_usb.h"
00075
00076
00077
00078
00082 #define Usb_send_event(x) (Set_bits(g_usb_event, 1 << (x)))
00083 #define Usb_ack_event(x) (Clr_bits(g_usb_event, 1 << (x)))
00084 #define Is_usb_event(x) (Tst_bits(g_usb_event, 1 << (x)))
00085 #define Usb_clear_all_event() (g_usb_event = 0x0000)
00086 #define Is_host_emergency_exit() (Is_usb_device() || Is_usb_event(EVT_HOST_DISCONNECTION) || Is_usb_event(EVT_USB_DEVICE_FUNCTION))
00087 #define Is_usb_device() (g_usb_mode == USB_MODE_DEVICE)
00088 #define Is_usb_host() (g_usb_mode == USB_MODE_HOST)
00089
00090 #define EVT_USB_POWERED 1 // USB plugged
00091 #define EVT_USB_UNPOWERED 2 // USB unplugged
00092 #define EVT_USB_DEVICE_FUNCTION 3 // USB in device
00093 #define EVT_USB_HOST_FUNCTION 4 // USB in host
00094 #define EVT_USB_SUSPEND 5 // USB suspend
00095 #define EVT_USB_WAKE_UP 6 // USB wake-up
00096 #define EVT_USB_RESUME 7 // USB resume
00097 #define EVT_USB_RESET 8 // USB reset
00098 #define EVT_HOST_SOF 9 // Host start-of-frame sent
00099 #define EVT_HOST_HWUP 10 // Host wake-up detected
00100 #define EVT_HOST_DISCONNECTION 11 // The target device is disconnected
00102
00105 #define GET_STATUS 0x00
00106 #define GET_DEVICE 0x01
00107 #define CLEAR_FEATURE 0x01
00108 #define GET_STRING 0x03
00109 #define SET_FEATURE 0x03
00110 #define SET_ADDRESS 0x05
00111 #define GET_DESCRIPTOR 0x06
00112 #define SET_DESCRIPTOR 0x07
00113 #define GET_CONFIGURATION 0x08
00114 #define SET_CONFIGURATION 0x09
00115 #define GET_INTERFACE 0x0A
00116 #define SET_INTERFACE 0x0B
00117 #define SYNCH_FRAME 0x0C
00118
00119 #define GET_DEVICE_DESCRIPTOR 1
00120 #define GET_CONFIGURATION_DESCRIPTOR 4
00121
00122 #define REQUEST_DEVICE_STATUS 0x80
00123 #define REQUEST_INTERFACE_STATUS 0x81
00124 #define REQUEST_ENDPOINT_STATUS 0x82
00125 #define DEVICE_TYPE 0x00
00126 #define INTERFACE_TYPE 0x01
00127 #define ENDPOINT_TYPE 0x02
00128
00129
00130 #define DEVICE_DESCRIPTOR 0x01
00131 #define CONFIGURATION_DESCRIPTOR 0x02
00132 #define STRING_DESCRIPTOR 0x03
00133 #define INTERFACE_DESCRIPTOR 0x04
00134 #define ENDPOINT_DESCRIPTOR 0x05
00135 #define DEVICE_QUALIFIER_DESCRIPTOR 0x06
00136 #define OTHER_SPEED_CONFIGURATION_DESCRIPTOR 0x07
00137
00138
00139 #define FEATURE_DEVICE_REMOTE_WAKEUP 0x01
00140 #define FEATURE_ENDPOINT_HALT 0x00
00141 #define FEATURE_TEST_MODE 0x02
00142
00143
00144 #define TEST_J 0x01
00145 #define TEST_K 0x02
00146 #define TEST_SE0_NAK 0x03
00147 #define TEST_PACKET 0x04
00148 #define TEST_FORCE_ENABLE 0x05
00149
00150
00151 #define BUS_POWERED 0
00152 #define SELF_POWERED 1
00153
00154
00155 #define MSK_EP_NBR 0x0F
00156 #define MSK_EP_DIR 0x80
00157
00161 #define Get_desc_ep_nbr(ep_addr) (Rd_bitfield(ep_addr, MSK_EP_NBR))
00162
00166 #define Get_desc_ep_dir(ep_addr) (Rd_bitfield(ep_addr, MSK_EP_DIR))
00167
00174 #if LITTLE_ENDIAN_MCU
00175 #define Usb_format_mcu_to_usb_data(width, data) ((TPASTE2(U, width))(data))
00176 #define Usb_format_usb_to_mcu_data(width, data) ((TPASTE2(U, width))(data))
00177 #define usb_format_mcu_to_usb_data(width, data) ((TPASTE2(U, width))(data))
00178 #define usb_format_usb_to_mcu_data(width, data) ((TPASTE2(U, width))(data))
00179 #else // BIG_ENDIAN_MCU
00180 #define Usb_format_mcu_to_usb_data(width, data) (TPASTE2(Swap, width)(data))
00181 #define Usb_format_usb_to_mcu_data(width, data) (TPASTE2(Swap, width)(data))
00182 #define usb_format_mcu_to_usb_data(width, data) (TPASTE2(swap, width)(data))
00183 #define usb_format_usb_to_mcu_data(width, data) (TPASTE2(swap, width)(data))
00184 #endif
00187
00188 #define USB_MODE_UNDEFINED 0x00
00189 #define USB_MODE_DEVICE 0x01
00190 #define USB_MODE_HOST 0x02
00191
00192
00193
00194
00195 extern volatile U16 g_usb_event;
00196
00197 #if USB_HOST_FEATURE == ENABLED
00198 extern volatile U32 private_sof_counter;
00199 #endif
00200
00201 #if USB_DEVICE_FEATURE == ENABLED && USB_HOST_FEATURE == ENABLED
00202 extern volatile U8 g_usb_mode;
00203 #elif USB_DEVICE_FEATURE == ENABLED
00204 #define g_usb_mode USB_MODE_DEVICE
00205 #elif USB_HOST_FEATURE == ENABLED
00206 #define g_usb_mode USB_MODE_HOST
00207 #else
00208 #error At least one of USB_DEVICE_FEATURE and USB_HOST_FEATURE must be enabled
00209 #endif
00210
00211 #if (!defined USB_HIGH_SPEED_SUPPORT)
00212 #define USB_HIGH_SPEED_SUPPORT DISABLED
00213 #endif
00214
00222 extern void usb_task_init(void);
00223
00228 #ifdef FREERTOS_USED
00229 extern void usb_task(void *pvParameters);
00230 #else
00231 extern void usb_task(void);
00232 #endif
00233
00235
00236
00237 #endif // _USB_TASK_H_