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.
Dependencies: net lpc1768 crypto clock web fram log
settings.c
00001 00002 00003 #include <stdbool.h> 00004 #include <stdlib.h> 00005 #include <string.h> 00006 00007 #include "clkgov.h" 00008 #include "fram.h" 00009 #include "log.h" 00010 #include "net.h" 00011 #include "link.h" 00012 #include "dnsname.h" 00013 #include "dnsquery.h" 00014 #include "dnsreply.h" 00015 #include "dnsserver.h" 00016 #include "dnslabel.h" 00017 #include "ntp.h" 00018 #include "dhcp.h" 00019 #include "ns.h" 00020 #include "nr.h" 00021 #include "ntpclient.h" 00022 #include "echo4.h" 00023 #include "echo6.h" 00024 #include "dest6.h" 00025 #include "ra.h" 00026 #include "rs.h" 00027 #include "ar4.h" 00028 #include "ar6.h" 00029 #include "arp.h" 00030 #include "ip4.h" 00031 #include "ip6.h" 00032 #include "udp.h" 00033 #include "tcp.h" 00034 #include "web.h" 00035 #include "tftp.h" 00036 #include "dns.h" 00037 #include "led.h" 00038 00039 static int iClkGovSlewDivisor ; 00040 static int iClkGovSlewMaxMs ; 00041 static int iClkGovPpbDivisor ; 00042 static int iClkGovPpbChangeMax ; 00043 static int iClkGovSyncedLimitNs ; 00044 static int iClkGovSyncedLimitPpb ; 00045 static int iClkGovSyncedHysterisNs ; 00046 static int iClkGovSyncedHysterisPpb; 00047 static int iClkGovMaxOffsetSecs ; 00048 static int iClkGov; 00049 00050 static int iDnsSendRequestsViaIp4 ; 00051 static int iNtpSendRequestsViaIp4 ; 00052 static int iTftpSendRequestsViaIp4; 00053 00054 static int iNetHost; 00055 static int iLogUart; 00056 static int iNetStack; 00057 static int iNetNewLine; 00058 static int iNetVerbose; 00059 static int iLink; 00060 static int iDnsName; 00061 static int iDnsQuery; 00062 static int iDnsReply; 00063 static int iDnsServer; 00064 static int iNtp; 00065 static int iDhcp; 00066 static int iNsRecvSol; 00067 static int iNsRecvAdv; 00068 static int iNsSendSol; 00069 static int iNr4; 00070 static int iNr; 00071 static int iNtpClient; 00072 static int iEcho4; 00073 static int iEcho6; 00074 static int iDest6; 00075 static int iRa; 00076 static int iRs; 00077 static int iAr4; 00078 static int iAr6; 00079 static int iArp; 00080 static int iIp4; 00081 static int iIp6; 00082 static int iUdp; 00083 static int iTcp; 00084 static int iHttp; 00085 static int iTftp; 00086 00087 //Values 00088 static int iValuesServerName; 00089 void SetValuesServerName(char* value) { FramWrite(iValuesServerName, DNS_MAX_LABEL_LENGTH, value); } 00090 void GetValuesServerName(char* value) { FramRead (iValuesServerName, DNS_MAX_LABEL_LENGTH, value); value[DNS_MAX_LABEL_LENGTH] = 0; } 00091 00092 static int iValuesFileName; 00093 void SetValuesFileName(char* value) { FramWrite(iValuesFileName, DNS_MAX_LABEL_LENGTH, value); } 00094 void GetValuesFileName(char* value) { FramRead (iValuesFileName, DNS_MAX_LABEL_LENGTH, value); value[DNS_MAX_LABEL_LENGTH] = 0; } 00095 00096 static int iValuesWriteSize; 00097 void SetValuesWriteSize(int* pValue) { FramWrite(iValuesWriteSize, 4, pValue); } 00098 void GetValuesWriteSize(int* pValue) { FramRead (iValuesWriteSize, 4, pValue); } 00099 00100 static int iValuesReadInterval; 00101 void SetValuesReadInterval(int* pValue) { FramWrite(iValuesReadInterval, 4, pValue); } 00102 void GetValuesReadInterval(int* pValue) { FramRead (iValuesReadInterval, 4, pValue); } 00103 00104 static int iValuesStartTime; 00105 void SetValuesStartTime(int64_t* pValue) { FramWrite(iValuesStartTime, 8, pValue); } 00106 void GetValuesStartTime(int64_t* pValue) { FramRead (iValuesStartTime, 8, pValue); } 00107 00108 static int iValuesCount; 00109 void SetValuesCount(int* pValue) { FramWrite(iValuesCount, 4, pValue); } 00110 void GetValuesCount(int* pValue) { FramRead (iValuesCount, 4, pValue); } 00111 00112 static int iValuesData; 00113 void GetValuesData(int index, char* pValue) { FramRead (iValuesData + index, 1, pValue); } 00114 void SetValuesData(int recordLength, int count, void* pValue) { FramWrite(iValuesData + recordLength * count, recordLength, pValue); } 00115 int GetValuesMaxIndex() { return FRAM_SIZE - iValuesData; } 00116 int GetValuesMaxCount(int recordLength) { return GetValuesMaxIndex() / recordLength; } 00117 00118 //Clock settings 00119 void SetClockSlewDivisor (int value) { ClkGovSlewDivisor = value; FramWrite(iClkGovSlewDivisor, 4, &ClkGovSlewDivisor ); } 00120 void SetClockSlewMaxMs (int value) { ClkGovSlewChangeMaxMs = value; FramWrite(iClkGovSlewMaxMs, 4, &ClkGovSlewChangeMaxMs ); } 00121 void SetClockPpbDivisor (int value) { ClkGovFreqDivisor = value; FramWrite(iClkGovPpbDivisor, 4, &ClkGovFreqDivisor ); } 00122 void SetClockPpbChangeMax (int value) { ClkGovFreqChangeMaxPpb = value; FramWrite(iClkGovPpbChangeMax, 4, &ClkGovFreqChangeMaxPpb ); } 00123 void SetClockSyncedLimitNs (int value) { ClkGovSlewSyncedLimNs = value; FramWrite(iClkGovSyncedLimitNs, 4, &ClkGovSlewSyncedLimNs ); } 00124 void SetClockSyncedLimitPpb (int value) { ClkGovFreqSyncedLimPpb = value; FramWrite(iClkGovSyncedLimitPpb, 4, &ClkGovFreqSyncedLimPpb ); } 00125 void SetClockSyncedHysterisNs (int value) { ClkGovSlewSyncedHysNs = value; FramWrite(iClkGovSyncedHysterisNs, 4, &ClkGovSlewSyncedHysNs ); } 00126 void SetClockSyncedHysterisPpb(int value) { ClkGovFreqSyncedHysPpb = value; FramWrite(iClkGovSyncedHysterisPpb, 4, &ClkGovFreqSyncedHysPpb ); } 00127 void SetClockMaxOffsetSecs (int value) { ClkGovSlewOffsetMaxSecs = value; FramWrite(iClkGovMaxOffsetSecs, 4, &ClkGovSlewOffsetMaxSecs); } 00128 void ChgTraceSync () { ClkGovTrace = !ClkGovTrace ; FramWrite(iClkGov, 1, &ClkGovTrace ); } 00129 00130 //Log settings 00131 void ChgLogUart () { LogUart = !LogUart; FramWrite(iLogUart, 1, &LogUart ); } 00132 00133 //Net settings 00134 void ChgDnsSendRequestsViaIp4 () { DnsSendRequestsViaIp4 = !DnsSendRequestsViaIp4; FramWrite( iDnsSendRequestsViaIp4, 1, &DnsSendRequestsViaIp4); } 00135 void ChgNtpSendRequestsViaIp4 () { NtpClientQuerySendRequestsViaIp4 = !NtpClientQuerySendRequestsViaIp4; FramWrite( iNtpSendRequestsViaIp4, 1, &NtpClientQuerySendRequestsViaIp4); } 00136 void ChgTftpSendRequestsViaIp4 () { TftpSendRequestsViaIp4 = !TftpSendRequestsViaIp4; FramWrite(iTftpSendRequestsViaIp4, 1, &TftpSendRequestsViaIp4); } 00137 00138 void SetTraceNetHost (char* text) 00139 { 00140 int value = strtol(text, NULL, 16); 00141 NetTraceHost[1] = value & 0xFF; 00142 NetTraceHost[0] = (value >> 8) & 0xFF; 00143 FramWrite(iNetHost, 2, NetTraceHost); 00144 } 00145 void ChgTraceNetStack () { NetTraceStack = !NetTraceStack; FramWrite(iNetStack, 1, &NetTraceStack ); } 00146 void ChgTraceNetNewLine() { NetTraceNewLine = !NetTraceNewLine; FramWrite(iNetNewLine, 1, &NetTraceNewLine); } 00147 void ChgTraceNetVerbose() { NetTraceVerbose = !NetTraceVerbose; FramWrite(iNetVerbose, 1, &NetTraceVerbose); } 00148 void ChgTraceLink () { LinkTrace = !LinkTrace; FramWrite(iLink, 1, &LinkTrace ); } 00149 void ChgTraceDnsName () { DnsNameTrace = !DnsNameTrace; FramWrite(iDnsName, 1, &DnsNameTrace ); } 00150 void ChgTraceDnsQuery () { DnsQueryTrace = !DnsQueryTrace; FramWrite(iDnsQuery, 1, &DnsQueryTrace ); } 00151 void ChgTraceDnsReply () { DnsReplyTrace = !DnsReplyTrace; FramWrite(iDnsReply, 1, &DnsReplyTrace ); } 00152 void ChgTraceDnsServer () { DnsServerTrace = !DnsServerTrace; FramWrite(iDnsServer, 1, &DnsServerTrace ); } 00153 void ChgTraceNtp () { NtpTrace = !NtpTrace; FramWrite(iNtp, 1, &NtpTrace ); } 00154 void ChgTraceDhcp () { DhcpTrace = !DhcpTrace; FramWrite(iDhcp, 1, &DhcpTrace ); } 00155 void ChgTraceNsRecvSol () { NsTraceRecvSol = !NsTraceRecvSol; FramWrite(iNsRecvSol, 1, &NsTraceRecvSol); } 00156 void ChgTraceNsRecvAdv () { NsTraceRecvAdv = !NsTraceRecvAdv; FramWrite(iNsRecvAdv, 1, &NsTraceRecvAdv); } 00157 void ChgTraceNsSendSol () { NsTraceSendSol = !NsTraceSendSol; FramWrite(iNsSendSol, 1, &NsTraceSendSol); } 00158 void ChgTraceNr4 () { Nr4Trace = !Nr4Trace ; FramWrite(iNr4, 1, &Nr4Trace ); } 00159 void ChgTraceNr () { NrTrace = !NrTrace ; FramWrite(iNr, 1, &NrTrace ); } 00160 void ChgTraceNtpClient () { NtpClientTrace = !NtpClientTrace ; FramWrite(iNtpClient, 1, &NtpClientTrace ); } 00161 void ChgTraceEcho4 () { Echo4Trace = !Echo4Trace ; FramWrite(iEcho4, 1, &Echo4Trace ); } 00162 void ChgTraceEcho6 () { Echo6Trace = !Echo6Trace ; FramWrite(iEcho6, 1, &Echo6Trace ); } 00163 void ChgTraceDest6 () { Dest6Trace = !Dest6Trace ; FramWrite(iDest6, 1, &Dest6Trace ); } 00164 void ChgTraceRa () { RaTrace = !RaTrace ; FramWrite(iRa, 1, &RaTrace ); } 00165 void ChgTraceRs () { RsTrace = !RsTrace ; FramWrite(iRs, 1, &RsTrace ); } 00166 void ChgTraceAr4 () { Ar4Trace = !Ar4Trace ; FramWrite(iAr4, 1, &Ar4Trace ); } 00167 void ChgTraceAr6 () { Ar6Trace = !Ar6Trace ; FramWrite(iAr6, 1, &Ar6Trace ); } 00168 void ChgTraceArp () { ArpTrace = !ArpTrace ; FramWrite(iArp, 1, &ArpTrace ); } 00169 void ChgTraceIp4 () { Ip4Trace = !Ip4Trace ; FramWrite(iIp4, 1, &Ip4Trace ); } 00170 void ChgTraceIp6 () { Ip6Trace = !Ip6Trace ; FramWrite(iIp6, 1, &Ip6Trace ); } 00171 void ChgTraceUdp () { UdpTrace = !UdpTrace ; FramWrite(iUdp, 1, &UdpTrace ); } 00172 void ChgTraceTcp () { TcpTrace = !TcpTrace ; FramWrite(iTcp, 1, &TcpTrace ); } 00173 void ChgTraceHttp () { WebTrace = !WebTrace ; FramWrite(iHttp, 1, &WebTrace ); } 00174 void ChgTraceTftp () { TftpTrace = !TftpTrace ; FramWrite(iTftp, 1, &TftpTrace ); } 00175 00176 00177 static int iServerName; 00178 static int iInitialInterval; 00179 static int iNormalInterval; 00180 static int iRetryInterval; 00181 static int iOffsetMs; 00182 static int iMaxDelayMs; 00183 00184 void SetNtpClientServerName ( char* value) { DnsLabelCopy(NtpClientQueryServerName, value); FramWrite(iServerName, DNS_MAX_LABEL_LENGTH, NtpClientQueryServerName ); } 00185 void SetNtpClientInitialInterval ( int value) { NtpClientQueryInitialInterval = (int32_t)value ; FramWrite(iInitialInterval, 4, &NtpClientQueryInitialInterval ); } 00186 void SetNtpClientNormalInterval ( int value) { NtpClientQueryNormalInterval = (int32_t)value ; FramWrite(iNormalInterval, 4, &NtpClientQueryNormalInterval ); } 00187 void SetNtpClientRetryInterval ( int value) { NtpClientQueryRetryInterval = (int32_t)value ; FramWrite(iRetryInterval, 4, &NtpClientQueryRetryInterval ); } 00188 void SetNtpClientOffsetMs ( int value) { NtpClientReplyOffsetMs = (int32_t)value ; FramWrite(iOffsetMs, 4, &NtpClientReplyOffsetMs ); } 00189 void SetNtpClientMaxDelayMs ( int value) { NtpClientReplyMaxDelayMs = (int32_t)value ; FramWrite(iMaxDelayMs, 4, &NtpClientReplyMaxDelayMs ); } 00190 00191 int SettingsNtpInit() 00192 { 00193 int address; 00194 int32_t def4; 00195 00196 def4 = 0; address = FramLoad( DNS_MAX_LABEL_LENGTH+1, NtpClientQueryServerName, NULL ); if (address < 0) return -1; iServerName = address; 00197 def4 = 1; address = FramLoad( 4, &NtpClientQueryInitialInterval, &def4); if (address < 0) return -1; iInitialInterval = address; 00198 def4 = 600; address = FramLoad( 4, &NtpClientQueryNormalInterval, &def4); if (address < 0) return -1; iNormalInterval = address; 00199 def4 = 60; address = FramLoad( 4, &NtpClientQueryRetryInterval, &def4); if (address < 0) return -1; iRetryInterval = address; 00200 def4 = 0; address = FramLoad( 4, &NtpClientReplyOffsetMs, &def4); if (address < 0) return -1; iOffsetMs = address; 00201 def4 = 50; address = FramLoad( 4, &NtpClientReplyMaxDelayMs, &def4); if (address < 0) return -1; iMaxDelayMs = address; 00202 00203 return 0; 00204 } 00205 00206 int SettingsInit() 00207 { 00208 int address; 00209 int32_t def4; 00210 int64_t def8; 00211 char b; 00212 00213 def4 = 10; address = FramLoad( 4, &ClkGovSlewDivisor, &def4); if (address < 0) return -1; iClkGovSlewDivisor = address; 00214 def4 = 20; address = FramLoad( 4, &ClkGovSlewChangeMaxMs, &def4); if (address < 0) return -1; iClkGovSlewMaxMs = address; 00215 def4 = 1000; address = FramLoad( 4, &ClkGovFreqDivisor, &def4); if (address < 0) return -1; iClkGovPpbDivisor = address; 00216 def4 = 10000000; address = FramLoad( 4, &ClkGovFreqChangeMaxPpb, &def4); if (address < 0) return -1; iClkGovPpbChangeMax = address; 00217 def4 = 100000; address = FramLoad( 4, &ClkGovSlewSyncedLimNs, &def4); if (address < 0) return -1; iClkGovSyncedLimitNs = address; 00218 def4 = 100000; address = FramLoad( 4, &ClkGovFreqSyncedLimPpb, &def4); if (address < 0) return -1; iClkGovSyncedLimitPpb = address; 00219 def4 = 10000; address = FramLoad( 4, &ClkGovSlewSyncedHysNs, &def4); if (address < 0) return -1; iClkGovSyncedHysterisNs = address; 00220 def4 = 1000; address = FramLoad( 4, &ClkGovFreqSyncedHysPpb, &def4); if (address < 0) return -1; iClkGovSyncedHysterisPpb = address; 00221 def4 = 3; address = FramLoad( 4, &ClkGovSlewOffsetMaxSecs, &def4); if (address < 0) return -1; iClkGovMaxOffsetSecs = address; 00222 address = FramLoad( 1, &b, NULL); ClkGovTrace = b; if (address < 0) return -1; iClkGov = address; 00223 address = FramLoad( 1, &b, NULL); DnsSendRequestsViaIp4 = b; if (address < 0) return -1; iDnsSendRequestsViaIp4 = address; 00224 address = FramLoad( 1, &b, NULL); NtpClientQuerySendRequestsViaIp4 = b; if (address < 0) return -1; iNtpSendRequestsViaIp4 = address; 00225 address = FramLoad( 1, &b, NULL); TftpSendRequestsViaIp4 = b; if (address < 0) return -1; iTftpSendRequestsViaIp4 = address; 00226 address = FramLoad( 1, &b, NULL); LogUart = b; if (address < 0) return -1; iLogUart = address; 00227 address = FramLoad( 2, NetTraceHost, NULL) ; if (address < 0) return -1; iNetHost = address; 00228 address = FramLoad( 1, &b, NULL); NetTraceStack = b; if (address < 0) return -1; iNetStack = address; 00229 address = FramLoad( 1, &b, NULL); NetTraceNewLine = b; if (address < 0) return -1; iNetNewLine = address; 00230 address = FramLoad( 1, &b, NULL); NetTraceVerbose = b; if (address < 0) return -1; iNetVerbose = address; 00231 address = FramLoad( 1, &b, NULL); LinkTrace = b; if (address < 0) return -1; iLink = address; 00232 address = FramLoad( 1, &b, NULL); DnsNameTrace = b; if (address < 0) return -1; iDnsName = address; 00233 address = FramLoad( 1, &b, NULL); DnsQueryTrace = b; if (address < 0) return -1; iDnsQuery = address; 00234 address = FramLoad( 1, &b, NULL); DnsReplyTrace = b; if (address < 0) return -1; iDnsReply = address; 00235 address = FramLoad( 1, &b, NULL); DnsServerTrace = b; if (address < 0) return -1; iDnsServer = address; 00236 address = FramLoad( 1, &b, NULL); NtpTrace = b; if (address < 0) return -1; iNtp = address; 00237 address = FramLoad( 1, &b, NULL); DhcpTrace = b; if (address < 0) return -1; iDhcp = address; 00238 address = FramLoad( 1, &b, NULL); NsTraceRecvSol = b; if (address < 0) return -1; iNsRecvSol = address; 00239 address = FramLoad( 1, &b, NULL); NsTraceRecvAdv = b; if (address < 0) return -1; iNsRecvAdv = address; 00240 address = FramLoad( 1, &b, NULL); NsTraceSendSol = b; if (address < 0) return -1; iNsSendSol = address; 00241 address = FramLoad( 1, &b, NULL); Nr4Trace = b; if (address < 0) return -1; iNr4 = address; 00242 address = FramLoad( 1, &b, NULL); NrTrace = b; if (address < 0) return -1; iNr = address; 00243 address = FramLoad( 1, &b, NULL); NtpClientTrace = b; if (address < 0) return -1; iNtpClient = address; 00244 address = FramLoad( 1, &b, NULL); Echo4Trace = b; if (address < 0) return -1; iEcho4 = address; 00245 address = FramLoad( 1, &b, NULL); Echo6Trace = b; if (address < 0) return -1; iEcho6 = address; 00246 address = FramLoad( 1, &b, NULL); Dest6Trace = b; if (address < 0) return -1; iDest6 = address; 00247 address = FramLoad( 1, &b, NULL); RaTrace = b; if (address < 0) return -1; iRa = address; 00248 address = FramLoad( 1, &b, NULL); RsTrace = b; if (address < 0) return -1; iRs = address; 00249 address = FramLoad( 1, &b, NULL); Ar4Trace = b; if (address < 0) return -1; iAr4 = address; 00250 address = FramLoad( 1, &b, NULL); Ar6Trace = b; if (address < 0) return -1; iAr6 = address; 00251 address = FramLoad( 1, &b, NULL); ArpTrace = b; if (address < 0) return -1; iArp = address; 00252 address = FramLoad( 1, &b, NULL); Ip4Trace = b; if (address < 0) return -1; iIp4 = address; 00253 address = FramLoad( 1, &b, NULL); Ip6Trace = b; if (address < 0) return -1; iIp6 = address; 00254 address = FramLoad( 1, &b, NULL); UdpTrace = b; if (address < 0) return -1; iUdp = address; 00255 address = FramLoad( 1, &b, NULL); TcpTrace = b; if (address < 0) return -1; iTcp = address; 00256 address = FramLoad( 1, &b, NULL); WebTrace = b; if (address < 0) return -1; iHttp = address; 00257 address = FramLoad( 1, &b, NULL); TftpTrace = b; if (address < 0) return -1; iTftp = address; 00258 00259 address = FramAllocate(DNS_MAX_LABEL_LENGTH); if (address < 0) return -1; iValuesServerName = address; 00260 FramAllocate(1); //Spare 00261 address = FramAllocate(DNS_MAX_LABEL_LENGTH); if (address < 0) return -1; iValuesFileName = address; 00262 FramAllocate(1); //Spare 00263 address = FramAllocate( 4); if (address < 0) return -1; iValuesWriteSize = address; 00264 address = FramAllocate( 4); if (address < 0) return -1; iValuesReadInterval = address; 00265 address = FramAllocate( 8); if (address < 0) return -1; iValuesStartTime = address; 00266 address = FramAllocate( 4); if (address < 0) return -1; iValuesCount = address; 00267 address = FramAllocate( 1); if (address < 0) return -1; iValuesData = address; 00268 if (FramEmpty) 00269 { 00270 b = 0; FramWrite(iValuesServerName , 1, &b ); 00271 b = 0; FramWrite(iValuesFileName , 1, &b ); 00272 def4 = 100; FramWrite(iValuesWriteSize , 4, &def4); 00273 def4 = 15; FramWrite(iValuesReadInterval, 4, &def4); 00274 def8 = 0; FramWrite(iValuesStartTime , 8, &def8); 00275 def4 = 0; FramWrite(iValuesCount , 4, &def4); 00276 } 00277 00278 iValuesData = FramUsed; 00279 00280 return 0; 00281 } 00282 00283 00284
Generated on Tue Jul 12 2022 21:42:35 by
1.7.2