Browse Source

Merge remote-tracking branch 'origin/startup' into Alarm_weergeven

Conflicts:
	main.c
Aareschluchtje 9 years ago
parent
commit
19886f9c1d
8 changed files with 107 additions and 52 deletions
  1. 46 0
      displayHandler.c
  2. 11 0
      displayHandler.h
  3. 1 0
      log.c
  4. 1 0
      log.h
  5. 30 39
      main.c
  6. 1 1
      network.h
  7. 14 12
      ntp.c
  8. 3 0
      ntp.h

+ 46 - 0
displayHandler.c

@@ -0,0 +1,46 @@
+//
+// Created by Jordy Sipkema on 26/02/16.
+//
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "display.h"
+#include "displayHandler.h"
+#include "ntp.h"
+#include "rtc.h"
+
+#define MONTH_OFFSET 1
+#define YEAR_OFFSET 1900
+
+void (*write_display_ptr[2])(char*, int) = {LcdArrayLineOne, LcdArrayLineTwo};
+
+void displayTime(int line_number){
+    tm time;
+    X12RtcGetClock(&time);
+
+    char str[12];
+    sprintf(str, "    %02d:%02d:%02d", time.tm_hour, time.tm_min, time.tm_sec);
+
+    if (line_number > -1 && line_number < 2){
+        (*write_display_ptr[line_number])(str, 12);
+    }
+}
+
+void displayDate(int line_number){
+    tm *time;
+    X12RtcGetClock(time);
+
+    char str[13];
+    sprintf(str, "   %02d-%02d-%04d", time->tm_mday, time->tm_mon+MONTH_OFFSET, time->tm_year+YEAR_OFFSET);
+
+    if(NtpIsSyncing())
+        str[1] = 'S';
+    if (line_number > -1 && line_number < 2){
+        (*write_display_ptr[line_number])(str, 13);
+    }
+}
+
+
+

+ 11 - 0
displayHandler.h

@@ -0,0 +1,11 @@
+//
+// Created by Jordy Sipkema on 26/02/16.
+//
+
+#ifndef MUTLI_OS_BUILD_DISPLAYHANDLER_H
+#define MUTLI_OS_BUILD_DISPLAYHANDLER_H
+
+void displayTime(int);
+void displayDate(int);
+
+#endif //MUTLI_OS_BUILD_DISPLAYHANDLER_H

+ 1 - 0
log.c

@@ -133,6 +133,7 @@ static PGM_P LogPrefixName_P(TLogLevel tLevel)
         case LOG_MENU_MODULE         :return(PSTR("ME: "));
         case LOG_MMC_MODULE          :return(PSTR("MM: "));
         case LOG_MMCDRV_MODULE       :return(PSTR("MD: "));
+        case LOG_NTP_MODULE          :return(PSTR("NT: "));
         case LOG_PARSE_MODULE        :return(PSTR("PA: "));
         case LOG_PLAYER_MODULE       :return(PSTR("PL: "));
         case LOG_REMCON_MODULE       :return(PSTR("RC: "));

+ 1 - 0
log.h

@@ -81,6 +81,7 @@ typedef u_char TLogLevel;
 #define LOG_MENU_MODULE         0xD0
 #define LOG_MMC_MODULE          0xE0
 #define LOG_MMCDRV_MODULE       0xF0
+#define LOG_NTP_MODULE          0xF8
 #define LOG_PARSE_MODULE        0x08
 #define LOG_PLAYER_MODULE       0x18
 #define LOG_REMCON_MODULE       0x28

+ 30 - 39
main.c

@@ -12,9 +12,6 @@
  *  COPYRIGHT (C) STREAMIT BV 2010
  *  \date 19 december 2003
  */
- 
- 
- 
 
 #define LOG_MODULE  LOG_MAIN_MODULE
 
@@ -29,6 +26,7 @@
 #include <sys/version.h>
 #include <dev/irqreg.h>
 
+#include "displayHandler.h"
 #include "system.h"
 #include "portio.h"
 #include "display.h"
@@ -192,22 +190,6 @@ static void SysControlMainBeat(u_char OnOff)
     }
 }
 
-void displayDate(){
-	struct _tm gmt;
-	gmt = GetRTCTime();
-	char str[13];
-	sprintf(str, "   %02d-%02d-%04d", gmt.tm_mday, gmt.tm_mon, gmt.tm_year+1900);
-	LcdArrayLineOne(str,13);
-}
-
-void displayTime(){
-	struct _tm gmt;
-	gmt = GetRTCTime();
-	char str[12];
-	sprintf(str, "    %02d:%02d:%02d", gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
-	LcdArrayLineTwo(str,12);
-}
-
 int timer(time_t start){
 	time_t diff = time(0) - start;
 	return diff;
@@ -251,6 +233,13 @@ void displayAlarm()
  */
 /* ����������������������������������������������������������������������� */
 
+THREAD(StartupInit, arg)
+{
+    NetworkInit();
+    NtpInit();
+    NutThreadExit();
+}
+
 int main(void)
 {
 	time_t start;
@@ -264,7 +253,6 @@ int main(void)
 	/*
 	 * Kroeske: Ook kan 'struct _tm gmt' Zie bovenstaande link
 	 */
-	
     /*
      *  First disable the watchdog
      */
@@ -283,21 +271,16 @@ int main(void)
     Uart0DriverInit();
     Uart0DriverStart();
 	LogInit();
-	
 
     CardInit();
 
-    NetworkInit();
+    X12Init();
+
+    NutThreadCreate("Bg", StartupInit, NULL, 512);
 
-    //NtpInit();
 	/*
 	 * Kroeske: sources in rtc.c en rtc.h
 	 */
-    X12Init();
-	gmt = GetRTCTime();
-	LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
-	
-
 
     if (At45dbInit()==AT45DB041B)
     {
@@ -319,12 +302,15 @@ int main(void)
 
 	/* Enable global interrupts */
 	sei();
+    gmt = GetRTCTime();
+    LogMsg_P(LOG_INFO, PSTR("Alarm : [%02d:%02d:%02d]"),gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
     alarmtime = GetRTCTime();
-    alarmtime.tm_hour = 5;
-    alarmtime.tm_min = 51;
-    alarmtime.tm_sec= 40;
+    alarmtime.tm_hour = 14;
+    alarmtime.tm_min = 32;
+    alarmtime.tm_sec= 00;
     printf("test");
-    X12RtcSetAlarm(0,&alarmtime,0b0000111);
+    X12RtcSetAlarm(0,&alarmtime,0b11111111);
+    //printf("alarm set: %d \n",X12RtcGetAlarm(0, &alarmtime, 0b11111111));
     printf("test2");
     for (;;)
     {		
@@ -342,16 +328,21 @@ int main(void)
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
 		}
-        if(X12RtcGetStatus(5) == 0)
+        LogMsg_P(LOG_INFO, PSTR("RTC Time : [%02d:%02d:%02d]"),gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
+        LogMsg_P(LOG_INFO, PSTR("Alarm : [%02d:%02d:%02d]"), alarmtime.tm_hour, alarmtime.tm_min, alarmtime.tm_sec );
+        if( gmt.tm_sec == alarmtime.tm_sec && gmt.tm_min == alarmtime.tm_min && gmt.tm_hour == alarmtime.tm_hour )
         {
-            displayAlarm();
-            printf("test3");
-            printf("data %d", X12RtcGetStatus(5));
-            printf("RTC2 time %d %d %d]\n", gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
+            //if(X12RtcGetStatus(5) == 0)
+           // {
+                displayAlarm();
+                printf("test3");
+                printf("test4");
+                printf("Getstatus %d \n", X12RtcGetStatus(5));
+            //}
         }
         else {
-            displayTime();
-            displayDate();
+            displayTime(0);
+            displayDate(1);
         }
         WatchDogRestart();
     }

+ 1 - 1
network.h

@@ -7,4 +7,4 @@
 
 extern void NetworkInit(void);
 
-#endif /* _Network_H */
+#endif /* _Network_H */

+ 14 - 12
ntp.c

@@ -17,20 +17,30 @@
 #include <string.h>
 #include <time.h>
 
+#include "log.h"
 #include "ntp.h"
 
+#define TIME_ZONE 1
+#define LOG_MODULE  LOG_NTP_MODULE
+
+bool isSyncing;
 time_t ntp_time = 0;
 tm *ntp_datetime;
 uint32_t timeserver = 0;
 
 void NtpInit() {
     /* Timezone van nederland (gmt 1) */
-    _timezone = -2 * 60 * 60;
+    _timezone = -TIME_ZONE * 3600;
     GetTime();
 }
 
+bool NtpIsSyncing(){
+    return isSyncing;
+}
+
 void GetTime(){
     /* Ophalen van pool.ntp.org */
+    isSyncing = true;
     puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     timeserver = inet_addr("213.154.229.24");
 
@@ -49,15 +59,7 @@ void GetTime(){
     printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
     printf("NTP date is: %02d.%02d.%02d\n\n", ntp_datetime->tm_mday, (ntp_datetime->tm_mon + 1), (ntp_datetime->tm_year + 1900));
 
-    NutRtcSetTime(ntp_datetime);
-
-
-    // This isn't working...
-    tm *test;
-
-    X12RtcGetClock(test);
-
-    printf("RTC time is: %02d:%02d:%02d\n", test->tm_hour, test->tm_min, test->tm_sec);
-    printf("RTC date is: %02d.%02d.%02d\n\n", test->tm_mday, (test->tm_mon + 1), (test->tm_year + 1900));
-}
+    X12RtcSetClock(ntp_datetime);
 
+    isSyncing = false;
+}

+ 3 - 0
ntp.h

@@ -5,6 +5,9 @@
 #ifndef _Network_H
 #define _Network_H
 
+typedef enum {false, true} bool;
+
+extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
 extern void GetTime(void);
 #endif /* _Network_H */