00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef _USB_HOST_TASK_H_
00042 #define _USB_HOST_TASK_H_
00043
00044
00045
00046 #if (USB_HUB_SUPPORT==ENABLE)
00047 #include "modules/usb/host_chap9/usb_host_hub.h"
00048 #endif
00049
00050
00051
00052 typedef struct
00053 {
00054 bit enable;
00055 U16 nb_byte_to_process;
00056 U16 nb_byte_processed;
00057 U16 nb_byte_on_going;
00058 U8 *ptr_buf;
00059 void(*handle)(U8 status, U16 nb_byte);
00060 U8 status;
00061 U8 timeout;
00062 U16 nak_timeout;
00063 } S_pipe_int;
00064
00065
00066
00067
00068
00069 #define PIPE_GOOD 0
00070 #define PIPE_DATA_TOGGLE 0x01
00071 #define PIPE_DATA_PID 0x02
00072 #define PIPE_PID 0x04
00073 #define PIPE_TIMEOUT 0x08
00074 #define PIPE_CRC16 0x10
00075 #define PIPE_STALL 0x20
00076 #define PIPE_NAK_TIMEOUT 0x40
00077 #define PIPE_DELAY_TIMEOUT 0x80
00078
00081
00085 #define Is_host_ready() ((device_state==DEVICE_READY) ? TRUE : FALSE)
00086
00088 #define Is_host_not_ready() ((device_state==DEVICE_READY) ? FALSE :TRUE)
00089
00091 #define Is_host_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? TRUE : FALSE)
00092
00094 #define Is_host_not_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? FALSE : TRUE)
00095
00097 #define Is_host_unattached() ((device_state==DEVICE_UNATTACHED) ? TRUE : FALSE)
00098
00100 #define Is_host_attached() ((device_state>=DEVICE_UNATTACHED) ? TRUE : FALSE)
00101
00103 #define Host_request_suspend() (device_state=DEVICE_SUSPENDED)
00104
00106 #define Host_request_resume() (request_resume=TRUE)
00107
00109 #define Host_ack_request_resume() (request_resume=FALSE)
00110
00112 #define Host_force_enumeration() (force_enumeration=TRUE, device_state=DEVICE_ATTACHED, init_usb_tree())
00113
00115 #define Is_host_request_resume() ((request_resume==TRUE) ? TRUE : FALSE)
00116
00118 #define Is_new_device_connection_event() (new_device_connected ? TRUE : FALSE)
00119
00121 #if (USB_HUB_SUPPORT==ENABLE)
00122 #define Is_device_disconnection_event() ((device_state==DEVICE_DISCONNECTED_ACK || device_state==DEVICE_DISCONNECTED || f_hub_port_disconnect) ? TRUE : FALSE)
00123 #else
00124 #define Is_device_disconnection_event() ((device_state==DEVICE_DISCONNECTED_ACK || device_state==DEVICE_DISCONNECTED) ? TRUE : FALSE)
00125 #endif
00126
00128 #define Host_stop_pipe_interrupt(i) (\
00129 Host_disable_transmit_interrupt(), \
00130 Host_disable_receive_interrupt(), \
00131 Host_disable_stall_interrupt(), \
00132 Host_disable_error_interrupt(), \
00133 Host_disable_nak_interrupt(), \
00134 Host_reset_pipe(i))
00135
00140 #define DEVICE_UNATTACHED 0
00141 #define DEVICE_ATTACHED 1
00142 #define DEVICE_POWERED 2
00143 #define DEVICE_DEFAULT 3
00144 #define DEVICE_ADDRESSED 4
00145 #define DEVICE_CONFIGURED 5
00146 #define DEVICE_READY 6
00147
00148 #define DEVICE_ERROR 7
00149
00150 #define DEVICE_SUSPENDED 8
00151 #define DEVICE_WAIT_RESUME 9
00152
00153 #define DEVICE_DISCONNECTED 10
00154 #define DEVICE_DISCONNECTED_ACK 11
00155
00156 #define Host_set_device_supported() (device_status |= 0x01)
00157 #define Host_clear_device_supported() (device_status &= ~0x01)
00158 #define Is_host_device_supported() (device_status & 0x01)
00159
00160 #define Host_set_device_ready() (device_status |= 0x02)
00161 #define Host_clear_device_ready() (device_status &= ~0x02)
00162 #define Is_host_device_ready() (device_status & 0x02)
00163
00164 #define Host_set_configured() (device_status |= 0x04)
00165 #define Host_clear_configured() (device_status &= ~0x04)
00166 #define Is_host_configured() (device_status & 0x04)
00167
00168 #define Host_clear_device_status() (device_status = 0x00)
00170
00171
00172
00173
00174
00186 void usb_host_task_init (void);
00187
00205 void usb_host_task (void);
00206
00219 U8 host_send_data(U8 pipe, U16 nb_data, U8 *buf);
00220
00236 U8 host_get_data(U8 pipe, U16 *nb_data, U8 *buf);
00237
00238 U8 host_get_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00239
00240 U8 host_send_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00241
00242 void reset_it_pipe_str(void);
00243
00244 U8 is_any_interrupt_pipe_active(void);
00245
00246 extern U8 device_state;
00247 extern U8 request_resume;
00248 extern U8 new_device_connected;
00249 extern U8 force_enumeration;
00250
00251
00253
00254
00255 #endif
00256