This file manages the USB high-level applicative device task.
Definition in file device_template_task.c.
#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "device_template_task.h"
Go to the source code of this file.
Defines | |
#define | LED_APPLI_0 LED2 |
#define | LED_APPLI_1 LED3 |
Functions | |
void | device_template_task (void *pvParameters) |
Entry point of the device applicative task management. | |
void | device_template_task_init (void) |
This function initializes the hardware/software resources required for device applicative task. | |
void | usb_sof_action (void) |
usb_sof_action | |
Variables | |
static U8 | data_length |
static U16 | sof_cnt |
#define LED_APPLI_0 LED2 |
Definition at line 75 of file device_template_task.c.
Referenced by device_template_task(), and host_template_task().
#define LED_APPLI_1 LED3 |
Definition at line 76 of file device_template_task.c.
Referenced by device_template_task(), host_send_data_callback(), and host_template_task().
void device_template_task | ( | void * | pvParameters | ) |
Entry point of the device applicative task management.
This function links the device application to the USB bus.
Definition at line 125 of file device_template_task.c.
References buf, configTSK_USB_DTP_PERIOD, data_length, EP_SIZE_TEMP2, EP_TEMP_IN, EP_TEMP_OUT, Is_device_enumerated, Is_usb_in_ready, Is_usb_out_received, LED_APPLI_0, LED_APPLI_1, sof_cnt, Usb_ack_in_ready_send, Usb_ack_out_received_free, Usb_byte_count, usb_read_ep_rxpacket(), Usb_reset_endpoint_fifo_access, and usb_write_ep_txpacket().
Referenced by device_template_task_init(), and main().
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 // First, check the device enumeration state 00141 if (!Is_device_enumerated()) continue; 00142 #else 00143 // First, check the device enumeration state 00144 if (!Is_device_enumerated()) return; 00145 #endif // FREERTOS_USED 00146 00147 // HERE STARTS THE USB DEVICE APPLICATIVE CODE 00148 // The example below just performs a loopback transmission/reception. 00149 // All data received with the OUT endpoint is stored in a RAM buffer and 00150 // sent back to the IN endpoint. 00151 00152 #if BOARD == EVK1100 00153 // For example, display Start-of-Frame counter on LEDs 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 // For example, display Start-of-Frame counter on LEDs 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 // If we receive something in the OUT endpoint, just store it in the RAM buffer 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 // Load the IN endpoint with the contents of the RAM buffer 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 }
void device_template_task_init | ( | void | ) |
This function initializes the hardware/software resources required for device applicative task.
Definition at line 94 of file device_template_task.c.
References configTSK_USB_DTP_NAME, configTSK_USB_DTP_PRIORITY, configTSK_USB_DTP_STACK_SIZE, data_length, device_template_task(), Is_usb_device, sof_cnt, and Usb_enable_sof_interrupt.
Referenced by main().
00095 { 00096 sof_cnt = 0; 00097 data_length = 0; 00098 #ifndef FREERTOS_USED 00099 #if USB_HOST_FEATURE == ENABLED 00100 // If both device and host features are enabled, check if device mode is engaged 00101 // (accessing the USB registers of a non-engaged mode, even with load operations, 00102 // may corrupt USB FIFO data). 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 }
U8 data_length [static] |
Definition at line 88 of file device_template_task.c.
Referenced by device_template_task(), device_template_task_init(), and host_transfer_control().
U16 sof_cnt [static] |
Definition at line 87 of file device_template_task.c.