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:
Tue Nov 20 17:21:38 2018 +0000
Revision:
88:1ba13e6062a3
Parent:
83:08c983006a6e
Child:
93:580fc113d9e9
Increased TCB pool from 10 to 20.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 61:aad055f1b0d1 1 #include <stdint.h>
andrewboyson 61:aad055f1b0d1 2
andrewboyson 66:18a10c0b6d93 3 #include "log.h"
andrewboyson 66:18a10c0b6d93 4 #include "tcp.h"
andrewboyson 66:18a10c0b6d93 5 #include "tcb.h"
andrewboyson 66:18a10c0b6d93 6 #include "clock.h"
andrewboyson 52:fbc5a46b5e16 7
andrewboyson 88:1ba13e6062a3 8 #define TCB_COUNT 20
andrewboyson 10:f0854784e960 9
andrewboyson 10:f0854784e960 10 struct tcb tcbs[TCB_COUNT];
andrewboyson 10:f0854784e960 11
andrewboyson 10:f0854784e960 12 uint32_t TcbGetIsn()
andrewboyson 10:f0854784e960 13 {
andrewboyson 10:f0854784e960 14 static uint32_t isn = 0;
andrewboyson 10:f0854784e960 15 isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs.
andrewboyson 10:f0854784e960 16 return isn;
andrewboyson 10:f0854784e960 17 }
andrewboyson 80:4ef1500fca1d 18 struct tcb* TcbGetExisting(int ipType, int remArIndex, int locIpScope, uint16_t remPort, uint16_t locPort)
andrewboyson 10:f0854784e960 19 {
andrewboyson 10:f0854784e960 20 for (int i = 0; i < TCB_COUNT; i++)
andrewboyson 10:f0854784e960 21 {
andrewboyson 10:f0854784e960 22 struct tcb* pTcb = tcbs + i;
andrewboyson 78:9d8fc88df405 23 if (pTcb->state &&
andrewboyson 78:9d8fc88df405 24 pTcb->ipType == ipType &&
andrewboyson 78:9d8fc88df405 25 pTcb->remArIndex == remArIndex &&
andrewboyson 80:4ef1500fca1d 26 pTcb->locIpScope == locIpScope &&
andrewboyson 80:4ef1500fca1d 27 pTcb->remPort == remPort &&
andrewboyson 80:4ef1500fca1d 28 pTcb->locPort == locPort) return pTcb;
andrewboyson 10:f0854784e960 29 }
andrewboyson 10:f0854784e960 30 return NULL;
andrewboyson 10:f0854784e960 31 }
andrewboyson 10:f0854784e960 32 struct tcb* TcbGetEmpty()
andrewboyson 10:f0854784e960 33 {
andrewboyson 10:f0854784e960 34 for (int i = 0; i < TCB_COUNT; i++)
andrewboyson 10:f0854784e960 35 {
andrewboyson 10:f0854784e960 36 struct tcb* pTcb = tcbs + i;
andrewboyson 57:e0fb648acf48 37 if (pTcb->state == TCB_EMPTY) return pTcb;
andrewboyson 10:f0854784e960 38 }
andrewboyson 10:f0854784e960 39 return NULL;
andrewboyson 10:f0854784e960 40 }
andrewboyson 83:08c983006a6e 41 struct tcb* TcbGetNext(struct tcb* pTcb)
andrewboyson 74:c3756bfa960e 42 {
andrewboyson 83:08c983006a6e 43 if (!pTcb) return tcbs; //Initialise if passed NULL
andrewboyson 83:08c983006a6e 44 ++pTcb; //Increment
andrewboyson 83:08c983006a6e 45 if (pTcb < tcbs + TCB_COUNT) return pTcb;
andrewboyson 83:08c983006a6e 46 else return tcbs;
andrewboyson 83:08c983006a6e 47
andrewboyson 74:c3756bfa960e 48 }
andrewboyson 10:f0854784e960 49
andrewboyson 52:fbc5a46b5e16 50 uint32_t TcbElapsed = 0;
andrewboyson 52:fbc5a46b5e16 51
andrewboyson 52:fbc5a46b5e16 52 void TcbMain()
andrewboyson 52:fbc5a46b5e16 53 {
andrewboyson 66:18a10c0b6d93 54 if (ClockTicked) TcbElapsed++;
andrewboyson 10:f0854784e960 55 }
andrewboyson 10:f0854784e960 56 void TcbInit()
andrewboyson 10:f0854784e960 57 {
andrewboyson 57:e0fb648acf48 58 for (int i = 0; i < TCB_COUNT; i++) tcbs[i].state = TCB_EMPTY;
andrewboyson 52:fbc5a46b5e16 59 }