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
Diff: link/link.c
- Revision:
- 98:b977424ec7f7
- Parent:
- 97:d91f7db00235
- Child:
- 122:402d148f85d3
diff -r d91f7db00235 -r b977424ec7f7 link/link.c --- a/link/link.c Wed Jan 02 17:48:38 2019 +0000 +++ b/link/link.c Thu Jan 03 17:23:38 2019 +0000 @@ -10,45 +10,39 @@ #include "nic.h" #include "led.h" #include "fault.h" +#include "jack.h" #define LINK_PIN FIO1PIN(25) #define SPEED_PIN FIO1PIN(26) bool LinkTrace = false; -bool LinkPhyLink = false; -bool LinkPhySpeed = false; -bool LinkActivity = false; - void LinkMain() { + int lastFaultPoint = FaultPoint; FaultPoint = FAULT_POINT_LinkMain; - //Flash lights - LinkPhyLink = ! LINK_PIN; - LinkPhySpeed = !SPEED_PIN; - + //Wait until the network is up if (!NicLinkIsUp()) { - FaultPoint = 0; + FaultPoint = lastFaultPoint; return; } + //Reset the trace of host at the very start + NetTraceHostResetMatched(); + //Handle packets int sizeRx; int sizeTx; char* pRx = NicGetReceivedPacketOrNull(&sizeRx); char* pTx = NicGetTransmitPacketOrNull(&sizeTx); - int action = DO_NOTHING; - - NetTraceHostResetMatched(); - - LinkActivity = false; - + int action = DO_NOTHING; + bool activity = false; if (pRx) { - LinkActivity = true; + activity = true; if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx); @@ -61,15 +55,21 @@ if ( action) { - LinkActivity = true; + activity = true; NicSendTransmitPacket(sizeTx); } } - FaultPoint = 0; + + //Flash lights + JackLeds(!LINK_PIN, !SPEED_PIN, activity); + + //Finish + FaultPoint = lastFaultPoint; } void LinkInit() { + JackInit(); NicInit(); NicLinkAddress(MacLocal); if (LinkTrace)