9 #include "sicslow_ethernet.h"
12 #include <avr/pgmspace.h>
13 #include <util/delay.h>
15 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
17 #define PRINTF_P printf_P
25 #define EEMCMD_ECHO 0x00
26 #define EEMCMD_ECHO_RESPONSE 0x01
27 #define EEMCMD_SUSPEND_HINT 0x02
28 #define EEMCMD_RESPONSE_HINT 0x03
29 #define EEMCMD_RESPONSE_COMPLETE_HINT 0x04
30 #define EEMCMD_TICKLE 0x05
33 void cdc_eem_configure_endpoints() {
34 usb_configure_endpoint(TX_EP, \
41 usb_configure_endpoint(RX_EP, \
51 void cdc_eem_process(
void) {
53 uint8_t bytecounter, headercounter;
56 #ifdef USB_ETH_HOOK_INIT
57 static uint8_t doInit = 1;
81 if (bytecounter < headercounter) {
88 while (headercounter) {
107 if ((datalength == 0) && (fail == 0))
114 command = command >> 3;
131 case EEMCMD_ECHO_RESPONSE:
132 case EEMCMD_SUSPEND_HINT:
133 case EEMCMD_RESPONSE_HINT:
134 case EEMCMD_RESPONSE_COMPLETE_HINT:
142 else if (datalength && (fail == 0))
145 #ifdef USB_ETH_HOOK_RX_START
146 USB_ETH_HOOK_RX_START();
149 uint16_t bytes_received = 0;
150 uint16_t dataleft = datalength;
151 U8 * buffer = uip_buf;
162 if ((bytecounter == 0) && (dataleft))
174 if (bytecounter == 0)
185 #ifdef USB_ETH_HOOK_RX_END
186 USB_ETH_HOOK_RX_END();
193 if(datalength <= USB_ETH_MTU) {
194 USB_ETH_HOOK_HANDLE_INBOUND_PACKET(uip_buf,datalength);
196 USB_ETH_HOOK_RX_ERROR(
"Oversized packet");
206 uint8_t eem_send(uint8_t * senddata, uint16_t sendlen, uint8_t led)
213 header[0] = (sendlen >> 8) & 0x3f;
214 header[1] = sendlen & 0xff;
224 if(usb_endpoint_wait_for_write_enabled()!=0) {
225 USB_ETH_HOOK_TX_ERROR(
"Timeout: write enabled");
229 #ifdef USB_ETH_HOOK_TX_START
230 USB_ETH_HOOK_TX_START();
248 if(usb_endpoint_wait_for_write_enabled()!=0) {
249 USB_ETH_HOOK_TX_ERROR(
"Timeout: write enabled");
260 uint8_t crc[4] = {0xde, 0xad, 0xbe, 0xef};
275 if(usb_endpoint_wait_for_write_enabled()!=0) {
276 USB_ETH_HOOK_TX_ERROR(
"Timeout: write enabled");
285 #ifdef USB_ETH_HOOK_TX_END
286 USB_ETH_HOOK_TX_END();
290 if(usb_endpoint_wait_for_IN_ready()!=0) {
291 USB_ETH_HOOK_TX_ERROR(
"Timeout: IN ready");