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:
Wed Jan 02 17:48:38 2019 +0000
Revision:
97:d91f7db00235
Parent:
86:55bc5ddac16c
Child:
98:b977424ec7f7
Added fault points

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 61:aad055f1b0d1 1 #include <stdbool.h>
andrewboyson 61:aad055f1b0d1 2
andrewboyson 70:74c11fb71a15 3 #include "gpio.h"
andrewboyson 59:e0e556c8bd46 4 #include "log.h"
andrewboyson 59:e0e556c8bd46 5 #include "eth.h"
andrewboyson 59:e0e556c8bd46 6 #include "action.h"
andrewboyson 59:e0e556c8bd46 7 #include "mac.h"
andrewboyson 59:e0e556c8bd46 8 #include "net.h"
andrewboyson 59:e0e556c8bd46 9 #include "link.h"
andrewboyson 59:e0e556c8bd46 10 #include "nic.h"
andrewboyson 85:cd9fdd6ab7e3 11 #include "led.h"
andrewboyson 97:d91f7db00235 12 #include "fault.h"
andrewboyson 59:e0e556c8bd46 13
andrewboyson 70:74c11fb71a15 14 #define LINK_PIN FIO1PIN(25)
andrewboyson 70:74c11fb71a15 15 #define SPEED_PIN FIO1PIN(26)
andrewboyson 59:e0e556c8bd46 16
andrewboyson 59:e0e556c8bd46 17 bool LinkTrace = false;
andrewboyson 59:e0e556c8bd46 18
andrewboyson 63:9d67a5eaa93c 19 bool LinkPhyLink = false;
andrewboyson 63:9d67a5eaa93c 20 bool LinkPhySpeed = false;
andrewboyson 63:9d67a5eaa93c 21 bool LinkActivity = false;
andrewboyson 63:9d67a5eaa93c 22
andrewboyson 59:e0e556c8bd46 23 void LinkMain()
andrewboyson 59:e0e556c8bd46 24 {
andrewboyson 97:d91f7db00235 25 FaultPoint = FAULT_POINT_LinkMain;
andrewboyson 97:d91f7db00235 26
andrewboyson 59:e0e556c8bd46 27 //Flash lights
andrewboyson 70:74c11fb71a15 28 LinkPhyLink = ! LINK_PIN;
andrewboyson 70:74c11fb71a15 29 LinkPhySpeed = !SPEED_PIN;
andrewboyson 59:e0e556c8bd46 30
andrewboyson 97:d91f7db00235 31 if (!NicLinkIsUp())
andrewboyson 97:d91f7db00235 32 {
andrewboyson 97:d91f7db00235 33 FaultPoint = 0;
andrewboyson 97:d91f7db00235 34 return;
andrewboyson 97:d91f7db00235 35 }
andrewboyson 59:e0e556c8bd46 36
andrewboyson 59:e0e556c8bd46 37 //Handle packets
andrewboyson 59:e0e556c8bd46 38 int sizeRx;
andrewboyson 59:e0e556c8bd46 39 int sizeTx;
andrewboyson 59:e0e556c8bd46 40 char* pRx = NicGetReceivedPacketOrNull(&sizeRx);
andrewboyson 59:e0e556c8bd46 41 char* pTx = NicGetTransmitPacketOrNull(&sizeTx);
andrewboyson 59:e0e556c8bd46 42
andrewboyson 59:e0e556c8bd46 43 int action = DO_NOTHING;
andrewboyson 59:e0e556c8bd46 44
andrewboyson 59:e0e556c8bd46 45 NetTraceHostResetMatched();
andrewboyson 59:e0e556c8bd46 46
andrewboyson 63:9d67a5eaa93c 47 LinkActivity = false;
andrewboyson 85:cd9fdd6ab7e3 48
andrewboyson 59:e0e556c8bd46 49 if (pRx)
andrewboyson 59:e0e556c8bd46 50 {
andrewboyson 63:9d67a5eaa93c 51 LinkActivity = true;
andrewboyson 59:e0e556c8bd46 52
andrewboyson 59:e0e556c8bd46 53 if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx);
andrewboyson 97:d91f7db00235 54
andrewboyson 59:e0e556c8bd46 55 NicReleaseReceivedPacket();
andrewboyson 59:e0e556c8bd46 56 }
andrewboyson 85:cd9fdd6ab7e3 57
andrewboyson 59:e0e556c8bd46 58 if (pTx)
andrewboyson 59:e0e556c8bd46 59 {
andrewboyson 59:e0e556c8bd46 60 if (!action) action = EthPollForPacketToSend(pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 61
andrewboyson 59:e0e556c8bd46 62 if ( action)
andrewboyson 59:e0e556c8bd46 63 {
andrewboyson 63:9d67a5eaa93c 64 LinkActivity = true;
andrewboyson 59:e0e556c8bd46 65 NicSendTransmitPacket(sizeTx);
andrewboyson 59:e0e556c8bd46 66 }
andrewboyson 59:e0e556c8bd46 67 }
andrewboyson 97:d91f7db00235 68 FaultPoint = 0;
andrewboyson 59:e0e556c8bd46 69 }
andrewboyson 59:e0e556c8bd46 70
andrewboyson 59:e0e556c8bd46 71 void LinkInit()
andrewboyson 59:e0e556c8bd46 72 {
andrewboyson 59:e0e556c8bd46 73 NicInit();
andrewboyson 59:e0e556c8bd46 74 NicLinkAddress(MacLocal);
andrewboyson 59:e0e556c8bd46 75 if (LinkTrace)
andrewboyson 59:e0e556c8bd46 76 {
andrewboyson 59:e0e556c8bd46 77 Log("\r\n");
andrewboyson 59:e0e556c8bd46 78 LogTime("MAC: ");
andrewboyson 59:e0e556c8bd46 79 MacLog(MacLocal);
andrewboyson 59:e0e556c8bd46 80 Log("\r\n");
andrewboyson 59:e0e556c8bd46 81 }
andrewboyson 59:e0e556c8bd46 82 }