00001
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
00045
00046
00047
00048
00049
00050 #include "conf_usb.h"
00051
00052
00053 #if USB_HOST_FEATURE == ENABLED
00054
00055 #include "board.h"
00056 #ifdef FREERTOS_USED
00057 #include "FreeRTOS.h"
00058 #include "task.h"
00059 #endif
00060 #include "usb_drv.h"
00061 #include "usb_host_enum.h"
00062 #include "usb_host_task.h"
00063 #include "host_template_task.h"
00064
00065
00066
00067
00068
00069
00070
00071 #if BOARD == EVK1100
00072 # define LED_APPLI_0 LED_BI0_GREEN
00073 # define LED_APPLI_1 LED_BI0_RED
00074 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
00075 # define LED_APPLI_0 LED2
00076 # define LED_APPLI_1 LED3
00077 #endif
00078
00079 #if !defined(LED_APPLI_0) || \
00080 !defined(LED_APPLI_1)
00081 # error The LED configuration to use in this example is missing.
00082 #endif
00083
00084
00085
00086
00087 static U16 sof_cnt;
00088 static U8 pipe_in;
00089 static U8 pipe_out;
00090 static U8 buf[64];
00091 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00092 static volatile U8 busy;
00093 #endif
00094
00095 volatile Bool tpl_new_device_connected;
00096
00097
00102 void host_template_task_init(void)
00103 {
00104 U8 i;
00105
00106 sof_cnt = 0;
00107 for (i = 0; i < sizeof(buf); i++) buf[i] = i;
00108 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00109 busy = FALSE;
00110 #endif
00111 tpl_new_device_connected = FALSE;
00112
00113 #ifdef FREERTOS_USED
00114 xTaskCreate(host_template_task,
00115 configTSK_USB_HTP_NAME,
00116 configTSK_USB_HTP_STACK_SIZE,
00117 NULL,
00118 configTSK_USB_HTP_PRIORITY,
00119 NULL);
00120 #endif // FREERTOS_USED
00121 }
00122
00123
00130 #ifdef FREERTOS_USED
00131 void host_template_task(void *pvParameters)
00132 #else
00133 void host_template_task(void)
00134 #endif
00135 {
00136 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE
00137 Status_t sta;
00138 U16 nb;
00139 #endif
00140 U8 i;
00141
00142 #ifdef FREERTOS_USED
00143 portTickType xLastWakeTime;
00144
00145 xLastWakeTime = xTaskGetTickCount();
00146 while (TRUE)
00147 {
00148 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HTP_PERIOD);
00149
00150 #endif // FREERTOS_USED
00151
00152
00153 if (Is_host_ready())
00154 {
00155
00156
00157 #if BOARD == EVK1100
00158
00159 LED_Display_Field(LED_MONO0_GREEN |
00160 LED_MONO1_GREEN |
00161 LED_MONO2_GREEN |
00162 LED_MONO3_GREEN,
00163 sof_cnt >> 5);
00164 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
00165
00166 LED_Display_Field(LED0 |
00167 LED1,
00168 sof_cnt >> 5);
00169 #else
00170 #error The display of the SOFs must be defined here.
00171 #endif
00172
00173
00174 if (tpl_new_device_connected)
00175 {
00176 tpl_new_device_connected = FALSE;
00177
00178 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00179
00180 busy = FALSE;
00181 #endif
00182
00183
00184 for (i = 0; i < Get_nb_supported_interface(); i++)
00185 {
00186
00187 if (Get_class(i) == VENDOR_CLASS)
00188 {
00189
00190 if (Is_ep_in(i, 0))
00191 {
00192 pipe_in = Get_ep_pipe(i, 0);
00193 pipe_out = Get_ep_pipe(i, 1);
00194 }
00195 else
00196 {
00197 pipe_in = Get_ep_pipe(i, 1);
00198 pipe_out = Get_ep_pipe(i, 0);
00199 }
00200 break;
00201 }
00202 }
00203 }
00204
00205 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE
00206
00207 LED_On(LED_APPLI_0);
00208 sta = host_send_data(pipe_out, sizeof(buf), buf);
00209 LED_Off(LED_APPLI_0);
00210
00211
00212 nb = sizeof(buf);
00213 LED_On(LED_APPLI_1);
00214 sta = host_get_data(pipe_in, &nb, buf);
00215 LED_Off(LED_APPLI_1);
00216 #else
00217
00218 if (!busy)
00219 {
00220 busy = TRUE;
00221 LED_On(LED_APPLI_0);
00222 host_send_data_interrupt(pipe_out, sizeof(buf), buf, host_send_data_callback);
00223 LED_Off(LED_APPLI_0);
00224 }
00225 #endif
00226
00227
00228 if (FALSE)
00229 {
00230 host_set_feature_remote_wakeup();
00231 Host_request_suspend();
00232 }
00233 }
00234
00235
00236 if (Is_host_suspended())
00237 {
00238 Host_request_resume();
00239 }
00240 #ifdef FREERTOS_USED
00241 }
00242 #endif
00243 }
00244
00245
00246 #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00247
00248 void host_send_data_callback(Status_t status, U16 nb_byte)
00249 {
00250 if (status == PIPE_GOOD)
00251 {
00252 LED_On(LED_APPLI_1);
00253 host_get_data_interrupt(pipe_in, sizeof(buf), buf, host_get_data_callback);
00254 LED_Off(LED_APPLI_1);
00255 }
00256 }
00257
00258
00259 void host_get_data_callback(Status_t status, U16 nb_byte)
00260 {
00261 if (status == PIPE_GOOD)
00262 {
00263 busy = FALSE;
00264 }
00265 }
00266
00267 #endif // USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
00268
00269
00277 void host_sof_action(void)
00278 {
00279 sof_cnt++;
00280 }
00281
00282
00283 #endif // USB_HOST_FEATURE == ENABLED