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@122:402d148f85d3, 2019-02-12 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Feb 12 13:15:42 2019 +0000
- Revision:
- 122:402d148f85d3
- Parent:
- 98:b977424ec7f7
- Child:
- 142:a8c0890a58d1
Removed CRLF from before the MAC log
Who changed what in which revision?
User | Revision | Line number | New 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 | 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 | 98:b977424ec7f7 | 22 | int lastFaultPoint = FaultPoint; |
andrewboyson | 97:d91f7db00235 | 23 | FaultPoint = 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 | 98:b977424ec7f7 | 28 | FaultPoint = lastFaultPoint; |
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 | 98:b977424ec7f7 | 67 | FaultPoint = lastFaultPoint; |
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 | } |