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
00042
00043
00044 #ifndef _USB_HOST_TASK_H_
00045 #define _USB_HOST_TASK_H_
00046
00047
00048
00049 #if (USB_HUB_SUPPORT==ENABLE)
00050 #include "modules/usb/host_chap9/usb_host_hub.h"
00051 #endif
00052
00053
00054
00055 typedef struct
00056 {
00057 bit enable;
00058 U16 nb_byte_to_process;
00059 U16 nb_byte_processed;
00060 U16 nb_byte_on_going;
00061 U8 *ptr_buf;
00062 void(*handle)(U8 status, U16 nb_byte);
00063 U8 status;
00064 U8 timeout;
00065 U16 nak_timeout;
00066 } S_pipe_int;
00067
00068
00069
00070
00071
00072 #define PIPE_GOOD 0
00073 #define PIPE_DATA_TOGGLE 0x01
00074 #define PIPE_DATA_PID 0x02
00075 #define PIPE_PID 0x04
00076 #define PIPE_TIMEOUT 0x08
00077 #define PIPE_CRC16 0x10
00078 #define PIPE_STALL 0x20
00079 #define PIPE_NAK_TIMEOUT 0x40
00080 #define PIPE_DELAY_TIMEOUT 0x80
00081
00084
00088 #define Is_host_ready() ((device_state==DEVICE_READY) ? TRUE : FALSE)
00089
00091 #define Is_host_not_ready() ((device_state==DEVICE_READY) ? FALSE :TRUE)
00092
00094 #define Is_host_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? TRUE : FALSE)
00095
00097 #define Is_host_not_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? FALSE : TRUE)
00098
00100 #define Is_host_unattached() ((device_state==DEVICE_UNATTACHED) ? TRUE : FALSE)
00101
00103 #define Is_host_attached() ((device_state>=DEVICE_UNATTACHED) ? TRUE : FALSE)
00104
00106 #define Host_request_suspend() (device_state=DEVICE_SUSPENDED)
00107
00109 #define Host_request_resume() (request_resume=TRUE)
00110
00112 #define Host_ack_request_resume() (request_resume=FALSE)
00113
00115 #define Host_force_enumeration() (force_enumeration=TRUE, device_state=DEVICE_ATTACHED, init_usb_tree())
00116
00118 #define Is_host_request_resume() ((request_resume==TRUE) ? TRUE : FALSE)
00119
00121 #define Is_new_device_connection_event() (new_device_connected ? TRUE : FALSE)
00122
00124 #if (USB_HUB_SUPPORT==ENABLE)
00125 #define Is_device_disconnection_event() ((device_state==DEVICE_DISCONNECTED_ACK || device_state==DEVICE_DISCONNECTED || f_hub_port_disconnect) ? TRUE : FALSE)
00126 #else
00127 #define Is_device_disconnection_event() ((device_state==DEVICE_DISCONNECTED_ACK || device_state==DEVICE_DISCONNECTED) ? TRUE : FALSE)
00128 #endif
00129
00131 #define Host_stop_pipe_interrupt(i) (\
00132 Host_disable_transmit_interrupt(), \
00133 Host_disable_receive_interrupt(), \
00134 Host_disable_stall_interrupt(), \
00135 Host_disable_error_interrupt(), \
00136 Host_disable_nak_interrupt(), \
00137 Host_reset_pipe(i))
00138
00143 #define DEVICE_UNATTACHED 0
00144 #define DEVICE_ATTACHED 1
00145 #define DEVICE_POWERED 2
00146 #define DEVICE_DEFAULT 3
00147 #define DEVICE_ADDRESSED 4
00148 #define DEVICE_CONFIGURED 5
00149 #define DEVICE_READY 6
00150
00151 #define DEVICE_ERROR 7
00152
00153 #define DEVICE_SUSPENDED 8
00154 #define DEVICE_WAIT_RESUME 9
00155
00156 #define DEVICE_DISCONNECTED 10
00157 #define DEVICE_DISCONNECTED_ACK 11
00158
00159 #define Host_set_device_supported() (device_status |= 0x01)
00160 #define Host_clear_device_supported() (device_status &= ~0x01)
00161 #define Is_host_device_supported() (device_status & 0x01)
00162
00163 #define Host_set_device_ready() (device_status |= 0x02)
00164 #define Host_clear_device_ready() (device_status &= ~0x02)
00165 #define Is_host_device_ready() (device_status & 0x02)
00166
00167 #define Host_set_configured() (device_status |= 0x04)
00168 #define Host_clear_configured() (device_status &= ~0x04)
00169 #define Is_host_configured() (device_status & 0x04)
00170
00171 #define Host_clear_device_status() (device_status = 0x00)
00173
00174
00175
00176
00177
00189 void usb_host_task_init (void);
00190
00208 void usb_host_task (void);
00209
00222 U8 host_send_data(U8 pipe, U16 nb_data, U8 *buf);
00223
00239 U8 host_get_data(U8 pipe, U16 *nb_data, U8 *buf);
00240
00241 U8 host_get_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00242
00243 U8 host_send_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00244
00245 void reset_it_pipe_str(void);
00246
00247 U8 is_any_interrupt_pipe_active(void);
00248
00249 extern U8 device_state;
00250 extern U8 request_resume;
00251 extern U8 new_device_connected;
00252 extern U8 force_enumeration;
00253
00254
00256
00257
00258 #endif
00259