OpenCores
URL https://opencores.org/ocsvn/xulalx25soc/xulalx25soc/trunk

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [wbsettime.cpp] - Diff between revs 5 and 7

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 5 Rev 7
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    wbsettime.cpp
// Filename:    wbsettime.cpp
//
//
// Project:     XuLA2 board
// Project:     XuLA2 board
//
//
// Purpose:     To give a user access, via a command line program, to set the
// Purpose:     To give a user access, via a command line program, to set the
//              real time clock within the FPGA.  
//              real time clock within the FPGA.  Note, however, that the RTC
 
//      clock device only sets the subseconds field when you program it at the
 
//      top of a minute.  This program, therefore, will wait 'til the top of a 
 
//      minute to set the clock.  It can be annoying, but ... it works.
//
//
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015, Gisselquist Technology, LLC
// Copyright (C) 2015, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <strings.h>
#include <strings.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <signal.h>
#include <assert.h>
#include <assert.h>
#include <time.h>
#include <time.h>
 
 
#include "port.h"
#include "port.h"
#include "llcomms.h"
#include "llcomms.h"
#include "regdefs.h"
#include "regdefs.h"
 
 
DEVBUS  *m_fpga;
DEVBUS  *m_fpga;
void    closeup(int v) {
void    closeup(int v) {
        m_fpga->kill();
        m_fpga->kill();
        exit(0);
        exit(0);
}
}
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        DEVBUS::BUSW    v;
        bool    set_time = true;
 
 
        bool    set_time = true, read_hack = false;
 
 
 
        FPGAOPEN(m_fpga);
        FPGAOPEN(m_fpga);
 
 
        signal(SIGSTOP, closeup);
        signal(SIGSTOP, closeup);
        signal(SIGHUP, closeup);
        signal(SIGHUP, closeup);
 
 
 
 
        time_t  now, then;
        time_t  now, then;
 
 
        // We first wait for a second change, because we don't know how
        // We first wait for a second change, because we don't know how
        // much time this will take.
        // much time this will take.
        DEVBUS::BUSW    clockword = 0l, dateword = 0l;
        DEVBUS::BUSW    clockword = 0l, dateword = 0l;
        clockword = m_fpga->readio(R_CLOCK);
        clockword = m_fpga->readio(R_CLOCK);
 
 
        now = time(NULL);
        now = time(NULL);
        while(time(NULL) == now)
        while(time(NULL) == now)
                ;
                ;
 
 
        if (set_time) {
        if (set_time) {
                // Now, we have one second to set the time
                // Now, we have one second to set the time
                struct  tm      *tmp;
                struct  tm      *tmp;
                int             sleepv = 0;
                int             sleepv = 0;
 
 
                then = now+1;
                then = now+1;
                tmp = localtime(&then);
                tmp = localtime(&then);
                clockword &= ~0x03fffff;
                clockword &= ~0x03fffff;
 
 
                if (tmp->tm_sec != 0) {
                if (tmp->tm_sec != 0) {
                        // printf("THEN SECONDS = %d, ADDING %d\n",
                        // printf("THEN SECONDS = %d, ADDING %d\n",
                                // tmp->tm_sec, 60-tmp->tm_sec);
                                // tmp->tm_sec, 60-tmp->tm_sec);
                        if (tmp->tm_sec < 58)
                        if (tmp->tm_sec < 58)
                                sleepv = 59 - tmp->tm_sec;
                                sleepv = 59 - tmp->tm_sec;
                        then += 60 - tmp->tm_sec;
                        then += 60 - tmp->tm_sec;
                        tmp = localtime(&then);
                        tmp = localtime(&then);
                        // printf("Sleeping %d seconds (THEN->SEC = %d)\n", sleepv, tmp->tm_sec);
                        printf("Sleeping for %d seconds, so as to set time at the top of the minute\n", sleepv);
                }
                }
 
 
                // printf("ORIGINAL : %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
                // printf("ORIGINAL : %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
                // Seconds
                // Seconds
                clockword |= (((tmp->tm_sec)%10)&0x0f);
                clockword |= (((tmp->tm_sec)%10)&0x0f);
                clockword |= (((tmp->tm_sec)/10)&0x0f)<< 4;
                clockword |= (((tmp->tm_sec)/10)&0x0f)<< 4;
                // Minutes
                // Minutes
                clockword |= (((tmp->tm_min)%10)&0x0f)<< 8;
                clockword |= (((tmp->tm_min)%10)&0x0f)<< 8;
                clockword |= (((tmp->tm_min)/10)&0x0f)<<12;
                clockword |= (((tmp->tm_min)/10)&0x0f)<<12;
                // Hours
                // Hours
                clockword |= (((tmp->tm_hour)%10)&0x0f)<<16;
                clockword |= (((tmp->tm_hour)%10)&0x0f)<<16;
                clockword |= (((tmp->tm_hour)/10)&0x0f)<<20;
                clockword |= (((tmp->tm_hour)/10)&0x0f)<<20;
 
 
                // Years
                // Years
                dateword   = 0x00000000;
                dateword   = 0x00000000;
                dateword  |= (((tmp->tm_year+1900)/1000)&0x0f)<<28;
                dateword  |= (((tmp->tm_year+1900)/1000)&0x0f)<<28;
                dateword  |=((((tmp->tm_year+1900)/100 )%10)&0x0f)<<24;
                dateword  |=((((tmp->tm_year+1900)/100 )%10)&0x0f)<<24;
                dateword  |=((((tmp->tm_year+1900)/10  )%10)&0x0f)<<20;
                dateword  |=((((tmp->tm_year+1900)/10  )%10)&0x0f)<<20;
                dateword  |=((((tmp->tm_year+1900)     )%10)&0x0f)<<16;
                dateword  |=((((tmp->tm_year+1900)     )%10)&0x0f)<<16;
                dateword  |= (((tmp->tm_mon +1)/10)&0x0f)<<12;
                dateword  |= (((tmp->tm_mon +1)/10)&0x0f)<<12;
                dateword  |= (((tmp->tm_mon +1)%10)&0x0f)<< 8;
                dateword  |= (((tmp->tm_mon +1)%10)&0x0f)<< 8;
                dateword  |= (((tmp->tm_mday  )/10)&0x0f)<< 4;
                dateword  |= (((tmp->tm_mday  )/10)&0x0f)<< 4;
                dateword  |= (((tmp->tm_mday  )%10)&0x0f);
                dateword  |= (((tmp->tm_mday  )%10)&0x0f);
                if (sleepv > 0)
                if (sleepv > 0)
                        sleep(sleepv);
                        sleep(sleepv);
 
 
                while(time(NULL) < then)
                while(time(NULL) < then)
                        ;
                        ;
                m_fpga->writeio(R_CLOCK, clockword);
                m_fpga->writeio(R_CLOCK, clockword);
 
 
                printf("Time set to   %06x\n", clockword & 0x03fffff);
                printf("Time set to   %06x\n", clockword & 0x03fffff);
#ifdef R_DATE   // If we have the date capability
#ifdef R_DATE   // If we have the date capability
                m_fpga->writeio(R_DATE, dateword);
                m_fpga->writeio(R_DATE, dateword);
                printf("Date set to %08x\n", dateword);
                printf("Date set to %08x\n", dateword);
                printf("(Now reads %08x)\n", m_fpga->readio(R_DATE));
                printf("(Now reads %08x)\n", m_fpga->readio(R_DATE));
#endif // R_DATE
#endif // R_DATE
 
 
                now = then;
                now = then;
        } if (read_hack) {
 
                then = time(NULL) + 5;
 
                while(time(NULL) < then)
 
                        ;
 
                clockword = m_fpga->readio(R_CLOCK);
 
                printf("Hack : %08x\n", m_fpga->readio(R_TIMEHACK));
 
                printf(" SUBS: %08x:%08x\n", m_fpga->readio(R_HACKHI), m_fpga->readio(R_HACKLO));
 
 
 
        }
        }
 
 
        if (m_fpga->poll())
 
                printf("FPGA was interrupted\n");
 
        delete  m_fpga;
        delete  m_fpga;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.