Add missing SVN eol-style property to files where it was missing.
[pub/USBasp.git] / Demos / Device / ClassDriver / RNDISEthernet / RNDISEthernet.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Main source file for the RNDISEthernet demo. This file contains the main tasks of
34 * the demo and is responsible for the initial application hardware configuration.
35 */
36
37 #include "RNDISEthernet.h"
38
39 /** LUFA RNDIS Class driver interface configuration and state information. This structure is
40 * passed to all RNDIS Class driver functions, so that multiple instances of the same class
41 * within a device can be differentiated from one another.
42 */
43 USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
44 {
45 .Config =
46 {
47 .ControlInterfaceNumber = 0,
48
49 .DataINEndpointNumber = CDC_TX_EPNUM,
50 .DataINEndpointSize = CDC_TXRX_EPSIZE,
51 .DataINEndpointDoubleBank = false,
52
53 .DataOUTEndpointNumber = CDC_RX_EPNUM,
54 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
55 .DataOUTEndpointDoubleBank = false,
56
57 .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,
58 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
59 .NotificationEndpointDoubleBank = false,
60
61 .AdapterVendorDescription = "LUFA RNDIS Demo Adapter",
62 .AdapterMACAddress = {ADAPTER_MAC_ADDRESS},
63 },
64 };
65
66
67 /** Main program entry point. This routine contains the overall program flow, including initial
68 * setup of all components and the main program loop.
69 */
70 int main(void)
71 {
72 SetupHardware();
73
74 TCP_Init();
75 Webserver_Init();
76
77 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
78 sei();
79
80 for (;;)
81 {
82 if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
83 {
84 LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
85 Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
86 LEDs_SetAllLEDs(LEDMASK_USB_READY);
87 }
88
89 TCP_TCPTask(&Ethernet_RNDIS_Interface);
90
91 RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
92 USB_USBTask();
93 }
94 }
95
96 /** Configures the board hardware and chip peripherals for the demo's functionality. */
97 void SetupHardware(void)
98 {
99 /* Disable watchdog if enabled by bootloader/fuses */
100 MCUSR &= ~(1 << WDRF);
101 wdt_disable();
102
103 /* Disable clock division */
104 clock_prescale_set(clock_div_1);
105
106 /* Hardware Initialization */
107 LEDs_Init();
108 Serial_Init(9600, false);
109 USB_Init();
110
111 /* Create a stdio stream for the serial port for stdin and stdout */
112 Serial_CreateStream(NULL);
113 }
114
115 /** Event handler for the library USB Connection event. */
116 void EVENT_USB_Device_Connect(void)
117 {
118 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
119 }
120
121 /** Event handler for the library USB Disconnection event. */
122 void EVENT_USB_Device_Disconnect(void)
123 {
124 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
125 }
126
127 /** Event handler for the library USB Configuration Changed event. */
128 void EVENT_USB_Device_ConfigurationChanged(void)
129 {
130 bool ConfigSuccess = true;
131
132 ConfigSuccess &= RNDIS_Device_ConfigureEndpoints(&Ethernet_RNDIS_Interface);
133
134 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
135 }
136
137 /** Event handler for the library USB Control Request reception event. */
138 void EVENT_USB_Device_ControlRequest(void)
139 {
140 RNDIS_Device_ProcessControlRequest(&Ethernet_RNDIS_Interface);
141 }
142