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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [wallclock/] [v2_0/] [src/] [wallclock.cxx] - Blame information for rev 593

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      devs/wallclock/wallclock.cxx
4
//
5
//      Wallclock base
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     jskov
44
// Contributors:  jskov
45
// Date:          2000-03-28
46
// Purpose:       Wallclock base driver
47
// Description:   This provides a generic wallclock base driver which
48
//                relies on sub-drivers to provide the interface functions
49
//                to the hardware device (see wallclock.hxx for details).
50
//
51
//                The driver can be configured to run in one of two modes:
52
//                  init-get mode:
53
//                    In this mode, the hardware driver only needs to
54
//                    implement a function to read the hardware clock
55
//                    and a (possibly empty) init function which makes
56
//                    sure the hardware clock is properly initialized.
57
//                    While the driver in this mode has a smaller memory
58
//                    foot-print, it does not support battery-backed up
59
//                    clocks.
60
//
61
//                  set-get mode:
62
//                    Requires both set and get functions for the hardware
63
//                    device. While bigger, it allows support of 
64
//                    battery-backed up clocks.
65
//
66
//
67
//####DESCRIPTIONEND####
68
//
69
//==========================================================================
70
 
71
#include <pkgconf/wallclock.h>          // Wallclock device config
72
 
73
#include <cyg/infra/cyg_type.h>         // Common type definitions and support
74
 
75
#include <cyg/hal/drv_api.h>            // Driver API
76
 
77
#include <cyg/io/wallclock.hxx>         // The WallClock API
78
 
79
 
80
//-----------------------------------------------------------------------------
81
// Local static variables
82
 
83
static Cyg_WallClock wallclock_instance CYGBLD_ATTRIB_INIT_AFTER( CYG_INIT_CLOCK );
84
 
85
#ifndef CYGSEM_WALLCLOCK_SET_GET_MODE
86
static cyg_uint32 epoch_ticks;
87
static cyg_uint32 epoch_time_stamp;
88
#endif
89
 
90
Cyg_WallClock *Cyg_WallClock::wallclock;
91
 
92
//-----------------------------------------------------------------------------
93
// Constructor
94
 
95
Cyg_WallClock::Cyg_WallClock()
96
{
97
    // install instance pointer
98
    wallclock = &wallclock_instance;
99
 
100
    // Always allow low-level driver to initialize clock, even though it
101
    // may not be necessary for set-get mode.
102
    init_hw_seconds();
103
}
104
 
105
//-----------------------------------------------------------------------------
106
// Returns the number of seconds elapsed since 1970-01-01 00:00:00.
107
// This may involve reading the hardware, so it may take anything up to
108
// a second to complete.
109
 
110
cyg_uint32 Cyg_WallClock::get_current_time()
111
{
112
    cyg_uint32 res;
113
 
114
    cyg_drv_dsr_lock();
115
 
116
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
117
    res = get_hw_seconds();
118
#else
119
    res = epoch_time_stamp + get_hw_seconds() - epoch_ticks;
120
#endif
121
 
122
    cyg_drv_dsr_unlock();
123
 
124
    return res;
125
}
126
 
127
//-----------------------------------------------------------------------------
128
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00.
129
// This may involve reading or writing to the hardware, so it may take
130
// anything up to a second to complete.
131
void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp )
132
{
133
    cyg_drv_dsr_lock();
134
 
135
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
136
    set_hw_seconds(time_stamp);
137
#else
138
    epoch_time_stamp    = time_stamp;
139
    epoch_ticks         = get_hw_seconds();
140
#endif
141
 
142
    cyg_drv_dsr_unlock();
143
}
144
 
145
//-----------------------------------------------------------------------------
146
// End of devs/wallclock/wallclock.cxx

powered by: WebSVN 2.1.0

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