Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: eth/ar6.c
- Revision:
- 93:580fc113d9e9
- Parent:
- 74:c3756bfa960e
--- a/eth/ar6.c Thu Nov 29 16:52:10 2018 +0000
+++ b/eth/ar6.c Sun Dec 02 18:40:35 2018 +0000
@@ -2,7 +2,7 @@
#include <stdbool.h>
#include "log.h"
-#include "clock.h"
+#include "mstimer.h"
#include "net.h"
#include "mac.h"
#include "ip6addr.h"
@@ -11,9 +11,9 @@
bool Ar6Trace = false;
-#define CACHE_TIMEOUT 3600
-#define FREEZE_TIMEOUT 1800
-#define REPLY_TIMEOUT 2
+#define CACHE_TIMEOUT_MS 3600 * 1000
+#define FREEZE_TIMEOUT_MS 1800 * 1000
+#define REPLY_TIMEOUT_MS 2 * 1000
#define SEND_ATTEMPTS 3
#define RECORDS_COUNT 20
@@ -22,7 +22,6 @@
#define STATE_SENT 2
#define STATE_VALID 3
-static uint32_t elapsed = 0;
struct record
{
uint32_t elapsed;
@@ -42,18 +41,19 @@
}
static int getOldest()
{
- int iN = 0;
- uint32_t tN = 0xFFFFFFFF;
+ int iOldest = 0;
+ uint32_t ageOldest = 0;
for (int i = 0; i < RECORDS_COUNT; i++)
{
if (!records[i].state) return i; //Found an empty slot so just return it
- if (records[i].elapsed < tN)
+ uint32_t age = MsTimerCount - records[i].elapsed;
+ if (age >= ageOldest)
{
- tN = records[i].elapsed;
- iN = i;
+ ageOldest = age;
+ iOldest = i;
}
}
- return iN; //Otherwise return the oldest
+ return iOldest; //Otherwise return the oldest
}
void Ar6MakeRequestForMacFromIp(char* ip)
{
@@ -65,7 +65,7 @@
i = getExistingIp(ip);
if (i > -1)
{
- if (elapsed < records[i].elapsed + FREEZE_TIMEOUT) return;
+ if (!MsTimerHasElapsed(records[i].elapsed, FREEZE_TIMEOUT_MS)) return;
if (Ar6Trace)
{
LogTime("AR6 Updated request for MAC of ");
@@ -74,7 +74,7 @@
}
records[i].state = STATE_WANT;
records[i].tries = 0;
- records[i].elapsed = elapsed;
+ records[i].elapsed = MsTimerCount;
return;
}
@@ -89,7 +89,7 @@
Ip6AddressCopy(records[i].ip, ip);
records[i].state = STATE_WANT;
records[i].tries = 0;
- records[i].elapsed = elapsed;
+ records[i].elapsed = MsTimerCount;
MacClear(records[i].mac);
}
int Ar6AddIpRecord(void (*traceback)(void), char* mac, char* ip)
@@ -119,7 +119,7 @@
i = getExistingIp(ip);
if (i > -1)
{
- records[i].elapsed = elapsed;
+ records[i].elapsed = MsTimerCount;
records[i].state = STATE_VALID;
MacCopy(records[i].mac, mac);
return i;
@@ -129,7 +129,7 @@
i = getOldest();
MacCopy(records[i].mac, mac);
Ip6AddressCopy(records[i].ip, ip);
- records[i].elapsed = elapsed;
+ records[i].elapsed = MsTimerCount;
records[i].state = STATE_VALID;
return i;
}
@@ -155,7 +155,7 @@
{
if (records[i].state)
{
- HttpAddF("%4u ", (elapsed - records[i].elapsed) / 60);
+ HttpAddF("%4u ", (MsTimerCount - records[i].elapsed) / 1000 / 60);
int ipLen = Ip6AddressHttp(records[i].ip);
HttpFillChar(' ', 40 - ipLen);
@@ -173,16 +173,16 @@
}
static void clearCache(struct record* pr)
{
- if (elapsed > pr->elapsed + CACHE_TIMEOUT) clear(pr);
+ if (MsTimerHasElapsed(pr->elapsed, CACHE_TIMEOUT_MS)) clear(pr);
}
static void retry(struct record* pr)
{
- if (pr->state == STATE_SENT && elapsed > pr->elapsed + REPLY_TIMEOUT)
+ if (pr->state == STATE_SENT && MsTimerHasElapsed(pr->elapsed, REPLY_TIMEOUT_MS))
{
if (pr->tries < SEND_ATTEMPTS)
{
pr->state = STATE_WANT;
- pr->elapsed = elapsed;
+ pr->elapsed = MsTimerCount;
pr->tries++;
}
else
@@ -206,7 +206,7 @@
Ip6AddressCopy(NsAddressToResolve, pr->ip);
NsResolveRequestFlag = true;
pr->state = STATE_SENT;
- pr->elapsed = elapsed;
+ pr->elapsed = MsTimerCount;
return;
}
}
@@ -222,8 +222,6 @@
clearCache (pr);
retry (pr);
sendRequest(pr);
-
- if (ClockTicked) elapsed++;
}
void Ar6Init()
{