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 <stdio.h>
00051 #include "usart.h"
00052
00053 #include "conf_usb.h"
00054
00055
00056 #if USB_DEVICE_FEATURE == ENABLED
00057
00058 #include "board.h"
00059 #ifdef FREERTOS_USED
00060 #include "FreeRTOS.h"
00061 #include "task.h"
00062 #endif
00063 #include "usb_drv.h"
00064 #include "gpio.h"
00065 #if BOARD == EVK1100 || BOARD == EVK1101
00066 # include "joystick.h"
00067 #endif
00068 #include "usb_descriptors.h"
00069 #include "usb_standard_request.h"
00070 #include "device_cdc_task.h"
00071 #include "uart_usb_lib.h"
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static volatile U16 sof_cnt;
00082
00083
00084
00089 void device_cdc_task_init(void)
00090 {
00091 sof_cnt =0 ;
00092 uart_usb_init();
00093
00094 #ifndef FREERTOS_USED
00095 #if USB_HOST_FEATURE == ENABLED
00096
00097
00098
00099 if (Is_usb_device())
00100 #endif // USB_HOST_FEATURE == ENABLED
00101 Usb_enable_sof_interrupt();
00102 #endif // FREERTOS_USED
00103
00104 #ifdef FREERTOS_USED
00105 xTaskCreate(device_cdc_task,
00106 configTSK_USB_DCDC_NAME,
00107 configTSK_USB_DCDC_STACK_SIZE,
00108 NULL,
00109 configTSK_USB_DCDC_PRIORITY,
00110 NULL);
00111
00112 #endif // FREERTOS_USED
00113 }
00114
00115
00119 #ifdef FREERTOS_USED
00120 void device_cdc_task(void *pvParameters)
00121 #else
00122 void device_cdc_task(void)
00123 #endif
00124 {
00125 int c;
00126 static Bool startup=TRUE;
00127
00128 #ifdef FREERTOS_USED
00129 portTickType xLastWakeTime;
00130 xLastWakeTime = xTaskGetTickCount();
00131
00132 while (TRUE)
00133 {
00134 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DCDC_PERIOD);
00135
00136
00137 if (!Is_device_enumerated()) continue;
00138 #else
00139
00140 if (!Is_device_enumerated()) return;
00141 #endif // FREERTOS_USED
00142
00143 if( startup )
00144 {
00145 printf("\r\nUSB DEVICE Communications Device Class demo.\r\n");
00146 startup=FALSE;
00147 }
00148
00149 if( sof_cnt>=NB_MS_BEFORE_FLUSH )
00150 {
00151 sof_cnt=0;
00152 uart_usb_flush();
00153 }
00154
00155 #if BOARD == EVK1100 || BOARD == EVK1101
00156 if ( is_joystick_right() )
00157 printf("Joystick Right key pressed.\r\n");
00158
00159 if ( is_joystick_left() )
00160 printf("Joystick Left key pressed.\r\n");
00161
00162 if ( is_joystick_down() )
00163 printf("Joystick Down key pressed.\r\n");
00164
00165 if ( is_joystick_up() )
00166 printf("Joystick Up key pressed.\r\n");
00167
00168 if ( is_joystick_pressed() )
00169 printf("Joystick Select key pressed.\r\n");
00170 #endif
00171 #if BOARD == EVK1100 || BOARD == EVK1101 || BOARD == UC3C_EK
00172 if (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0))
00173 printf("Button 0 key pressed.\r\n");
00174
00175 if (!gpio_get_pin_value(GPIO_PUSH_BUTTON_1))
00176 printf("Button 1 key pressed.\r\n");
00177 #endif
00178
00179 if (usart_test_hit(DBG_USART))
00180 {
00181 if( uart_usb_tx_ready() )
00182 {
00183 if( USART_SUCCESS==usart_read_char(DBG_USART, &c) )
00184 {
00185 uart_usb_putchar(c);
00186 LED_Toggle(LED0);
00187 }
00188 else {
00189 usart_reset_status( DBG_USART );
00190 }
00191 }
00192 }
00193
00194 if (uart_usb_test_hit())
00195 {
00196 if (usart_tx_ready(DBG_USART))
00197 {
00198 c= uart_usb_getchar();
00199 usart_write_char(DBG_USART, c);
00200 LED_Toggle(LED1);
00201 }
00202 }
00203 #ifdef FREERTOS_USED
00204 }
00205 #endif
00206 }
00207
00208
00216 void usb_sof_action(void)
00217 {
00218 sof_cnt++;
00219 }
00220
00221 #endif // USB_DEVICE_FEATURE == ENABLED