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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [doc/] [bsp_howto/] [rtc.t] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
@c
2
@c  COPYRIGHT (c) 1988-2002.
3
@c  On-Line Applications Research Corporation (OAR).
4
@c  All rights reserved.
5
@c
6
@c  rtc.t,v 1.5 2002/01/17 21:47:44 joel Exp
7
@c
8
 
9
@chapter Real-Time Clock Driver
10
 
11
@section Introduction
12
 
13
The Real-Time Clock (@b{RTC}) driver is responsible for providing an
14
interface to an @b{RTC} device.  [NOTE: In this chapter, the abbreviation
15
@b{TOD} is used for @b{Time of Day}.]  The capabilities provided by this
16
driver are:
17
 
18
@itemize @bullet
19
@item Set the RTC TOD to RTEMS TOD
20
@item Set the RTEMS TOD to the RTC TOD
21
@item Get the RTC TOD
22
@item Set the RTC TOD to the Specified TOD
23
@item Get the Difference Between the RTEMS and RTC TOD
24
@end itemize
25
 
26
The reference implementation for a real-time clock driver can
27
be found in @code{c/src/lib/libbsp/shared/tod.c}.  This driver
28
is based on the libchip concept and can be easily configured
29
to work with any of the RTC chips supported by the RTC
30
chip drivers in the directory @code{c/src/lib/lib/libchip/rtc}.
31
There is a README file in this directory for each supported
32
RTC chip.  Each of these README explains how to configure the
33
shared libchip implementation of the RTC driver for that particular
34
RTC chip.
35
 
36
The DY-4 DMV177 BSP uses the shared libchip implementation of the RTC
37
driver.  Its @code{RTC_Table} configuration table can be found in
38
@code{c/src/lib/libbsp/powerpc/dmv177/tod/config.c}.
39
 
40
@section Initialization
41
 
42
The @code{rtc_initialize} routine is responsible for initializing the
43
RTC chip so it can be used.  The shared libchip implementation of this
44
driver supports multiple RTCs and bases its initialization order on
45
the order the chips are defined in the @code{RTC_Table}.  Each chip
46
defined in the table may or may not be present on this particular board.
47
It is the responsibility of the @code{deviceProbe} to indicate the
48
presence of a particular RTC chip.  The first RTC found to be present
49
is considered the preferred RTC.
50
 
51
In the shared libchip based implementation
52
of the driver, the following actions are performed:
53
 
54
@example
55
@group
56
rtems_device_driver rtc_initialize(
57
  rtems_device_major_number  major,
58
  rtems_device_minor_number  minor_arg,
59
  void                      *arg
60
)
61
@{
62
   for each RTC configured in RTC_Table
63
     if the deviceProbe for this RTC indicates it is present
64
       set RTC_Minor to this device
65
       set RTC_Present to TRUE
66
       break out of this loop
67
 
68
   if RTC_Present is not TRUE
69
     return RTEMS_INVALID_NUMBER to indicate that no RTC is present
70
 
71
   register this minor number as the "/dev/rtc"
72
 
73
   perform the deviceInitialize routine for the preferred RTC chip
74
 
75
   for RTCs past this one in the RTC_Table
76
     if the deviceProbe for this RTC indicates it is present
77
       perform the deviceInitialize routine for this RTC chip
78
       register the configured name for this RTC
79
@}
80
@end group
81
@end example
82
 
83
The @code{deviceProbe} routine returns TRUE if the device
84
configured by this entry in the @code{RTC_Table} is present.
85
This configuration scheme allows one to support multiple versions
86
of the same board with a single BSP.  For example, if the first
87
generation of a board had Vendor A's RTC chip and the second
88
generation had Vendor B's RTC chip, RTC_Table could contain
89
information for both.  The @code{deviceProbe} configured
90
for Vendor A's RTC chip would need to return TRUE if the
91
board was a first generation one.  The @code{deviceProbe}
92
routines are very board dependent and must be provided by
93
the BSP.
94
 
95
@section setRealTimeToRTEMS
96
 
97
The @code{setRealTimeToRTEMS} routine sets the current RTEMS TOD to that
98
of the preferred RTC.
99
 
100
@example
101
@group
102
void setRealTimeToRTEMS(void)
103
@{
104
  if no RTCs are present
105
    return
106
 
107
  invoke the deviceGetTime routine for the preferred RTC
108
  set the RTEMS TOD using rtems_clock_set
109
@}
110
@end group
111
@end example
112
 
113
@section setRealTimeFromRTEMS
114
 
115
The @code{setRealTimeFromRTEMS} routine sets the preferred RTC TOD to the
116
current RTEMS TOD.
117
 
118
@example
119
@group
120
void setRealTimeFromRTEMS(void)
121
@{
122
  if no RTCs are present
123
    return
124
 
125
  obtain the RTEMS TOD using rtems_clock_get
126
  invoke the deviceSetTime routine for the preferred RTC
127
@}
128
@end group
129
@end example
130
 
131
@section getRealTime
132
 
133
The @code{getRealTime} returns the preferred RTC TOD to the
134
caller.
135
 
136
@example
137
@group
138
void getRealTime( rtems_time_of_day *tod )
139
@{
140
  if no RTCs are present
141
    return
142
 
143
  invoke the deviceGetTime routine for the preferred RTC
144
@}
145
@end group
146
@end example
147
 
148
@section setRealTime
149
 
150
The @code{setRealTime} routine sets the preferred RTC TOD to the
151
TOD specified by the caller.
152
 
153
@example
154
@group
155
void setRealTime( rtems_time_of_day *tod )
156
@{
157
  if no RTCs are present
158
    return
159
 
160
  invoke the deviceSetTime routine for the preferred RTC
161
@}
162
@end group
163
@end example
164
 
165
@section checkRealTime
166
 
167
The @code{checkRealTime} routine returns the number of seconds
168
difference between the RTC TOD and the current RTEMS TOD.
169
 
170
@example
171
@group
172
int checkRealTime( void )
173
@{
174
  if no RTCs are present
175
    return -1
176
 
177
 
178
  obtain the RTEMS TOD using rtems_clock_get
179
  get the TOD from the preferred RTC using the deviceGetTime routine
180
 
181
  convert the RTEMS TOD to seconds
182
  convert the RTC TOD to seconds
183
 
184
  return the RTEMS TOD in seconds - RTC TOD in seconds
185
@}
186
@end group
187
@end example
188
 

powered by: WebSVN 2.1.0

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