00001
00016 #ifndef _USB_HOST_TASK_H_
00017 #define _USB_HOST_TASK_H_
00018
00019
00020
00021
00022
00023
00024 typedef struct
00025 {
00026 bit enable;
00027 U16 nb_byte_to_process;
00028 U16 nb_byte_processed;
00029 U16 nb_byte_on_going;
00030 U8 *ptr_buf;
00031 void(*handle)(U8 status, U16 nb_byte);
00032 U8 status;
00033 U8 timeout;
00034 U16 nak_timeout;
00035 } S_pipe_int;
00036
00037
00038
00039
00040
00041 #define PIPE_GOOD 0
00042 #define PIPE_DATA_TOGGLE 0x01
00043 #define PIPE_DATA_PID 0x02
00044 #define PIPE_PID 0x04
00045 #define PIPE_TIMEOUT 0x08
00046 #define PIPE_CRC16 0x10
00047 #define PIPE_STALL 0x20
00048 #define PIPE_NAK_TIMEOUT 0x40
00049 #define PIPE_DELAY_TIMEOUT 0x80
00050
00053
00057 #define Is_host_ready() ((device_state==DEVICE_READY) ? TRUE : FALSE)
00058
00060 #define Is_host_not_ready() ((device_state==DEVICE_READY) ? FALSE :TRUE)
00061
00063 #define Is_host_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? TRUE : FALSE)
00064
00066 #define Is_host_not_suspended() (((device_state==DEVICE_WAIT_RESUME) ||(device_state==DEVICE_SUSPENDED)) ? FALSE : TRUE)
00067
00069 #define Is_host_unattached() ((device_state==DEVICE_UNATTACHED) ? TRUE : FALSE)
00070
00072 #define Is_host_attached() ((device_state>=DEVICE_UNATTACHED) ? TRUE : FALSE)
00073
00075 #define Host_request_suspend() (device_state=DEVICE_SUSPENDED)
00076
00078 #define Host_request_resume() (request_resume=TRUE)
00079
00081 #define Host_ack_request_resume() (request_resume=FALSE)
00082
00084 #define Host_force_enumeration() (force_enumeration=TRUE, device_state=DEVICE_ATTACHED)
00085
00087 #define Is_host_request_resume() ((request_resume==TRUE) ? TRUE : FALSE)
00088
00090 #define Is_new_device_connection_event() (new_device_connected ? TRUE : FALSE)
00091
00093 #define Is_device_disconnection_event() ((device_state==DEVICE_DISCONNECTED_ACK || device_state==DEVICE_DISCONNECTED) ? TRUE : FALSE)
00094
00096 #define Host_stop_pipe_interrupt(i) (\
00097 Host_disable_transmit_interrupt(), \
00098 Host_disable_receive_interrupt(), \
00099 Host_disable_stall_interrupt(), \
00100 Host_disable_error_interrupt(), \
00101 Host_disable_nak_interrupt(), \
00102 Host_reset_pipe(i))
00103
00108 #define DEVICE_UNATTACHED 0
00109 #define DEVICE_ATTACHED 1
00110 #define DEVICE_POWERED 2
00111 #define DEVICE_DEFAULT 3
00112 #define DEVICE_ADDRESSED 4
00113 #define DEVICE_CONFIGURED 5
00114 #define DEVICE_READY 6
00115
00116 #define DEVICE_ERROR 7
00117
00118 #define DEVICE_SUSPENDED 8
00119 #define DEVICE_WAIT_RESUME 9
00120
00121 #define DEVICE_DISCONNECTED 10
00122 #define DEVICE_DISCONNECTED_ACK 11
00123
00124 #define A_PERIPHERAL 12 // used for A-Device in OTG mode
00125 #define A_INIT_HNP 13
00126 #define A_SUSPEND 14
00127 #define A_END_HNP_WAIT_VFALL 15
00128 #define A_TEMPO_VBUS_DISCHARGE 16
00130
00131
00132 #define Host_set_device_supported() (device_status |= 0x01)
00133 #define Host_clear_device_supported() (device_status &= ~0x01)
00134 #define Is_host_device_supported() (device_status & 0x01)
00135
00136 #define Host_set_device_ready() (device_status |= 0x02)
00137 #define Host_clear_device_ready() (device_status &= ~0x02)
00138 #define Is_host_device_ready() (device_status & 0x02)
00139
00140 #define Host_set_configured() (device_status |= 0x04)
00141 #define Host_clear_configured() (device_status &= ~0x04)
00142 #define Is_host_configured() (device_status & 0x04)
00143
00144 #define Host_clear_device_status() (device_status = 0x00)
00145
00146
00147
00148
00160 void usb_host_task_init (void);
00161
00179 void usb_host_task (void);
00180
00193 U8 host_send_data(U8 pipe, U16 nb_data, U8 *buf);
00194
00210 U8 host_get_data(U8 pipe, U16 *nb_data, U8 *buf);
00211
00212 U8 host_get_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00213
00214 U8 host_send_data_interrupt(U8 pipe, U16 nb_data, U8 *buf, void (*handle)(U8 status, U16 nb_byte));
00215
00216 void reset_it_pipe_str(void);
00217
00218 U8 is_any_interrupt_pipe_active(void);
00219
00220
00221 extern U8 ep_table[];
00222 extern U8 device_state;
00223 extern U8 request_resume;
00224 extern U8 new_device_connected;
00225 extern U8 force_enumeration;
00226
00227 extern U8 usb_configuration_nb;
00228
00229
00230
00231
00234
00235 #ifndef USB_OTG_FEATURE
00236 #define USB_OTG_FEATURE DISABLED
00237 #endif
00238
00239
00240 extern U16 otg_ta_srp_wait_connect;
00241 extern U16 otg_ta_aidl_bdis_tmr;
00242 extern U8 otg_ta_vbus_rise;
00243 extern U16 otg_timeout_bdev_respond;
00244 extern U16 otg_end_hnp_vbus_delay;
00245
00246 extern U8 otg_a_device_srp;
00247 extern U8 otg_device_connected;
00248
00249
00251 #define Srp_received_and_waiting_connect() (otg_a_device_srp |= 0x01)
00252 #define Ack_srp_received_and_connect() (otg_a_device_srp &= ~0x01)
00253 #define Is_srp_received_and_waiting_connect() (((otg_a_device_srp&0x01) != 0) ? TRUE : FALSE)
00255 #define Host_session_started_srp() (otg_a_device_srp |= 0x02)
00256 #define Host_end_session_started_srp() (otg_a_device_srp &= ~0x02)
00257 #define Is_host_session_started_srp() (((otg_a_device_srp&0x02) != 0) ? TRUE : FALSE)
00258
00260 #define Peripheral_is_not_otg_device() (otg_device_connected = 0x00)
00261 #define Peripheral_is_otg_device() (otg_device_connected = 0x11)
00262 #define Is_peripheral_otg_device() ((otg_device_connected != 0) ? TRUE : FALSE)
00263
00265 #define T_VBUS_DELIV_AFTER_SRP 0xDAC // minimum time (x2ms) with Vbus ON once a SRP has been received (5s<t<30s)
00266 #define Init_ta_srp_counter() (otg_ta_srp_wait_connect = 0)
00267 #define Is_ta_srp_counter_overflow() ((otg_ta_srp_wait_connect > T_VBUS_DELIV_AFTER_SRP) ? TRUE : FALSE)
00269 #define TA_AIDL_BDIS 0x800 // minimum time (x2ms) in A_suspend state before stop Vbus (must be > 200ms)
00270
00271 #define Init_ta_aidl_bdis_counter() (otg_ta_aidl_bdis_tmr = TA_AIDL_BDIS)
00272 #define Is_ta_aidl_bdis_counter_overflow() ((otg_ta_aidl_bdis_tmr == 0x0001) ? TRUE : FALSE)
00274 #define TM_OUT_MAX_BDEV_RESPONSE 0xD00 // maximum delay for the A-Device waiting for a response from B-Device once attached
00275 #define Init_timeout_bdev_response() (otg_timeout_bdev_respond = TM_OUT_MAX_BDEV_RESPONSE)
00276 #define Is_timeout_bdev_response_overflow() ((otg_timeout_bdev_respond == 0) ? TRUE : FALSE)
00278 #define TA_VBUS_RISE 0x28 // maximum delay for Vbus to reach the Va_vbus_valid threshold after being requested (must be < 100ms)
00279 #define Init_ta_vbus_rise_counter() (otg_ta_vbus_rise = TA_VBUS_RISE)
00280 #define Is_ta_vbus_rise_counter_overflow() ((otg_ta_vbus_rise == 0) ? TRUE : FALSE)
00282 #define TA_VBUS_FALL 50
00283 #define Init_ta_vbus_fall_counter() (otg_end_hnp_vbus_delay = TA_VBUS_FALL)
00284 #define Is_ta_vbus_fall_counter_overflow() ((otg_end_hnp_vbus_delay == 0) ? TRUE : FALSE)
00285
00286
00288
00289
00290 #endif
00291