Fixed RTC bugs

This commit is contained in:
llsth 2015-03-18 00:37:25 +01:00
parent a228bc78bd
commit 2e2438f8ca
2 changed files with 25 additions and 34 deletions

View File

@ -36,10 +36,6 @@
#include <math.h>
#include <sys/socket.h>
#include <resources/battclock.h>
#include <clib/battclock_protos.h>
#include <clib/utility_protos.h>
#ifdef Debug
#undef Debug
#endif
@ -82,7 +78,7 @@
const char *vers = "\0$VER: ntimed 1.0a";
BOOL tracefile;
BOOL savetime;
BOOL started_from_wb;
struct Library *BattClockBase;
struct Library *UtilityBase = NULL;
@ -92,6 +88,8 @@ struct ntp_peerset *nps = NULL;
struct todolist *tdl = NULL;
struct udp_socket *usc = NULL;
extern int validtime;
struct ntimedargs {
char *params;
char *tracefile;
@ -136,7 +134,6 @@ int main(int argc, char **argv)
if (args.tracefile) {
ArgTracefile(args.tracefile);
tracefile = 1;
}
init_logic(&args);
@ -145,14 +142,11 @@ int main(int argc, char **argv)
SetSyncTime(10);
}
savetime = (BOOL)args.save;
NTP_PeerSet_Poll(NULL, nps, usc, tdl);
(void)TODO_Run(NULL, tdl);
if (args.save) {
Time_Amiga_Save();
Put(NULL, OCX_DEBUG, "Saved time to hardware clock\n");
}
return 0;
}
@ -259,6 +253,11 @@ static void init_logic(struct ntimedargs *args)
static void clean_exit()
{
if (savetime && validtime) {
Time_Amiga_Save();
Put(NULL, OCX_DEBUG, "Saved to real-time clock\n");
}
ArgTracefile(NULL);
if(usc) {
@ -282,7 +281,7 @@ static void clean_exit()
FreeArgs(rdargs);
rdargs = NULL;
}
freeall();
}

View File

@ -29,31 +29,19 @@
#include <stdio.h>
#include <math.h>
#include <exec/types.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <clib/alib_protos.h>
#include <proto/dos.h>
#include <clib/battclock_protos.h>
#include <devices/timer.h>
#include <signal.h>
#ifdef AROS
#include <exec/types.h>
#include <dos/dosextens.h>
#include <dos/rdargs.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <libraries/locale.h>
#include <utility/tagitem.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/battclock.h>
#include <proto/locale.h>
#include <proto/exec.h>
#include <proto/timer.h>
#endif
#include <proto/locale.h>
#include <proto/battclock.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
#include <clib/battclock_protos.h>
#ifdef Debug
#undef Debug
@ -84,6 +72,7 @@ struct timeval {
#endif
struct timeval sync_time;
int validtime = 0;
int limited_sync = 0;
float utcoffset = 0.0;
@ -268,7 +257,6 @@ void delete_timer(struct timerequest *request)
int amiga_get_time(struct timeval *tv)
{
struct timerequest *request;
long tzoffset = (long)round(utcoffset * 60.0 * 60.0);
request = create_timer();
if (request == NULL)
@ -278,7 +266,6 @@ int amiga_get_time(struct timeval *tv)
DoIO((struct IORequest*)request);
*tv = request->tr_time;
tv->tv_secs = (long)tv->tv_secs - tzoffset;
delete_timer(request);
return 0;
@ -300,6 +287,7 @@ int amiga_set_time(struct timeval *tv)
DoIO((struct IORequest*)request);
delete_timer(request);
validtime = 1;
return 0;
}
@ -307,7 +295,11 @@ int amiga_set_time(struct timeval *tv)
void amiga_save_time(void)
{
if(!validtime)
return;
struct timeval tv;
ResetBattClock();
amiga_get_time(&tv);
WriteBattClock(tv.tv_secs);
}