source: rtems/doc/bsp_howto/rtc.t @ bc950e87

4.104.114.84.95
Last change on this file since bc950e87 was bc950e87, checked in by Joel Sherrill <joel.sherrill@…>, on 11/19/98 at 16:02:06

Applied updates from remote work while doing class.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-1998.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@chapter Real-Time Clock Driver
10
11@section Introduction
12
13The Real-Time Clock (@b{RTC}) driver is responsible for providing an
14interface 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
16driver 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
26The reference implementation for a real-time clock driver can
27be found in @code{c/src/lib/libbsp/shared/tod.c}.  This driver
28is based on the libchip concept and can be easily configured
29to work with any of the RTC chips supported by the RTC
30chip drivers in the directory @code{c/src/lib/lib/libchip/rtc}.
31There is a README file in this directory for each supported
32RTC chip.  Each of these README explains how to configure the
33shared libchip implementation of the RTC driver for that particular
34RTC chip.
35
36The DY-4 DMV177 BSP uses the shared libchip implementation of the RTC
37driver.  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
42The @code{rtc_initialize} routine is responsible for initializing the
43RTC chip so it can be used.  The shared libchip implementation of this
44driver supports multiple RTCs and bases its initialization order on
45the order the chips are defined in the @code{RTC_Table}.  Each chip
46defined in the table may or may not be present on this particular board.
47It is the responsibility of the @code{deviceProbe} to indicate the
48presence of a particular RTC chip.  The first RTC found to be present
49is considered the preferred RTC.
50
51In the shared libchip based implementation
52of the driver, the following actions are performed:
53
54@example
55@group
56rtems_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
83The @code{deviceProbe} routine returns TRUE if the device
84configured by this entry in the @code{RTC_Table} is present. 
85This configuration scheme allows one to support multiple versions
86of the same board with a single BSP.  For example, if the first
87generation of a board had Vendor A's RTC chip and the second
88generation had Vendor B's RTC chip, RTC_Table could contain
89information for both.  The @code{deviceProbe} configured
90for Vendor A's RTC chip would need to return TRUE if the
91board was a first generation one.  The @code{deviceProbe}
92routines are very board dependent.
93
94@section setRealTimeToRTEMS
95
96The @code{setRealTimeToRTEMS} routine sets the current RTEMS TOD to that
97of the preferred RTC. 
98
99@example
100@group
101void setRealTimeToRTEMS(void)
102@{
103  if no RTCs are present
104    return
105
106  invoke the deviceGetTime routine for the preferred RTC
107  set the RTEMS TOD using rtems_clock_set
108@}
109@end group
110@end example
111
112@section setRealTimeFromRTEMS
113
114The @code{setRealTimeFromRTEMS} routine sets the preferred RTC TOD to the
115current RTEMS TOD.
116
117@example
118@group
119void setRealTimeFromRTEMS(void)
120@{
121  if no RTCs are present
122    return
123
124  obtain the RTEMS TOD using rtems_clock_get
125  invoke the deviceSetTime routine for the preferred RTC
126@}
127@end group
128@end example
129
130@section getRealTime
131
132The @code{getRealTime} returns the preferred RTC TOD to the
133caller.
134
135@example
136@group
137void getRealTime( rtems_time_of_day *tod )
138@{
139  if no RTCs are present
140    return
141
142  invoke the deviceGetTime routine for the preferred RTC
143@}
144@end group
145@end example
146
147@section setRealTime
148
149The @code{setRealTime} routine sets the preferred RTC TOD to the
150TOD specified by the caller.
151
152@example
153@group
154void setRealTime( rtems_time_of_day *tod )
155@{
156  if no RTCs are present
157    return
158
159  invoke the deviceSetTime routine for the preferred RTC
160@}
161@end group
162@end example
163
164@section checkRealTime
165
166The @code{checkRealTime} routine returns the number of seconds
167difference between the RTC TOD and the current RTEMS TOD.
168
169@example
170@group
171int checkRealTime( void )
172@{
173  if no RTCs are present
174    return -1
175
176 
177  obtain the RTEMS TOD using rtems_clock_get
178  get the TOD from the preferred RTC using the deviceGetTime routine
179
180  convert the RTEMS TOD to seconds
181  convert the RTC TOD to seconds
182 
183  return the RTEMS TOD in seconds - RTC TOD in seconds
184@}
185@end group
186@end example
187
Note: See TracBrowser for help on using the repository browser.