source: rtems/doc/bsp_howto/rtc.t @ 0660b4f8

4.104.114.84.95
Last change on this file since 0660b4f8 was 0660b4f8, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 19:50:56

Changed copyright date to 1999.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-1999.
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 and must be provided by
93the BSP.
94
95@section setRealTimeToRTEMS
96
97The @code{setRealTimeToRTEMS} routine sets the current RTEMS TOD to that
98of the preferred RTC. 
99
100@example
101@group
102void 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
115The @code{setRealTimeFromRTEMS} routine sets the preferred RTC TOD to the
116current RTEMS TOD.
117
118@example
119@group
120void 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
133The @code{getRealTime} returns the preferred RTC TOD to the
134caller.
135
136@example
137@group
138void 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
150The @code{setRealTime} routine sets the preferred RTC TOD to the
151TOD specified by the caller.
152
153@example
154@group
155void 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
167The @code{checkRealTime} routine returns the number of seconds
168difference between the RTC TOD and the current RTEMS TOD.
169
170@example
171@group
172int 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
Note: See TracBrowser for help on using the repository browser.