PROCESS_THREAD(network_process, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_PAUSE(); uip_len = enc28j60_read(uip_buf, UIP_BUFSIZE); if (uip_len > 0) { HAL_IWDG_Refresh(&hiwdg); struct uip_eth_hdr *header = ((struct uip_eth_hdr *)&uip_buf[0]); uint16_t packetType = header->type; #ifdef ENC28J60_DEBUG printf("?receivePacket: len: %d, dest: %02x:%02x:%02x:%02x:%02x:%02x, src: %02x:%02x:%02x:%02x:%02x:%02x, type: %d\n", uip_len, header->dest.addr[0], header->dest.addr[1], header->dest.addr[2], header->dest.addr[3], header->dest.addr[4], header->dest.addr[5], header->src.addr[0], header->src.addr[1], header->src.addr[2], header->src.addr[3], header->src.addr[4], header->src.addr[5], packetType ); for (int i = 0; i < uip_len; i++) { printf("%02x ", uip_buf[i]); } printf("\n"); #endif if (packetType == UIP_HTONS(UIP_ETHTYPE_IP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type IP\n"); #endif uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); enc28j60_send(uip_buf, uip_len + sizeof(struct uip_eth_hdr)); } } else if (packetType == UIP_HTONS(UIP_ETHTYPE_ARP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type ARP\n"); #endif uip_arp_arpin(); if (uip_len > 0) { enc28j60_send(uip_buf, uip_len + sizeof(struct uip_eth_hdr)); } } } } PROCESS_END(); }
void eth_drv_send(uint8_t *packet, uint16_t len) { LOG6LBR_PRINTF(PACKET, ETH_OUT, "write: %d\n", len); LOG6LBR_DUMP_PACKET(ETH_OUT, packet, len); enc28j60_send(packet, len); }
int puts(const char* str) { enc28j60_send(str, strlen(str)); return 0; }
uint8_t enc28j60_tcp_output() { uip_arp_out(); enc28j60_send(uip_buf, uip_len + sizeof(struct uip_eth_hdr)); return 0; }
void enc28j60_tick(ENC28J60 *enc28j60) { uip_len = _enc28j60_receivePacket(enc28j60, ((uint8_t *)uip_buf), UIP_BUFSIZE); if (uip_len > 0) { struct uip_eth_hdr *header = ((struct uip_eth_hdr *)&uip_buf[0]); uint16_t packetType = header->type; #ifdef ENC28J60_DEBUG printf("?receivePacket: len: %d, dest: %d.%d.%d.%d, src: %d.%d.%d.%d, type: %d\n", uip_len, header->dest.u8[0], header->dest.u8[1], header->dest.u8[2], header->dest.u8[3], header->src.u8[0], header->src.u8[1], header->src.u8[2], header->src.u8[3], packetType ); for (int i = 0; i < uip_len; i++) { printf("%02x ", uip_buf[i]); } printf("\n"); #endif if (packetType == UIP_HTONS(UIP_ETHTYPE_IP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type IP\n"); #endif uip_arp_ipin(); uip_input(); if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } else if (packetType == UIP_HTONS(UIP_ETHTYPE_ARP)) { #ifdef ENC28J60_DEBUG printf("?readPacket type ARP\n"); #endif uip_arp_arpin(); if (uip_len > 0) { enc28j60_send(enc28j60); } } } if (timer_expired(&enc28j60->_enc28j60_periodicTimer)) { timer_restart(&enc28j60->_enc28j60_periodicTimer); for (int i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // If the above function invocation resulted in data that // should be sent out on the Enc28J60Network, the global variable // uip_len is set to a value > 0. if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } #if UIP_UDP for (int i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); // If the above function invocation resulted in data that // should be sent out on the Enc28J60Network, the global variable // uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); enc28j60_send(enc28j60); } } #endif /* UIP_UDP */ } }
/*---------------------------------------------------------------------------*/ static int output(uint8_t *packet, uint16_t len) { enc28j60_send(packet, len); return len; }