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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [wallclock/] [synth/] [current/] [src/] [wallclock_synth.cxx] - Blame information for rev 811

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      wallclock_synth.cxx
4
//
5
//      eCos synthetic wallclock driver.
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     Savin Zlobec <savin@elatec.si>
43
// Contributors:  
44
// Date:          2003-10-02
45
// Purpose:        
46
//
47
//####DESCRIPTIONEND####
48
//
49
//==========================================================================
50
 
51
#include <pkgconf/wallclock.h>           
52
#include <pkgconf/devs_wallclock_synth.h>
53
 
54
#include <cyg/hal/hal_io.h>               
55
#include <cyg/hal/hal_arch.h>
56
 
57
#include <cyg/infra/cyg_type.h>          
58
#include <cyg/infra/diag.h>            
59
 
60
#include <cyg/io/wallclock.hxx>          
61
 
62
//-----------------------------------------------------------------------------
63
 
64
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
65
// Difference between system and eCos wallclock
66
static cyg_uint32 epoch_ticks;
67
static cyg_uint32 epoch_time_stamp;
68
#endif
69
 
70
//-----------------------------------------------------------------------------
71
// Functions required for the hardware-driver API.
72
 
73
// Initializes the clock
74
void
75
Cyg_WallClock::init_hw_seconds(void)
76
{
77
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
78
    int fd;
79
 
80
    // Read difference between system and eCos wallclock from file
81
    fd = cyg_hal_sys_open(CYGDAT_DEVS_WALLCLOCK_SYNTH_FILENAME,
82
        CYG_HAL_SYS_O_RDONLY, 0);
83
 
84
    if (fd > 0)
85
    {
86
        cyg_hal_sys_read(fd, &epoch_time_stamp, sizeof(epoch_time_stamp));
87
        cyg_hal_sys_read(fd, &epoch_ticks, sizeof(epoch_ticks));
88
        cyg_hal_sys_close(fd);
89
    }
90
#endif
91
}
92
 
93
// Returns the number of seconds elapsed since 1970-01-01 00:00:00
94
cyg_uint32
95
Cyg_WallClock::get_hw_seconds(void)
96
{
97
    cyg_uint32 res;
98
    struct cyg_hal_sys_timeval  ctv;
99
    struct cyg_hal_sys_timezone ctz;
100
 
101
    cyg_hal_sys_gettimeofday(&ctv, &ctz);
102
 
103
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
104
    res = epoch_time_stamp + ctv.hal_tv_sec - epoch_ticks;
105
#else
106
    res = ctv.hal_tv_sec;
107
#endif
108
 
109
    return res;
110
}
111
 
112
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
113
 
114
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00
115
void
116
Cyg_WallClock::set_hw_seconds(cyg_uint32 secs)
117
{
118
    int fd;
119
    struct cyg_hal_sys_timeval  ctv;
120
    struct cyg_hal_sys_timezone ctz;
121
 
122
    // System wallclock time    
123
    cyg_hal_sys_gettimeofday(&ctv, &ctz);
124
 
125
    // Set the difference between the system and eCos wallclock
126
    epoch_time_stamp = secs;
127
    epoch_ticks      = ctv.hal_tv_sec;
128
 
129
    // Write difference to file
130
    fd = cyg_hal_sys_open(CYGDAT_DEVS_WALLCLOCK_SYNTH_FILENAME,
131
        CYG_HAL_SYS_O_WRONLY | CYG_HAL_SYS_O_CREAT,
132
        CYG_HAL_SYS_S_IRWXU | CYG_HAL_SYS_S_IRWXG | CYG_HAL_SYS_S_IRWXO);
133
 
134
    if (fd > 0)
135
    {
136
        cyg_hal_sys_write(fd, &epoch_time_stamp, sizeof(epoch_time_stamp));
137
        cyg_hal_sys_write(fd, &epoch_ticks, sizeof(epoch_ticks));
138
        cyg_hal_sys_close(fd);
139
    }
140
}
141
 
142
#endif // CYGSEM_WALLCLOCK_SET_GET_MODE
143
 
144
//-----------------------------------------------------------------------------
145
// EOF wallclock_synth.cxx

powered by: WebSVN 2.1.0

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