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 1-wire lpc1768 crypto clock web fram log
Diff: main/main.c
- Revision:
- 0:3c04f4b47041
- Child:
- 1:ccc66fdf858d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/main.c	Thu Jan 11 17:40:08 2018 +0000
@@ -0,0 +1,74 @@
+#include "watchdog.h"
+#include "sc.h"
+#include "led.h"
+#include "clock.h"
+#include "tick.h"
+#include "log.h"
+#include "fram.h"
+#include "net.h"
+#include "1-wire.h"
+#include "1-wire-device.h"
+#include "heating.h"
+#include "settings.h"
+#include "ntp-client.h"
+#include "server-http.h"
+#include "trace.h"
+#include "values.h"
+
+int MainScanAverage = 0;
+
+static void establishScanTime()
+{
+    //Establish this scan time
+    static int lastCount = 0;
+    int elapsed = TickElapsed(&lastCount);
+    
+    //Average the scan time
+    if (elapsed > MainScanAverage) MainScanAverage++;
+    if (elapsed < MainScanAverage) MainScanAverage--;
+}
+
+static void getTmUtc(struct tm * ptm)
+{
+    int64_t ns = ClockNowNs();
+    ClockNsToTmUtc(ns, ptm);
+}
+
+int main()
+{
+               ScInit();
+              LedInit();
+            ClockInit();
+              LogInit();
+    if (     FramInit()) goto end; //Reserves 1 FRAM byte to detect if empty
+    if ( WatchdogInit()) goto end; //Reserves 1 FRAM byte for the program position
+              NetInit("ch4", "ch6");
+    if (NtpClientInit()) goto end;;
+       ServerHttpInit();
+          OneWireInit();
+           DeviceInit();
+          HeatingInit();
+    if ( SettingsInit()) goto end;
+    if (    TraceInit()) goto end;
+    if (   ValuesInit()) goto end;
+    LogUart = 1;
+    LogTmFunction = getTmUtc;
+      
+    while (1)
+    {   
+        WatchdogThisProgramPosition = 1;      WatchdogMain();
+        WatchdogThisProgramPosition = 2;           LogMain();
+        WatchdogThisProgramPosition = 3;         ClockMain();
+        WatchdogThisProgramPosition = 4;           NetMain();
+        WatchdogThisProgramPosition = 5;     NtpClientMain();
+        WatchdogThisProgramPosition = 6;        ValuesMain();
+        WatchdogThisProgramPosition = 7; if (  OneWireMain()) break;
+        WatchdogThisProgramPosition = 8; if (   DeviceMain()) break;
+        WatchdogThisProgramPosition = 9;       HeatingMain();
+        establishScanTime();
+    }
+
+end:
+    Led1(1); Led2(1); Led3(1); Led4(1);
+    return 0;
+}
\ No newline at end of file