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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [devs/] [wallclock/] [dallas/] [ds1742/] [v2_0/] [ds1742.inl] - Blame information for rev 773

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      devs/wallclock/ds1742.inl
4
//
5
//      Wallclock implementation for Dallas 1742
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-05-25
46
// Purpose:       Wallclock driver for Dallas 1742
47
//
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
#ifndef DS_BASE
53
# error "Need to know base of DS1742 RAM"
54
#endif
55
 
56
#include          // Common type definitions and support
57
#include              // IO macros
58
 
59
// Offsets from DS_BASE
60
#define DS_SECONDS       0x7f9          // control bit!
61
#define DS_SECONDS_MASK  0x7f
62
#define DS_MINUTES       0x7fa
63
#define DS_HOUR          0x7fb
64
#define DS_DAY           0x7fc          // control bits
65
#define DS_DAY_MASK      0x07
66
#define DS_DATE          0x7fd
67
#define DS_MONTH         0x7fe
68
#define DS_YEAR          0x7ff
69
#define DS_CENTURY       0x7f8          // control bits!
70
#define DS_CENTURY_MASK  0x3f
71
 
72
// Control bits
73
#define DS_SECONDS_OSC   0x80           // set to stop oscillator (power save)
74
#define DS_CENTURY_READ  0x40           // set during read
75
#define DS_CENTURY_WRITE 0x80           // set during write
76
#define DS_DAY_BF        0x80           // battery flag
77
#define DS_DAY_FT        0x40           // frequency test
78
 
79
 
80
// Make sure test modes are disabled and that clock is running.
81
static void
82
init_ds_hwclock(void)
83
{
84
    cyg_uint8 _tmp;
85
 
86
    // Enable clock
87
    HAL_READ_UINT8(DS_BASE+DS_SECONDS, _tmp);
88
    _tmp &= ~DS_SECONDS_OSC;
89
    HAL_WRITE_UINT8(DS_BASE+DS_SECONDS, _tmp);
90
 
91
    // clear frequency test
92
    HAL_READ_UINT8(DS_BASE+DS_DAY, _tmp);
93
    _tmp &= ~DS_DAY_FT;
94
    HAL_WRITE_UINT8(DS_BASE+DS_DAY, _tmp);
95
}
96
 
97
 
98
static void
99
set_ds_hwclock(cyg_uint32 year, cyg_uint32 month, cyg_uint32 mday,
100
               cyg_uint32 hour, cyg_uint32 minute, cyg_uint32 second)
101
{
102
    cyg_uint8 _tmp;
103
    // Init write operation
104
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
105
    _tmp &= ~(DS_CENTURY_WRITE|DS_CENTURY_READ);
106
    _tmp |= DS_CENTURY_WRITE;
107
    HAL_WRITE_UINT8(DS_BASE+DS_CENTURY, _tmp);
108
 
109
    // Entries with control bits
110
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
111
    _tmp &= ~DS_CENTURY_MASK;
112
    _tmp |= TO_BCD(year/100) & DS_CENTURY_MASK;
113
    HAL_WRITE_UINT8(DS_BASE+DS_CENTURY, _tmp);
114
 
115
    HAL_READ_UINT8(DS_BASE+DS_SECONDS, _tmp);
116
    _tmp &= ~DS_SECONDS_MASK;
117
    _tmp |= TO_BCD(second) & DS_SECONDS_MASK;
118
    HAL_WRITE_UINT8(DS_BASE+DS_SECONDS, _tmp);
119
 
120
    HAL_READ_UINT8(DS_BASE+DS_DAY, _tmp);
121
    _tmp &= ~DS_DAY_FT;                 // clear frequency test
122
    HAL_WRITE_UINT8(DS_BASE+DS_DAY, _tmp);
123
 
124
 
125
    // Dedicated entries
126
    HAL_WRITE_UINT8(DS_BASE+DS_YEAR, TO_BCD(year % 100));
127
    HAL_WRITE_UINT8(DS_BASE+DS_MONTH, TO_BCD(month));
128
    HAL_WRITE_UINT8(DS_BASE+DS_DATE, TO_BCD(mday));
129
    HAL_WRITE_UINT8(DS_BASE+DS_HOUR, TO_BCD(hour));
130
    HAL_WRITE_UINT8(DS_BASE+DS_MINUTES, TO_BCD(minute));
131
 
132
    // Enable clock
133
    HAL_READ_UINT8(DS_BASE+DS_SECONDS, _tmp);
134
    _tmp &= ~DS_SECONDS_OSC;
135
    HAL_WRITE_UINT8(DS_BASE+DS_SECONDS, _tmp);
136
 
137
    // Finish write operation
138
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
139
    _tmp &= ~(DS_CENTURY_WRITE|DS_CENTURY_READ);
140
    HAL_WRITE_UINT8(DS_BASE+DS_CENTURY, _tmp);
141
}
142
 
143
static void
144
get_ds_hwclock(cyg_uint32* year, cyg_uint32* month, cyg_uint32* mday,
145
               cyg_uint32* hour, cyg_uint32* minute, cyg_uint32* second)
146
{
147
    cyg_uint8 _tmp;
148
 
149
    // Init read operation
150
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
151
    _tmp &= ~(DS_CENTURY_WRITE|DS_CENTURY_READ);
152
    _tmp |= DS_CENTURY_READ;
153
    HAL_WRITE_UINT8(DS_BASE+DS_CENTURY, _tmp);
154
 
155
    // Entries with control bits
156
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
157
    _tmp &= DS_CENTURY_MASK;
158
    *year = 100*TO_DEC(_tmp);
159
 
160
    HAL_READ_UINT8(DS_BASE+DS_SECONDS, _tmp);
161
    _tmp &= DS_SECONDS_MASK;
162
    *second = TO_DEC(_tmp);
163
 
164
    // Dedicated entries
165
    HAL_READ_UINT8(DS_BASE+DS_YEAR, _tmp);
166
    *year += TO_DEC(_tmp);
167
    HAL_READ_UINT8(DS_BASE+DS_MONTH, _tmp);
168
    *month = TO_DEC(_tmp);
169
    HAL_READ_UINT8(DS_BASE+DS_DATE, _tmp);
170
    *mday = TO_DEC(_tmp);
171
    HAL_READ_UINT8(DS_BASE+DS_HOUR, _tmp);
172
    *hour = TO_DEC(_tmp);
173
    HAL_READ_UINT8(DS_BASE+DS_MINUTES, _tmp);
174
    *minute = TO_DEC(_tmp);
175
 
176
    // Finish read operation
177
    HAL_READ_UINT8(DS_BASE+DS_CENTURY, _tmp);
178
    _tmp &= ~(DS_CENTURY_WRITE|DS_CENTURY_READ);
179
    HAL_WRITE_UINT8(DS_BASE+DS_CENTURY, _tmp);
180
}
181
 
182
//-----------------------------------------------------------------------------
183
// End of devs/wallclock/ds1742.inl

powered by: WebSVN 2.1.0

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