1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| void device_template_task(void)
#endif
{
static U8 buf[EP_SIZE_TEMP2];
#ifdef FREERTOS_USED
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
while (true)
{
vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DTP_PERIOD);
// First, check the device enumeration state
if (!Is_device_enumerated()) continue;
#else
// First, check the device enumeration state
if (!Is_device_enumerated()) return;
#endif // FREERTOS_USED
// HERE STARTS THE USB DEVICE APPLICATIVE CODE
// The example below just performs a loopback transmission/reception.
// All data received with the OUT endpoint is stored in a RAM buffer and
// sent back to the IN endpoint.
#if BOARD == EVK1100
// For example, display Start-of-Frame counter on LEDs
LED_Display_Field(LED_MONO0_GREEN |
LED_MONO1_GREEN |
LED_MONO2_GREEN |
LED_MONO3_GREEN,
sof_cnt >> 5);
#elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105
// For example, display Start-of-Frame counter on LEDs
LED_Display_Field(LED0 |
LED1,
sof_cnt >> 5);
#else
#error The display of the SOFs must be defined here.
#endif
// If we receive something in the OUT endpoint, just store it in the RAM buffer
if (Is_usb_out_received(EP_TEMP_OUT))
{
LED_On(LED_APPLI_1);
Usb_reset_endpoint_fifo_access(EP_TEMP_OUT);
data_length = Usb_byte_count(EP_TEMP_OUT);
usb_read_ep_rxpacket(EP_TEMP_OUT, buf, data_length, NULL);
Usb_ack_out_received_free(EP_TEMP_OUT);
LED_Off(LED_APPLI_1);
}
// Load the IN endpoint with the contents of the RAM buffer
if (data_length && Is_usb_in_ready(EP_TEMP_IN))
{
LED_On(LED_APPLI_0);
Usb_reset_endpoint_fifo_access(EP_TEMP_IN);
usb_write_ep_txpacket(EP_TEMP_IN, buf, data_length, NULL);
data_length = 0;
Usb_ack_in_ready_send(EP_TEMP_IN);
LED_Off(LED_APPLI_0);
}
#ifdef FREERTOS_USED
}
#endif
} |