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:
Fri Jul 19 17:48:06 2019 +0000
Revision:
151:bde6f7da1755
Parent:
142:a8c0890a58d1
Removed private key and certificate from semihost storage as found to be unreliable (though secure) and moved it into flash storage (reliable, simple, but visible on mbed.

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 142:a8c0890a58d1 12 #include "restart.h"
andrewboyson 98:b977424ec7f7 13 #include "jack.h"
andrewboyson 59:e0e556c8bd46 14
andrewboyson 70:74c11fb71a15 15 #define LINK_PIN FIO1PIN(25)
andrewboyson 70:74c11fb71a15 16 #define SPEED_PIN FIO1PIN(26)
andrewboyson 59:e0e556c8bd46 17
andrewboyson 59:e0e556c8bd46 18 bool LinkTrace = false;
andrewboyson 59:e0e556c8bd46 19
andrewboyson 59:e0e556c8bd46 20 void LinkMain()
andrewboyson 59:e0e556c8bd46 21 {
andrewboyson 142:a8c0890a58d1 22 int lastRestartPoint = RestartPoint;
andrewboyson 142:a8c0890a58d1 23 RestartPoint = FAULT_POINT_LinkMain;
andrewboyson 97:d91f7db00235 24
andrewboyson 98:b977424ec7f7 25 //Wait until the network is up
andrewboyson 97:d91f7db00235 26 if (!NicLinkIsUp())
andrewboyson 97:d91f7db00235 27 {
andrewboyson 142:a8c0890a58d1 28 RestartPoint = lastRestartPoint;
andrewboyson 97:d91f7db00235 29 return;
andrewboyson 97:d91f7db00235 30 }
andrewboyson 59:e0e556c8bd46 31
andrewboyson 98:b977424ec7f7 32 //Reset the trace of host at the very start
andrewboyson 98:b977424ec7f7 33 NetTraceHostResetMatched();
andrewboyson 98:b977424ec7f7 34
andrewboyson 59:e0e556c8bd46 35 //Handle packets
andrewboyson 59:e0e556c8bd46 36 int sizeRx;
andrewboyson 59:e0e556c8bd46 37 int sizeTx;
andrewboyson 59:e0e556c8bd46 38 char* pRx = NicGetReceivedPacketOrNull(&sizeRx);
andrewboyson 59:e0e556c8bd46 39 char* pTx = NicGetTransmitPacketOrNull(&sizeTx);
andrewboyson 59:e0e556c8bd46 40
andrewboyson 98:b977424ec7f7 41 int action = DO_NOTHING;
andrewboyson 98:b977424ec7f7 42 bool activity = false;
andrewboyson 59:e0e556c8bd46 43 if (pRx)
andrewboyson 59:e0e556c8bd46 44 {
andrewboyson 98:b977424ec7f7 45 activity = true;
andrewboyson 59:e0e556c8bd46 46
andrewboyson 59:e0e556c8bd46 47 if (pTx) action = EthHandlePacket(pRx, sizeRx, pTx, &sizeTx);
andrewboyson 97:d91f7db00235 48
andrewboyson 59:e0e556c8bd46 49 NicReleaseReceivedPacket();
andrewboyson 59:e0e556c8bd46 50 }
andrewboyson 85:cd9fdd6ab7e3 51
andrewboyson 59:e0e556c8bd46 52 if (pTx)
andrewboyson 59:e0e556c8bd46 53 {
andrewboyson 59:e0e556c8bd46 54 if (!action) action = EthPollForPacketToSend(pTx, &sizeTx);
andrewboyson 59:e0e556c8bd46 55
andrewboyson 59:e0e556c8bd46 56 if ( action)
andrewboyson 59:e0e556c8bd46 57 {
andrewboyson 98:b977424ec7f7 58 activity = true;
andrewboyson 59:e0e556c8bd46 59 NicSendTransmitPacket(sizeTx);
andrewboyson 59:e0e556c8bd46 60 }
andrewboyson 59:e0e556c8bd46 61 }
andrewboyson 98:b977424ec7f7 62
andrewboyson 98:b977424ec7f7 63 //Flash lights
andrewboyson 98:b977424ec7f7 64 JackLeds(!LINK_PIN, !SPEED_PIN, activity);
andrewboyson 98:b977424ec7f7 65
andrewboyson 98:b977424ec7f7 66 //Finish
andrewboyson 142:a8c0890a58d1 67 RestartPoint = lastRestartPoint;
andrewboyson 59:e0e556c8bd46 68 }
andrewboyson 59:e0e556c8bd46 69
andrewboyson 59:e0e556c8bd46 70 void LinkInit()
andrewboyson 59:e0e556c8bd46 71 {
andrewboyson 98:b977424ec7f7 72 JackInit();
andrewboyson 59:e0e556c8bd46 73 NicInit();
andrewboyson 59:e0e556c8bd46 74 NicLinkAddress(MacLocal);
andrewboyson 59:e0e556c8bd46 75 if (LinkTrace)
andrewboyson 59:e0e556c8bd46 76 {
andrewboyson 122:402d148f85d3 77 LogTime("MAC ");
andrewboyson 59:e0e556c8bd46 78 MacLog(MacLocal);
andrewboyson 59:e0e556c8bd46 79 Log("\r\n");
andrewboyson 59:e0e556c8bd46 80 }
andrewboyson 59:e0e556c8bd46 81 }