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@63:9d67a5eaa93c, 2018-01-16 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Jan 16 22:03:16 2018 +0000
- Revision:
- 63:9d67a5eaa93c
- Parent:
- 61:aad055f1b0d1
- Child:
- 67:b89a81c6ed99
Pulled out the connector leds so that the same library could be used with different boards
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 | 61:aad055f1b0d1 | 3 | #include "peripherals.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 | 59:e0e556c8bd46 | 11 | |
andrewboyson | 61:aad055f1b0d1 | 12 | #define phyLinkNeg_MASK 1UL << 25 //P1.25 input |
andrewboyson | 61:aad055f1b0d1 | 13 | #define phySpeedNeg_MASK 1UL << 26 //P1.26 input |
andrewboyson | 61:aad055f1b0d1 | 14 | |
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 | 63:9d67a5eaa93c | 25 | LinkPhyLink = !(LPC_GPIO1->FIOPIN & phyLinkNeg_MASK); |
andrewboyson | 63:9d67a5eaa93c | 26 | LinkPhySpeed = !(LPC_GPIO1->FIOPIN & phySpeedNeg_MASK); |
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 | 63:9d67a5eaa93c | 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 | 59:e0e556c8bd46 | 50 | if (pTx) |
andrewboyson | 59:e0e556c8bd46 | 51 | { |
andrewboyson | 59:e0e556c8bd46 | 52 | if (!action) action = EthPollForPacketToSend(pTx, &sizeTx); |
andrewboyson | 59:e0e556c8bd46 | 53 | |
andrewboyson | 59:e0e556c8bd46 | 54 | if ( action) |
andrewboyson | 59:e0e556c8bd46 | 55 | { |
andrewboyson | 63:9d67a5eaa93c | 56 | LinkActivity = true; |
andrewboyson | 59:e0e556c8bd46 | 57 | NicSendTransmitPacket(sizeTx); |
andrewboyson | 59:e0e556c8bd46 | 58 | } |
andrewboyson | 59:e0e556c8bd46 | 59 | } |
andrewboyson | 59:e0e556c8bd46 | 60 | } |
andrewboyson | 59:e0e556c8bd46 | 61 | |
andrewboyson | 59:e0e556c8bd46 | 62 | void LinkInit() |
andrewboyson | 59:e0e556c8bd46 | 63 | { |
andrewboyson | 59:e0e556c8bd46 | 64 | NicInit(); |
andrewboyson | 59:e0e556c8bd46 | 65 | NicLinkAddress(MacLocal); |
andrewboyson | 59:e0e556c8bd46 | 66 | if (LinkTrace) |
andrewboyson | 59:e0e556c8bd46 | 67 | { |
andrewboyson | 59:e0e556c8bd46 | 68 | Log("\r\n"); |
andrewboyson | 59:e0e556c8bd46 | 69 | LogTime("MAC: "); |
andrewboyson | 59:e0e556c8bd46 | 70 | MacLog(MacLocal); |
andrewboyson | 59:e0e556c8bd46 | 71 | Log("\r\n"); |
andrewboyson | 59:e0e556c8bd46 | 72 | } |
andrewboyson | 59:e0e556c8bd46 | 73 | } |