00001
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
00045
00046
00047
00048
00049 #ifndef _USB_HOST_TASK_H_
00050 #define _USB_HOST_TASK_H_
00051
00052
00053 #include "conf_usb.h"
00054
00055 #if USB_HOST_FEATURE == DISABLED
00056 #error usb_host_task.h is #included although USB_HOST_FEATURE is disabled
00057 #endif
00058
00059
00062
00063
00064
00065 #include "compiler.h"
00066 #include "usb_host_enum.h"
00067
00068
00069
00070
00071 typedef void Pipe_handler(Status_t status, U16 nb_byte);
00072
00073 typedef struct
00074 {
00075 Bool enable;
00076 U16 nb_byte_to_process;
00077 U16 nb_byte_processed;
00078 U16 nb_byte_on_going;
00079 void *ptr_buf;
00080 Pipe_handler *handler;
00081 Status_t status;
00082 U8 timeout;
00083 U16 nak_timeout;
00084 } S_pipe_int;
00085
00086
00087
00088
00089 #define PIPE_GOOD 0x00
00090 #define PIPE_DATA_TOGGLE 0x01
00091 #define PIPE_DATA_PID 0x02
00092 #define PIPE_PID 0x04
00093 #define PIPE_TIMEOUT 0x08
00094 #define PIPE_CRC16 0x10
00095 #define PIPE_STALL 0x20
00096 #define PIPE_NAK_TIMEOUT 0x40
00097 #define PIPE_DELAY_TIMEOUT 0x80
00098
00101 #define Is_host_ready() (device_state == DEVICE_READY)
00102
00104 #define Is_host_suspended() (device_state == DEVICE_WAIT_RESUME ||\
00105 device_state == DEVICE_SUSPENDED)
00106
00108 #define Is_host_error() (device_state == DEVICE_ERROR)
00109
00111 #define Is_host_addressed() (device_state >= DEVICE_ADDRESSED)
00112
00114 #define Is_host_powered() (device_state >= DEVICE_POWERED)
00115
00117 #define Is_host_attached() (device_state >= DEVICE_ATTACHED)
00118
00120 #define Host_request_suspend() (device_state = DEVICE_SUSPENDED)
00121
00123 #define Host_request_resume() (request_resume = TRUE)
00124
00126 #define Host_ack_request_resume() (request_resume = FALSE)
00127
00129 #define Is_host_request_resume() (request_resume == TRUE)
00130
00135 #define DEVICE_UNATTACHED 0
00136 #define DEVICE_ATTACHED 1
00137 #define DEVICE_POWERED 2
00138 #define DEVICE_DEFAULT 3
00139 #define DEVICE_ADDRESSED 4
00140 #define DEVICE_CONFIGURED 5
00141 #define DEVICE_READY 6
00142
00143 #define DEVICE_ERROR 7
00144
00145 #define DEVICE_SUSPENDED 8
00146 #define DEVICE_WAIT_RESUME 9
00147
00148 #define Host_set_device_supported() (Set_bits(device_status, 0x01))
00149 #define Host_clear_device_supported() (Clr_bits(device_status, 0x01))
00150 #define Is_host_device_supported() (Tst_bits(device_status, 0x01))
00151
00152 #define Host_set_device_ready() (Set_bits(device_status, 0x02))
00153 #define Host_clear_device_ready() (Clr_bits(device_status, 0x02))
00154 #define Is_host_device_ready() (Tst_bits(device_status, 0x02))
00155
00156 #define Host_set_configured() (Set_bits(device_status, 0x04))
00157 #define Host_clear_configured() (Clr_bits(device_status, 0x04))
00158 #define Is_host_configured() (Tst_bits(device_status, 0x04))
00159
00160 #define Host_clear_device_status() (device_status = 0x00)
00162
00163
00164
00165
00171 extern void usb_host_task_init(void);
00172
00185 #ifdef FREERTOS_USED
00186 extern void usb_host_task(void *pvParameters);
00187 #else
00188 extern void usb_host_task(void);
00189 #endif
00190
00203 extern Status_t host_send_data(U8 pipe, U16 nb_data, const void *ptr_buf);
00204
00219 extern Status_t host_get_data(U8 pipe, U16 *nb_data, void *ptr_buf);
00220
00221 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00222
00223 extern void reset_it_pipe_str(void);
00224
00225 extern Bool is_any_interrupt_pipe_active(void);
00226
00237 extern Bool host_send_data_interrupt(U8 pipe, U16 nb_data, const void *ptr_buf, Pipe_handler *handler);
00238
00251 extern Bool host_get_data_interrupt(U8 pipe, U16 nb_data, void *ptr_buf, Pipe_handler *handler);
00252
00258 extern void usb_pipe_interrupt(U8 pipe);
00259
00260 #endif // USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00261
00262 extern volatile U8 device_state;
00263 extern volatile S_usb_setup_data usb_request;
00264 extern U8 data_stage[SIZEOF_DATA_STAGE];
00265 extern volatile U8 device_status;
00266 extern volatile Bool request_resume;
00267
00269
00270
00271 #endif // _USB_HOST_TASK_H_