source: rtems/c/src/lib/libbsp/shared/tod.c @ 6273201

4.115
Last change on this file since 6273201 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  Real Time Clock Driver Wrapper for Libchip
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 */
8
9#include <rtems.h>
10#include <rtems/rtc.h>
11#include <rtems/libio.h>
12
13#include <libchip/rtc.h>
14
15/*
16 *  Configuration Information
17 */
18
19extern size_t                     RTC_Count;
20extern rtems_device_minor_number  RTC_Minor;
21
22int RTC_Present;
23
24extern void setRealTimeToRTEMS(void);
25
26/*
27 *  rtc_initialize
28 *
29 *  Initialize the RTC driver
30 */
31
32rtems_device_driver rtc_initialize(
33  rtems_device_major_number  major,
34  rtems_device_minor_number  minor_arg,
35  void                      *arg
36)
37{
38  rtems_device_minor_number minor;
39  rtems_status_code status;
40
41  for (minor=0; minor < RTC_Count ; minor++) {
42    /*
43     * First perform the configuration dependent probe, then the
44     * device dependent probe
45     */
46
47    if (RTC_Table[minor].deviceProbe && RTC_Table[minor].deviceProbe(minor)) {
48      /*
49       * Use this device as the primary RTC
50       */
51      RTC_Minor = minor;
52      RTC_Present = 1;
53      break;
54    }
55  }
56
57  if ( !RTC_Present ) {
58    /*
59     * Failed to find an RTC -- this is not a fatal error.
60     */
61
62    return RTEMS_INVALID_NUMBER;
63  }
64
65  /*
66   *  Register and initialize the primary RTC's
67   */
68
69  status = rtems_io_register_name( RTC_DEVICE_NAME, major, RTC_Minor );
70  if (status != RTEMS_SUCCESSFUL) {
71    rtems_fatal_error_occurred(status);
72  }
73
74  RTC_Table[minor].pDeviceFns->deviceInitialize( RTC_Minor );
75
76  /*
77   *  Now initialize any secondary RTC's
78   */
79
80  for ( minor++ ; minor<RTC_Count ; minor++) {
81    /*
82     * First perform the configuration dependent probe, then the
83     * device dependent probe
84     */
85
86    if (RTC_Table[minor].deviceProbe && RTC_Table[minor].deviceProbe(minor)) {
87      status = rtems_io_register_name(
88        RTC_Table[minor].sDeviceName,
89        major,
90        minor );
91      if (status != RTEMS_SUCCESSFUL) {
92        rtems_fatal_error_occurred(status);
93      }
94
95      /*
96       * Initialize the hardware device.
97       */
98
99      RTC_Table[minor].pDeviceFns->deviceInitialize(minor);
100
101    }
102  }
103
104  setRealTimeToRTEMS();
105  return RTEMS_SUCCESSFUL;
106}
107
108rtems_device_driver rtc_read(
109  rtems_device_major_number  major,
110  rtems_device_minor_number  minor,
111  void *arg
112)
113{
114  int rv = 0;
115  rtems_libio_rw_args_t *rw = arg;
116  rtems_time_of_day *tod = (rtems_time_of_day *) rw->buffer;
117
118  rw->offset = 0;
119  rw->bytes_moved = 0;
120
121  if (!RTC_Present) {
122    return RTEMS_NOT_CONFIGURED;
123  }
124
125  if (rw->count != sizeof( rtems_time_of_day)) {
126    return RTEMS_INVALID_SIZE;
127  }
128
129  rv = RTC_Table [RTC_Minor].pDeviceFns->deviceGetTime(
130    RTC_Minor,
131    tod
132  );
133  if (rv != 0) {
134    return RTEMS_IO_ERROR;
135  }
136
137  rw->bytes_moved = rw->count;
138
139  return RTEMS_SUCCESSFUL;
140}
141
142rtems_device_driver rtc_write(
143  rtems_device_major_number  major,
144  rtems_device_minor_number  minor,
145  void *arg
146)
147{
148  int rv = 0;
149  rtems_libio_rw_args_t *rw = arg;
150  const rtems_time_of_day *tod = (const rtems_time_of_day *) rw->buffer;
151
152  rw->offset = 0;
153  rw->bytes_moved = 0;
154
155  if (!RTC_Present) {
156    return RTEMS_NOT_CONFIGURED;
157  }
158
159  if (rw->count != sizeof( rtems_time_of_day)) {
160    return RTEMS_INVALID_SIZE;
161  }
162
163  rv = RTC_Table [RTC_Minor].pDeviceFns->deviceSetTime(
164    RTC_Minor,
165    tod
166  );
167  if (rv != 0) {
168    return RTEMS_IO_ERROR;
169  }
170
171  rw->bytes_moved = rw->count;
172
173  return RTEMS_SUCCESSFUL;
174}
175
176rtems_device_driver rtc_open(
177  rtems_device_major_number major,
178  rtems_device_minor_number minor,
179  void *arg
180)
181{
182  return RTEMS_SUCCESSFUL;
183}
184
185rtems_device_driver rtc_close(
186  rtems_device_major_number major,
187  rtems_device_minor_number minor,
188  void *arg
189)
190{
191  return RTEMS_SUCCESSFUL;
192}
193
194rtems_device_driver rtc_control(
195  rtems_device_major_number major,
196  rtems_device_minor_number minor,
197  void *arg
198)
199{
200  return RTEMS_NOT_IMPLEMENTED;
201}
202
203/*PAGE
204 *
205 *  This routine copies the time from the real time clock to RTEMS
206 *
207 *  Input parameters:  NONE
208 *
209 *  Output parameters:  NONE
210 *
211 *  Return values: NONE
212 */
213
214void setRealTimeToRTEMS()
215{
216  rtems_time_of_day rtc_tod;
217
218  if (!RTC_Present)
219    return;
220
221  RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, &rtc_tod);
222  rtems_clock_set( &rtc_tod );
223}
224
225/*PAGE
226 *
227 *  setRealTimeFromRTEMS
228 *
229 *  This routine copies the time from RTEMS to the real time clock
230 *
231 *  Input parameters:  NONE
232 *
233 *  Output parameters:  NONE
234 *
235 *  Return values: NONE
236 */
237
238void setRealTimeFromRTEMS(void)
239{
240  rtems_time_of_day rtems_tod;
241
242  if (!RTC_Present)
243    return;
244
245  rtems_clock_get_tod( &rtems_tod );
246  RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, &rtems_tod);
247}
248
249/*PAGE
250 *
251 *  getRealTime
252 *
253 *  This routine reads the current time from the RTC.
254 *
255 *  Input parameters:  NONE
256 *
257 *  Output parameters:  NONE
258 *
259 *  Return values: NONE
260 */
261
262void getRealTime(
263  rtems_time_of_day *tod
264)
265{
266  if (!RTC_Present)
267    return;
268
269  RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, tod);
270}
271
272/*PAGE
273 *
274 *  setRealTime
275 *
276 *  This routine sets the RTC.
277 *
278 *  Input parameters:  NONE
279 *
280 *  Output parameters:  NONE
281 *
282 *  Return values: NONE
283 */
284int setRealTime(
285  const rtems_time_of_day *tod
286)
287{
288  if (!RTC_Present)
289    return -1;
290
291  if ( !_TOD_Validate(tod) )
292    return -1;
293
294  RTC_Table[RTC_Minor].pDeviceFns->deviceSetTime(RTC_Minor, tod);
295  return 0;
296}
297
298/*PAGE
299 *
300 *  checkRealTime
301 *
302 *  This routine reads the returns the variance betweent the real time and
303 *  rtems time.
304 *
305 *  Input parameters: NONE
306 *
307 *  Output parameters:  NONE
308 *
309 *  Return values:
310 *    int   The differance between the real time clock and rtems time.
311 */
312int checkRealTime(void)
313{
314  rtems_time_of_day rtems_tod;
315  rtems_time_of_day rtc_tod;
316  uint32_t   rtems_time;
317  uint32_t   rtc_time;
318
319  if (!RTC_Present)
320    return -1;
321
322  rtems_clock_get_tod( &rtems_tod );
323  RTC_Table[RTC_Minor].pDeviceFns->deviceGetTime(RTC_Minor, &rtc_tod);
324
325  rtems_time = _TOD_To_seconds( &rtems_tod );
326  rtc_time = _TOD_To_seconds( &rtc_tod );
327
328  return rtems_time - rtc_time;
329}
Note: See TracBrowser for help on using the repository browser.