Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file
Dependencies: net 1-wire lpc1768 crypto clock web fram log
/media/uploads/andrewboyson/heating.sch
/media/uploads/andrewboyson/heating.brd
/media/uploads/andrewboyson/eagle.epf
Diff: main/main.c
- Revision:
- 1:ccc66fdf858d
- Parent:
- 0:3c04f4b47041
- Child:
- 4:9e1c6ac4ef06
--- a/main/main.c Thu Jan 11 17:40:08 2018 +0000 +++ b/main/main.c Sun Jan 28 14:41:12 2018 +0000 @@ -1,11 +1,12 @@ +#include "lpc1768.h" #include "watchdog.h" -#include "sc.h" +#include "periphs.h" #include "led.h" #include "clock.h" #include "tick.h" #include "log.h" #include "fram.h" -#include "net.h" +#include "net-server.h" #include "1-wire.h" #include "1-wire-device.h" #include "heating.h" @@ -15,35 +16,16 @@ #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(); + PeriphsInit(); + Lpc1768Init(); 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;; + NetServerInit(); + if (NtpClientInit()) goto end; ServerHttpInit(); OneWireInit(); DeviceInit(); @@ -52,23 +34,22 @@ if ( TraceInit()) goto end; if ( ValuesInit()) goto end; LogUart = 1; - LogTmFunction = getTmUtc; + LogTmFunction = ClockTmUtc; while (1) { WatchdogThisProgramPosition = 1; WatchdogMain(); WatchdogThisProgramPosition = 2; LogMain(); WatchdogThisProgramPosition = 3; ClockMain(); - WatchdogThisProgramPosition = 4; NetMain(); + WatchdogThisProgramPosition = 4; NetServerMain(); 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); + Led1Set(1); Led2Set(1); Led3Set(1); Led4Set(1); return 0; } \ No newline at end of file