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
link/link.c
- Committer:
- andrewboyson
- Date:
- 2018-11-17
- Revision:
- 85:cd9fdd6ab7e3
- Parent:
- 70:74c11fb71a15
- Child:
- 86:55bc5ddac16c
File content as of revision 85:cd9fdd6ab7e3:
#include <stdbool.h> #include "gpio.h" #include "log.h" #include "eth.h" #include "action.h" #include "mac.h" #include "net.h" #include "link.h" #include "nic.h" #include "led.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() { //Flash lights LinkPhyLink = ! LINK_PIN; LinkPhySpeed = !SPEED_PIN; if (!NicLinkIsUp()) return; //Handle packets int sizeRx; int sizeTx; char* pRx = NicGetReceivedPacketOrNull(&sizeRx); char* pTx = NicGetTransmitPacketOrNull(&sizeTx); int action = DO_NOTHING; NetTraceHostResetMatched(); LinkActivity = false; Led1Set(true); if (pRx) { LinkActivity = true; if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx); NicReleaseReceivedPacket(); } Led1Set(false); Led2Set(true); if (pTx) { if (!action) action = EthPollForPacketToSend(pTx, &sizeTx); if ( action) { LinkActivity = true; NicSendTransmitPacket(sizeTx); } } Led2Set(false); } void LinkInit() { NicInit(); NicLinkAddress(MacLocal); if (LinkTrace) { Log("\r\n"); LogTime("MAC: "); MacLog(MacLocal); Log("\r\n"); } }