A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Thu Dec 14 20:55:40 2017 +0000
Revision:
59:e0e556c8bd46
Added buffer length to help avoid over runs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 59:e0e556c8bd46 1 #include "mbed.h"
andrewboyson 59:e0e556c8bd46 2 #include "io.h"
andrewboyson 59:e0e556c8bd46 3 #include "log.h"
andrewboyson 59:e0e556c8bd46 4 #include "eth.h"
andrewboyson 59:e0e556c8bd46 5 #include "action.h"
andrewboyson 59:e0e556c8bd46 6 #include "mac.h"
andrewboyson 59:e0e556c8bd46 7 #include "net.h"
andrewboyson 59:e0e556c8bd46 8 #include "link.h"
andrewboyson 59:e0e556c8bd46 9 #include "nic.h"
andrewboyson 59:e0e556c8bd46 10
andrewboyson 59:e0e556c8bd46 11 DigitalIn phyLinkNeg (P1_25);
andrewboyson 59:e0e556c8bd46 12 DigitalIn phySpeedNeg(P1_26);
andrewboyson 59:e0e556c8bd46 13
andrewboyson 59:e0e556c8bd46 14 bool LinkTrace = false;
andrewboyson 59:e0e556c8bd46 15
andrewboyson 59:e0e556c8bd46 16 static int count = 0;
andrewboyson 59:e0e556c8bd46 17 static void lights()
andrewboyson 59:e0e556c8bd46 18 {
andrewboyson 59:e0e556c8bd46 19 if (count)
andrewboyson 59:e0e556c8bd46 20 {
andrewboyson 59:e0e556c8bd46 21 IoEthLedGrL = false;
andrewboyson 59:e0e556c8bd46 22 IoEthLedYeR = false;
andrewboyson 59:e0e556c8bd46 23 count--;
andrewboyson 59:e0e556c8bd46 24 }
andrewboyson 59:e0e556c8bd46 25 else
andrewboyson 59:e0e556c8bd46 26 {
andrewboyson 59:e0e556c8bd46 27 IoEthLedGrL = !phyLinkNeg;
andrewboyson 59:e0e556c8bd46 28 IoEthLedYeR = !phySpeedNeg;
andrewboyson 59:e0e556c8bd46 29 }
andrewboyson 59:e0e556c8bd46 30 }
andrewboyson 59:e0e556c8bd46 31 static void lightsBlink()
andrewboyson 59:e0e556c8bd46 32 {
andrewboyson 59:e0e556c8bd46 33 count = 500; //==50ms at 100ns per scan
andrewboyson 59:e0e556c8bd46 34 }
andrewboyson 59:e0e556c8bd46 35 void LinkMain()
andrewboyson 59:e0e556c8bd46 36 {
andrewboyson 59:e0e556c8bd46 37 //Flash lights
andrewboyson 59:e0e556c8bd46 38 lights();
andrewboyson 59:e0e556c8bd46 39
andrewboyson 59:e0e556c8bd46 40 if (!NicLinkIsUp()) return;
andrewboyson 59:e0e556c8bd46 41
andrewboyson 59:e0e556c8bd46 42 //Handle packets
andrewboyson 59:e0e556c8bd46 43 int sizeRx;
andrewboyson 59:e0e556c8bd46 44 int sizeTx;
andrewboyson 59:e0e556c8bd46 45 char* pRx = NicGetReceivedPacketOrNull(&sizeRx);
andrewboyson 59:e0e556c8bd46 46 char* pTx = NicGetTransmitPacketOrNull(&sizeTx);
andrewboyson 59:e0e556c8bd46 47
andrewboyson 59:e0e556c8bd46 48 int action = DO_NOTHING;
andrewboyson 59:e0e556c8bd46 49
andrewboyson 59:e0e556c8bd46 50 NetTraceHostResetMatched();
andrewboyson 59:e0e556c8bd46 51
andrewboyson 59:e0e556c8bd46 52 if (pRx)
andrewboyson 59:e0e556c8bd46 53 {
andrewboyson 59:e0e556c8bd46 54 lightsBlink();
andrewboyson 59:e0e556c8bd46 55
andrewboyson 59:e0e556c8bd46 56 if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 57
andrewboyson 59:e0e556c8bd46 58 NicReleaseReceivedPacket();
andrewboyson 59:e0e556c8bd46 59 }
andrewboyson 59:e0e556c8bd46 60 if (pTx)
andrewboyson 59:e0e556c8bd46 61 {
andrewboyson 59:e0e556c8bd46 62 if (!action) action = EthPollForPacketToSend(pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 63
andrewboyson 59:e0e556c8bd46 64 if ( action)
andrewboyson 59:e0e556c8bd46 65 {
andrewboyson 59:e0e556c8bd46 66 lightsBlink();
andrewboyson 59:e0e556c8bd46 67 NicSendTransmitPacket(sizeTx);
andrewboyson 59:e0e556c8bd46 68 }
andrewboyson 59:e0e556c8bd46 69 }
andrewboyson 59:e0e556c8bd46 70 }
andrewboyson 59:e0e556c8bd46 71
andrewboyson 59:e0e556c8bd46 72 void LinkInit()
andrewboyson 59:e0e556c8bd46 73 {
andrewboyson 59:e0e556c8bd46 74 phyLinkNeg.mode(PullUp);
andrewboyson 59:e0e556c8bd46 75 phySpeedNeg.mode(PullUp);
andrewboyson 59:e0e556c8bd46 76 NicInit();
andrewboyson 59:e0e556c8bd46 77 NicLinkAddress(MacLocal);
andrewboyson 59:e0e556c8bd46 78 if (LinkTrace)
andrewboyson 59:e0e556c8bd46 79 {
andrewboyson 59:e0e556c8bd46 80 Log("\r\n");
andrewboyson 59:e0e556c8bd46 81 LogTime("MAC: ");
andrewboyson 59:e0e556c8bd46 82 MacLog(MacLocal);
andrewboyson 59:e0e556c8bd46 83 Log("\r\n");
andrewboyson 59:e0e556c8bd46 84 }
andrewboyson 59:e0e556c8bd46 85 }