void Network::Spin() { if (active) { // ++inLwip; ethernet_task(); // keep the Ethernet running // --inLwip; // See if we can send anything RequestState* r = writingTransactions; if (r != NULL) { bool finished = r->Send(); // Disable interrupts while we mess around with the lists in case we get a callback from a network ISR irqflags_t flags = cpu_irq_save(); writingTransactions = r->next; if (finished) { RequestState *rn = r->nextWrite; r->nextWrite = NULL; HttpState *hs = r->hs; AppendTransaction(&freeTransactions, r); if (rn != NULL) { if (hs != NULL) { hs->sendingRs = (rn->hs == hs) ? rn : NULL; } AppendTransaction(&writingTransactions, rn); } else if (hs != NULL) { hs->sendingRs = NULL; } } else { AppendTransaction(&writingTransactions, r); } cpu_irq_restore(flags); } } else if (establish_ethernet_link()) { start_ethernet(reprap.GetPlatform()->IPAddress(), reprap.GetPlatform()->NetMask(), reprap.GetPlatform()->GateWay()); httpd_init(); active = true; } }
void Network::Spin() { // Basically we can't do anything if we can't interact with LWIP if (!LockLWIP()) { platform->ClassReport(longWait); return; } if (state == NetworkActive) { // See if we can read any packets if (readingData) { readingData = false; do { // read all queued packets from the RX buffer } while (ethernet_read()); ethernet_set_rx_callback(&emac_read_packet); } // See if we can send anything NetworkTransaction *r = writingTransactions; if (r != NULL && r->Send()) { // We're done, free up this transaction ConnectionState *cs = r->cs; NetworkTransaction *rn = r->nextWrite; writingTransactions = r->next; AppendTransaction(&freeTransactions, r); // If there is more data to write on this connection, do it next time if (cs != NULL) { cs->sendingTransaction = rn; } if (rn != NULL) { PrependTransaction(&writingTransactions, rn); } } } else if (state == NetworkInitializing && establish_ethernet_link()) { start_ethernet(platform->IPAddress(), platform->NetMask(), platform->GateWay()); ethernet_set_rx_callback(&emac_read_packet); httpd_init(); ftpd_init(); telnetd_init(); netbios_init(); state = NetworkActive; } UnlockLWIP(); platform->ClassReport(longWait); }