A GPS disciplined clock
Dependencies: net lpc1768 crypto clock web log
settings/settings.c@17:1dcc58dac445, 2018-12-31 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Dec 31 19:19:57 2018 +0000
- Revision:
- 17:1dcc58dac445
- Parent:
- 16:3d40d832dc70
- Child:
- 18:eda70c3ee1a0
Updated clock part of http-base libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 8:2ef0f459bc83 | 1 | #include <stdlib.h> |
andrewboyson | 8:2ef0f459bc83 | 2 | #include <stdbool.h> |
andrewboyson | 8:2ef0f459bc83 | 3 | |
andrewboyson | 12:9bd8f04df514 | 4 | #include "clkstate.h" |
andrewboyson | 8:2ef0f459bc83 | 5 | #include "log.h" |
andrewboyson | 8:2ef0f459bc83 | 6 | #include "net.h" |
andrewboyson | 8:2ef0f459bc83 | 7 | #include "link.h" |
andrewboyson | 8:2ef0f459bc83 | 8 | #include "dns.h" |
andrewboyson | 8:2ef0f459bc83 | 9 | #include "dnsname.h" |
andrewboyson | 8:2ef0f459bc83 | 10 | #include "dnsquery.h" |
andrewboyson | 8:2ef0f459bc83 | 11 | #include "dnsreply.h" |
andrewboyson | 8:2ef0f459bc83 | 12 | #include "dnsserver.h" |
andrewboyson | 8:2ef0f459bc83 | 13 | #include "ntp.h" |
andrewboyson | 8:2ef0f459bc83 | 14 | #include "dhcp.h" |
andrewboyson | 8:2ef0f459bc83 | 15 | #include "ns.h" |
andrewboyson | 8:2ef0f459bc83 | 16 | #include "nr4.h" |
andrewboyson | 8:2ef0f459bc83 | 17 | #include "nr6.h" |
andrewboyson | 12:9bd8f04df514 | 18 | #include "clksync.h" |
andrewboyson | 8:2ef0f459bc83 | 19 | #include "echo4.h" |
andrewboyson | 8:2ef0f459bc83 | 20 | #include "echo6.h" |
andrewboyson | 8:2ef0f459bc83 | 21 | #include "dest6.h" |
andrewboyson | 8:2ef0f459bc83 | 22 | #include "ra.h" |
andrewboyson | 8:2ef0f459bc83 | 23 | #include "rs.h" |
andrewboyson | 8:2ef0f459bc83 | 24 | #include "ar4.h" |
andrewboyson | 8:2ef0f459bc83 | 25 | #include "ar6.h" |
andrewboyson | 8:2ef0f459bc83 | 26 | #include "arp.h" |
andrewboyson | 8:2ef0f459bc83 | 27 | #include "ip4.h" |
andrewboyson | 8:2ef0f459bc83 | 28 | #include "ip6.h" |
andrewboyson | 8:2ef0f459bc83 | 29 | #include "udp.h" |
andrewboyson | 8:2ef0f459bc83 | 30 | #include "tcp.h" |
andrewboyson | 8:2ef0f459bc83 | 31 | #include "http.h" |
andrewboyson | 8:2ef0f459bc83 | 32 | #include "tftp.h" |
andrewboyson | 8:2ef0f459bc83 | 33 | |
andrewboyson | 8:2ef0f459bc83 | 34 | #define GPREG2 (*((volatile unsigned *) 0x4002404C)) |
andrewboyson | 8:2ef0f459bc83 | 35 | #define GPREG3 (*((volatile unsigned *) 0x40024050)) |
andrewboyson | 8:2ef0f459bc83 | 36 | #define GPREG4 (*((volatile unsigned *) 0x40024054)) |
andrewboyson | 8:2ef0f459bc83 | 37 | #define ALMON (*((volatile unsigned *) 0x40024078)) |
andrewboyson | 8:2ef0f459bc83 | 38 | #define ALYEAR (*((volatile unsigned *) 0x4002407C)) |
andrewboyson | 16:3d40d832dc70 | 39 | #define ALDOM (*((volatile unsigned *) 0x4002406C)) |
andrewboyson | 11:baa388c55583 | 40 | |
andrewboyson | 11:baa388c55583 | 41 | /* |
andrewboyson | 16:3d40d832dc70 | 42 | ALSEC 6 Alarm value for Seconds R/W 0x4002 4060 - |
andrewboyson | 16:3d40d832dc70 | 43 | ALMIN 6 Alarm value for Minutes R/W 0x4002 4064 - |
andrewboyson | 11:baa388c55583 | 44 | ALHOUR 5 Alarm value for Hours R/W 0x4002 4068 |
andrewboyson | 16:3d40d832dc70 | 45 | ALDOM 5 Alarm value for Day of Month R/W 0x4002 406C * |
andrewboyson | 11:baa388c55583 | 46 | ALDOW 3 Alarm value for Day of Week R/W 0x4002 4070 |
andrewboyson | 16:3d40d832dc70 | 47 | ALDOY 9 Alarm value for Day of Year R/W 0x4002 4074 - |
andrewboyson | 16:3d40d832dc70 | 48 | ALMON 4 Alarm value for Months R/W 0x4002 4078 * |
andrewboyson | 16:3d40d832dc70 | 49 | ALYEAR 12 Alarm value for Years R/W 0x4002 407C * |
andrewboyson | 11:baa388c55583 | 50 | */ |
andrewboyson | 8:2ef0f459bc83 | 51 | |
andrewboyson | 8:2ef0f459bc83 | 52 | enum { iLogUart, iNetStack, iNetNewLine, iNetVerbose, iLink, iDnsName, iDnsQuery, iDnsReply, iDnsServer, |
andrewboyson | 14:1bce51823be0 | 53 | iNtp, iDhcp, iNsRecvSol, iNsRecvAdv, iNsSendSol, iNr4, iNr6, iNtpClient, iClkSync, iEcho4, iEcho6, |
andrewboyson | 8:2ef0f459bc83 | 54 | iDest6, iRa, iRs, iAr4, iAr6, iArp, iIp4, iIp6, iUdp, iTcp, iHttp, iTftp }; |
andrewboyson | 8:2ef0f459bc83 | 55 | |
andrewboyson | 11:baa388c55583 | 56 | int GetSensorHeight() |
andrewboyson | 11:baa388c55583 | 57 | { |
andrewboyson | 16:3d40d832dc70 | 58 | return ALDOM; //9 bits |
andrewboyson | 11:baa388c55583 | 59 | } |
andrewboyson | 11:baa388c55583 | 60 | void SetSensorHeight(int value) |
andrewboyson | 11:baa388c55583 | 61 | { |
andrewboyson | 16:3d40d832dc70 | 62 | ALDOM = value & 0x001F; //5 bits +32 |
andrewboyson | 11:baa388c55583 | 63 | } |
andrewboyson | 11:baa388c55583 | 64 | |
andrewboyson | 8:2ef0f459bc83 | 65 | static bool getBit(int bit) |
andrewboyson | 8:2ef0f459bc83 | 66 | { |
andrewboyson | 8:2ef0f459bc83 | 67 | return GPREG4 & (1U << bit); |
andrewboyson | 8:2ef0f459bc83 | 68 | } |
andrewboyson | 8:2ef0f459bc83 | 69 | static void setBit(int bit, bool value) |
andrewboyson | 8:2ef0f459bc83 | 70 | { |
andrewboyson | 8:2ef0f459bc83 | 71 | if (value) GPREG4 |= 1U << bit ; |
andrewboyson | 8:2ef0f459bc83 | 72 | else GPREG4 &= ~(1U << bit); |
andrewboyson | 8:2ef0f459bc83 | 73 | } |
andrewboyson | 8:2ef0f459bc83 | 74 | |
andrewboyson | 8:2ef0f459bc83 | 75 | void SetTraceNetHost (char* text) |
andrewboyson | 8:2ef0f459bc83 | 76 | { |
andrewboyson | 8:2ef0f459bc83 | 77 | int value = strtol(text, NULL, 16); |
andrewboyson | 8:2ef0f459bc83 | 78 | NetTraceHost[1] = value & 0xFF; //Little endian so low byte |
andrewboyson | 8:2ef0f459bc83 | 79 | NetTraceHost[0] = (value >> 8) & 0xFF; //high byte |
andrewboyson | 8:2ef0f459bc83 | 80 | ALMON = value >> 12; // 4 bits |
andrewboyson | 8:2ef0f459bc83 | 81 | ALYEAR = value & 0x3FFF; //12 bits |
andrewboyson | 8:2ef0f459bc83 | 82 | } |
andrewboyson | 8:2ef0f459bc83 | 83 | void ChgLogUart () { LogUart = !LogUart; setBit(iLogUart, LogUart ); } |
andrewboyson | 8:2ef0f459bc83 | 84 | void ChgTraceNetStack () { NetTraceStack = !NetTraceStack; setBit(iNetStack, NetTraceStack ); } |
andrewboyson | 8:2ef0f459bc83 | 85 | void ChgTraceNetNewLine() { NetTraceNewLine = !NetTraceNewLine; setBit(iNetNewLine, NetTraceNewLine); } |
andrewboyson | 8:2ef0f459bc83 | 86 | void ChgTraceNetVerbose() { NetTraceVerbose = !NetTraceVerbose; setBit(iNetVerbose, NetTraceVerbose); } |
andrewboyson | 8:2ef0f459bc83 | 87 | void ChgTraceLink () { LinkTrace = !LinkTrace; setBit(iLink, LinkTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 88 | void ChgTraceDnsName () { DnsNameTrace = !DnsNameTrace; setBit(iDnsName, DnsNameTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 89 | void ChgTraceDnsQuery () { DnsQueryTrace = !DnsQueryTrace; setBit(iDnsQuery, DnsQueryTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 90 | void ChgTraceDnsReply () { DnsReplyTrace = !DnsReplyTrace; setBit(iDnsReply, DnsReplyTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 91 | void ChgTraceDnsServer () { DnsServerTrace = !DnsServerTrace; setBit(iDnsServer, DnsServerTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 92 | void ChgTraceNtp () { NtpTrace = !NtpTrace; setBit(iNtp, NtpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 93 | void ChgTraceDhcp () { DhcpTrace = !DhcpTrace; setBit(iDhcp, DhcpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 94 | void ChgTraceNsRecvSol () { NsTraceRecvSol = !NsTraceRecvSol; setBit(iNsRecvSol, NsTraceRecvSol); } |
andrewboyson | 8:2ef0f459bc83 | 95 | void ChgTraceNsRecvAdv () { NsTraceRecvAdv = !NsTraceRecvAdv; setBit(iNsRecvAdv, NsTraceRecvAdv); } |
andrewboyson | 8:2ef0f459bc83 | 96 | void ChgTraceNsSendSol () { NsTraceSendSol = !NsTraceSendSol; setBit(iNsSendSol, NsTraceSendSol); } |
andrewboyson | 8:2ef0f459bc83 | 97 | void ChgTraceNr4 () { Nr4Trace = !Nr4Trace ; setBit(iNr4, Nr4Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 98 | void ChgTraceNr6 () { Nr6Trace = !Nr6Trace ; setBit(iNr6, Nr6Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 99 | void ChgTraceNtpClient () { NtpClientTrace = !NtpClientTrace ; setBit(iNtpClient, NtpClientTrace ); } |
andrewboyson | 14:1bce51823be0 | 100 | void ChgTraceSync () { ClkSyncTrace = !ClkSyncTrace ; setBit(iClkSync, ClkSyncTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 101 | void ChgTraceEcho4 () { Echo4Trace = !Echo4Trace ; setBit(iEcho4, Echo4Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 102 | void ChgTraceEcho6 () { Echo6Trace = !Echo6Trace ; setBit(iEcho6, Echo6Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 103 | void ChgTraceDest6 () { Dest6Trace = !Dest6Trace ; setBit(iDest6, Dest6Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 104 | void ChgTraceRa () { RaTrace = !RaTrace ; setBit(iRa, RaTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 105 | void ChgTraceRs () { RsTrace = !RsTrace ; setBit(iRs, RsTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 106 | void ChgTraceAr4 () { Ar4Trace = !Ar4Trace ; setBit(iAr4, Ar4Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 107 | void ChgTraceAr6 () { Ar6Trace = !Ar6Trace ; setBit(iAr6, Ar6Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 108 | void ChgTraceArp () { ArpTrace = !ArpTrace ; setBit(iArp, ArpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 109 | void ChgTraceIp4 () { Ip4Trace = !Ip4Trace ; setBit(iIp4, Ip4Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 110 | void ChgTraceIp6 () { Ip6Trace = !Ip6Trace ; setBit(iIp6, Ip6Trace ); } |
andrewboyson | 8:2ef0f459bc83 | 111 | void ChgTraceUdp () { UdpTrace = !UdpTrace ; setBit(iUdp, UdpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 112 | void ChgTraceTcp () { TcpTrace = !TcpTrace ; setBit(iTcp, TcpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 113 | void ChgTraceHttp () { HttpTrace = !HttpTrace ; setBit(iHttp, HttpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 114 | void ChgTraceTftp () { TftpTrace = !TftpTrace ; setBit(iTftp, TftpTrace ); } |
andrewboyson | 8:2ef0f459bc83 | 115 | |
andrewboyson | 8:2ef0f459bc83 | 116 | void ChgDnsSendRequestsViaIp4() { DnsSendRequestsViaIp4 = !DnsSendRequestsViaIp4; } |
andrewboyson | 8:2ef0f459bc83 | 117 | void ChgNtpSendRequestsViaIp4() { NtpSendRequestsViaIp4 = !NtpSendRequestsViaIp4; } |
andrewboyson | 8:2ef0f459bc83 | 118 | void ChgTftpSendRequestsViaIp4() { TftpSendRequestsViaIp4 = !TftpSendRequestsViaIp4; } |
andrewboyson | 8:2ef0f459bc83 | 119 | |
andrewboyson | 17:1dcc58dac445 | 120 | //Clock settings |
andrewboyson | 17:1dcc58dac445 | 121 | void SetClockSlewDivisor (int value) { ClockSlewDivisor = value; } |
andrewboyson | 17:1dcc58dac445 | 122 | void SetClockSlewMaxMs (int value) { ClockSlewMaxMs = value; } |
andrewboyson | 17:1dcc58dac445 | 123 | void SetClockPpbDivisor (int value) { ClockPpbDivisor = value; } |
andrewboyson | 17:1dcc58dac445 | 124 | void SetClockPpbChangeMax (int value) { ClockPpbChangeMax = value; } |
andrewboyson | 17:1dcc58dac445 | 125 | void SetClockSyncedLimitNs (int value) { ClockSyncedLimitNs = value; } |
andrewboyson | 17:1dcc58dac445 | 126 | void SetClockSyncedLimitPpb (int value) { ClockSyncedLimitPpb = value; } |
andrewboyson | 17:1dcc58dac445 | 127 | void SetClockSyncedHysterisNs (int value) { ClockSyncedHysterisNs = value; } |
andrewboyson | 17:1dcc58dac445 | 128 | void SetClockSyncedHysterisPpb(int value) { ClockSyncedHysterisPpb = value; } |
andrewboyson | 17:1dcc58dac445 | 129 | void SetClockMaxOffsetSecs (int value) { ClockMaxOffsetSecs = value; } |
andrewboyson | 17:1dcc58dac445 | 130 | |
andrewboyson | 8:2ef0f459bc83 | 131 | int SettingsInit() |
andrewboyson | 8:2ef0f459bc83 | 132 | { |
andrewboyson | 8:2ef0f459bc83 | 133 | ClockSlewDivisor = 10; |
andrewboyson | 8:2ef0f459bc83 | 134 | ClockSlewMaxMs = 20; |
andrewboyson | 8:2ef0f459bc83 | 135 | ClockPpbDivisor = 1000; |
andrewboyson | 8:2ef0f459bc83 | 136 | ClockPpbChangeMax = 10000000; |
andrewboyson | 8:2ef0f459bc83 | 137 | ClockSyncedLimitNs = 100000; |
andrewboyson | 8:2ef0f459bc83 | 138 | ClockSyncedLimitPpb = 100000; |
andrewboyson | 8:2ef0f459bc83 | 139 | ClockSyncedHysterisNs = 10000; |
andrewboyson | 8:2ef0f459bc83 | 140 | ClockSyncedHysterisPpb = 1000; |
andrewboyson | 8:2ef0f459bc83 | 141 | ClockMaxOffsetSecs = 3; |
andrewboyson | 8:2ef0f459bc83 | 142 | |
andrewboyson | 8:2ef0f459bc83 | 143 | DnsSendRequestsViaIp4 = false; |
andrewboyson | 8:2ef0f459bc83 | 144 | NtpSendRequestsViaIp4 = false; |
andrewboyson | 8:2ef0f459bc83 | 145 | TftpSendRequestsViaIp4 = true; |
andrewboyson | 8:2ef0f459bc83 | 146 | |
andrewboyson | 8:2ef0f459bc83 | 147 | NetTraceHost[1] = ALYEAR & 0xFF; //Little endian so low byte |
andrewboyson | 8:2ef0f459bc83 | 148 | NetTraceHost[0] = (ALMON << 4) + (ALYEAR >> 8); //high byte |
andrewboyson | 8:2ef0f459bc83 | 149 | |
andrewboyson | 8:2ef0f459bc83 | 150 | LogUart = getBit(iLogUart); |
andrewboyson | 8:2ef0f459bc83 | 151 | NetTraceStack = getBit(iNetStack); |
andrewboyson | 8:2ef0f459bc83 | 152 | NetTraceNewLine = getBit(iNetNewLine); |
andrewboyson | 8:2ef0f459bc83 | 153 | NetTraceVerbose = getBit(iNetVerbose); |
andrewboyson | 8:2ef0f459bc83 | 154 | LinkTrace = getBit(iLink); |
andrewboyson | 8:2ef0f459bc83 | 155 | DnsNameTrace = getBit(iDnsName); |
andrewboyson | 8:2ef0f459bc83 | 156 | DnsQueryTrace = getBit(iDnsQuery); |
andrewboyson | 8:2ef0f459bc83 | 157 | DnsReplyTrace = getBit(iDnsReply); |
andrewboyson | 8:2ef0f459bc83 | 158 | DnsServerTrace = getBit(iDnsServer); |
andrewboyson | 8:2ef0f459bc83 | 159 | NtpTrace = getBit(iNtp); |
andrewboyson | 8:2ef0f459bc83 | 160 | DhcpTrace = getBit(iDhcp); |
andrewboyson | 8:2ef0f459bc83 | 161 | NsTraceRecvSol = getBit(iNsRecvSol); |
andrewboyson | 8:2ef0f459bc83 | 162 | NsTraceRecvAdv = getBit(iNsRecvAdv); |
andrewboyson | 8:2ef0f459bc83 | 163 | NsTraceSendSol = getBit(iNsSendSol); |
andrewboyson | 8:2ef0f459bc83 | 164 | Nr4Trace = getBit(iNr4); |
andrewboyson | 8:2ef0f459bc83 | 165 | Nr6Trace = getBit(iNr6); |
andrewboyson | 8:2ef0f459bc83 | 166 | NtpClientTrace = getBit(iNtpClient); |
andrewboyson | 14:1bce51823be0 | 167 | ClkSyncTrace = getBit(iClkSync); |
andrewboyson | 8:2ef0f459bc83 | 168 | Echo4Trace = getBit(iEcho4); |
andrewboyson | 8:2ef0f459bc83 | 169 | Echo6Trace = getBit(iEcho6); |
andrewboyson | 8:2ef0f459bc83 | 170 | Dest6Trace = getBit(iDest6); |
andrewboyson | 8:2ef0f459bc83 | 171 | RaTrace = getBit(iRa); |
andrewboyson | 8:2ef0f459bc83 | 172 | RsTrace = getBit(iRs); |
andrewboyson | 8:2ef0f459bc83 | 173 | Ar4Trace = getBit(iAr4); |
andrewboyson | 8:2ef0f459bc83 | 174 | Ar6Trace = getBit(iAr6); |
andrewboyson | 8:2ef0f459bc83 | 175 | ArpTrace = getBit(iArp); |
andrewboyson | 8:2ef0f459bc83 | 176 | Ip4Trace = getBit(iIp4); |
andrewboyson | 8:2ef0f459bc83 | 177 | Ip6Trace = getBit(iIp6); |
andrewboyson | 8:2ef0f459bc83 | 178 | UdpTrace = getBit(iUdp); |
andrewboyson | 8:2ef0f459bc83 | 179 | TcpTrace = getBit(iTcp); |
andrewboyson | 8:2ef0f459bc83 | 180 | HttpTrace = getBit(iHttp); |
andrewboyson | 8:2ef0f459bc83 | 181 | TftpTrace = getBit(iTftp); |
andrewboyson | 8:2ef0f459bc83 | 182 | |
andrewboyson | 8:2ef0f459bc83 | 183 | return 0; |
andrewboyson | 8:2ef0f459bc83 | 184 | } |