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_DEVICE_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_descriptors.h"
00062 #include "usb_standard_request.h"
00063 #include "device_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 == EVK1104 || BOARD == UC3C_EK || 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 data_length;
00089
00090
00094 void device_template_task_init(void)
00095 {
00096 sof_cnt = 0;
00097 data_length = 0;
00098 #ifndef FREERTOS_USED
00099 #if USB_HOST_FEATURE == ENABLED
00100
00101
00102
00103 if (Is_usb_device())
00104 #endif // USB_HOST_FEATURE == ENABLED
00105 Usb_enable_sof_interrupt();
00106 #endif // FREERTOS_USED
00107
00108 #ifdef FREERTOS_USED
00109 xTaskCreate(device_template_task,
00110 configTSK_USB_DTP_NAME,
00111 configTSK_USB_DTP_STACK_SIZE,
00112 NULL,
00113 configTSK_USB_DTP_PRIORITY,
00114 NULL);
00115 #endif // FREERTOS_USED
00116 }
00117
00118
00124 #ifdef FREERTOS_USED
00125 void device_template_task(void *pvParameters)
00126 #else
00127 void device_template_task(void)
00128 #endif
00129 {
00130 static U8 buf[EP_SIZE_TEMP2];
00131
00132 #ifdef FREERTOS_USED
00133 portTickType xLastWakeTime;
00134
00135 xLastWakeTime = xTaskGetTickCount();
00136 while (TRUE)
00137 {
00138 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DTP_PERIOD);
00139
00140
00141 if (!Is_device_enumerated()) continue;
00142 #else
00143
00144 if (!Is_device_enumerated()) return;
00145 #endif // FREERTOS_USED
00146
00147
00148
00149
00150
00151
00152 #if BOARD == EVK1100
00153
00154 LED_Display_Field(LED_MONO0_GREEN |
00155 LED_MONO1_GREEN |
00156 LED_MONO2_GREEN |
00157 LED_MONO3_GREEN,
00158 sof_cnt >> 5);
00159 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
00160
00161 LED_Display_Field(LED0 |
00162 LED1,
00163 sof_cnt >> 5);
00164 #else
00165 #error The display of the SOFs must be defined here.
00166 #endif
00167
00168
00169 if (Is_usb_out_received(EP_TEMP_OUT))
00170 {
00171 LED_On(LED_APPLI_1);
00172 Usb_reset_endpoint_fifo_access(EP_TEMP_OUT);
00173 data_length = Usb_byte_count(EP_TEMP_OUT);
00174 usb_read_ep_rxpacket(EP_TEMP_OUT, buf, data_length, NULL);
00175 Usb_ack_out_received_free(EP_TEMP_OUT);
00176 LED_Off(LED_APPLI_1);
00177 }
00178
00179
00180 if (data_length && Is_usb_in_ready(EP_TEMP_IN))
00181 {
00182 LED_On(LED_APPLI_0);
00183 Usb_reset_endpoint_fifo_access(EP_TEMP_IN);
00184 usb_write_ep_txpacket(EP_TEMP_IN, buf, data_length, NULL);
00185 data_length = 0;
00186 Usb_ack_in_ready_send(EP_TEMP_IN);
00187 LED_Off(LED_APPLI_0);
00188 }
00189 #ifdef FREERTOS_USED
00190 }
00191 #endif
00192 }
00193
00194
00202 void usb_sof_action(void)
00203 {
00204 sof_cnt++;
00205 }
00206
00207
00208 #endif // USB_DEVICE_FEATURE == ENABLED