simple reliable networking over ethernet. Provides IPv4 ARP, ICMP echo reply, and UDP unicast. Does NOT provide TCP, that's not simple :-).
Diff: snet.cpp
- Revision:
- 1:9c211ac06a12
- Parent:
- 0:6df0a6ed91d4
- Child:
- 2:397316d97354
--- a/snet.cpp Wed Mar 04 02:04:32 2015 +0000 +++ b/snet.cpp Thu Mar 05 00:18:25 2015 +0000 @@ -7,19 +7,10 @@ //volatile uint32_t enet_rx_cnt; //volatile int enet_rx_balance; -extern uint8_t my_ip[4]; - - -//uint8_t correspondent_mac[6]; // correspondent's MAC const uint8_t Snet::broadcast_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -//const char ourEtherType[] = { 0x82, 0x48 }; const uint8_t Snet::ipEtherType[] = { 0x08, 0x00 }; const uint8_t Snet::arp_req_payload_prefix[] = { 0x0, 0x1, 0x8, 0x0, 0x6, 0x4, 0x0, 0x1 }; -extern void interpret_inet_packet(uint8_t *buf, int len); -extern void send_packet_to_radio(uint8_t const *, int); - - Snet::Snet(): eth() { @@ -27,19 +18,6 @@ printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\r\n", my_mac[0], my_mac[1], my_mac[2], my_mac[3], my_mac[4], my_mac[5]); printf("no IP\r\n"); -#if 0 // FIXME - LPC_EMAC->IntEnable = 0; // disable all Ethernet interrupts - LPC_EMAC->IntClear = ~0; // clear all interrupts - - //enet_rx_balance = 0; - // Enable Ethernet TX and RX Packet Interrupts: - //LPC_EMAC->IntEnable |= (ETH_RxFinishedInt | ETH_TxFinishedInt); - LPC_EMAC->IntEnable |= (ETH_RxDoneInt | ETH_TxDoneInt); - NVIC_SetPriority(ENET_IRQn, 0); // lower numbers have priority - - // Enable the interrupt. - NVIC_EnableIRQ(ENET_IRQn); -#endif } Snet::Snet(const uint8_t *ip): eth() @@ -50,23 +28,8 @@ memcpy(my_ip, ip, 4); printf("IP %d.%d.%d.%d\r\n", my_ip[0], my_ip[1], my_ip[2], my_ip[3]); -#if 0 // FIXME - LPC_EMAC->IntEnable = 0; // disable all Ethernet interrupts - LPC_EMAC->IntClear = ~0; // clear all interrupts - - //enet_rx_balance = 0; - // Enable Ethernet TX and RX Packet Interrupts: - //LPC_EMAC->IntEnable |= (ETH_RxFinishedInt | ETH_TxFinishedInt); - LPC_EMAC->IntEnable |= (ETH_RxDoneInt | ETH_TxDoneInt); - NVIC_SetPriority(ENET_IRQn, 0); // lower numbers have priority - - // Enable the interrupt. - NVIC_EnableIRQ(ENET_IRQn); -#endif } - - void Snet::handle_arp_request(uint8_t *buf, int len) { #if 0 printf("Arp from %02x:%02x:%02x:%02x:%02x:%02x ", @@ -118,9 +81,9 @@ interpret_inet_packet(buf, len); } -int Snet::rx_and_process_one_packet() { +int Snet::rx_and_process_available_packets() { #if 0 - // if the damn Ethernet worked correctly: + // if the MBED Ethernet worked correctly: uint8_t buf[0x600]; #else uint8_t buf[750+6+6+2]; // Experimentally-derived maximum packet size is 750 at the IP layer