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:
Sun Nov 18 12:13:15 2018 +0000
Revision:
86:55bc5ddac16c
Parent:
85:cd9fdd6ab7e3
Child:
97:d91f7db00235
Hard fault is coming from Tcp4handler. Moved Leds to keep tracking it down.

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 59:e0e556c8bd46 12
andrewboyson 70:74c11fb71a15 13 #define LINK_PIN FIO1PIN(25)
andrewboyson 70:74c11fb71a15 14 #define SPEED_PIN FIO1PIN(26)
andrewboyson 59:e0e556c8bd46 15
andrewboyson 59:e0e556c8bd46 16 bool LinkTrace = false;
andrewboyson 59:e0e556c8bd46 17
andrewboyson 63:9d67a5eaa93c 18 bool LinkPhyLink = false;
andrewboyson 63:9d67a5eaa93c 19 bool LinkPhySpeed = false;
andrewboyson 63:9d67a5eaa93c 20 bool LinkActivity = false;
andrewboyson 63:9d67a5eaa93c 21
andrewboyson 59:e0e556c8bd46 22 void LinkMain()
andrewboyson 59:e0e556c8bd46 23 {
andrewboyson 59:e0e556c8bd46 24 //Flash lights
andrewboyson 70:74c11fb71a15 25 LinkPhyLink = ! LINK_PIN;
andrewboyson 70:74c11fb71a15 26 LinkPhySpeed = !SPEED_PIN;
andrewboyson 59:e0e556c8bd46 27
andrewboyson 59:e0e556c8bd46 28 if (!NicLinkIsUp()) return;
andrewboyson 59:e0e556c8bd46 29
andrewboyson 59:e0e556c8bd46 30 //Handle packets
andrewboyson 59:e0e556c8bd46 31 int sizeRx;
andrewboyson 59:e0e556c8bd46 32 int sizeTx;
andrewboyson 59:e0e556c8bd46 33 char* pRx = NicGetReceivedPacketOrNull(&sizeRx);
andrewboyson 59:e0e556c8bd46 34 char* pTx = NicGetTransmitPacketOrNull(&sizeTx);
andrewboyson 59:e0e556c8bd46 35
andrewboyson 59:e0e556c8bd46 36 int action = DO_NOTHING;
andrewboyson 59:e0e556c8bd46 37
andrewboyson 59:e0e556c8bd46 38 NetTraceHostResetMatched();
andrewboyson 59:e0e556c8bd46 39
andrewboyson 63:9d67a5eaa93c 40 LinkActivity = false;
andrewboyson 85:cd9fdd6ab7e3 41
andrewboyson 59:e0e556c8bd46 42 if (pRx)
andrewboyson 59:e0e556c8bd46 43 {
andrewboyson 63:9d67a5eaa93c 44 LinkActivity = true;
andrewboyson 59:e0e556c8bd46 45
andrewboyson 59:e0e556c8bd46 46 if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 47
andrewboyson 59:e0e556c8bd46 48 NicReleaseReceivedPacket();
andrewboyson 59:e0e556c8bd46 49 }
andrewboyson 85:cd9fdd6ab7e3 50
andrewboyson 59:e0e556c8bd46 51 if (pTx)
andrewboyson 59:e0e556c8bd46 52 {
andrewboyson 59:e0e556c8bd46 53 if (!action) action = EthPollForPacketToSend(pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 54
andrewboyson 59:e0e556c8bd46 55 if ( action)
andrewboyson 59:e0e556c8bd46 56 {
andrewboyson 63:9d67a5eaa93c 57 LinkActivity = true;
andrewboyson 59:e0e556c8bd46 58 NicSendTransmitPacket(sizeTx);
andrewboyson 59:e0e556c8bd46 59 }
andrewboyson 59:e0e556c8bd46 60 }
andrewboyson 59:e0e556c8bd46 61 }
andrewboyson 59:e0e556c8bd46 62
andrewboyson 59:e0e556c8bd46 63 void LinkInit()
andrewboyson 59:e0e556c8bd46 64 {
andrewboyson 59:e0e556c8bd46 65 NicInit();
andrewboyson 59:e0e556c8bd46 66 NicLinkAddress(MacLocal);
andrewboyson 59:e0e556c8bd46 67 if (LinkTrace)
andrewboyson 59:e0e556c8bd46 68 {
andrewboyson 59:e0e556c8bd46 69 Log("\r\n");
andrewboyson 59:e0e556c8bd46 70 LogTime("MAC: ");
andrewboyson 59:e0e556c8bd46 71 MacLog(MacLocal);
andrewboyson 59:e0e556c8bd46 72 Log("\r\n");
andrewboyson 59:e0e556c8bd46 73 }
andrewboyson 59:e0e556c8bd46 74 }