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