source: rtems/bsps/arm/atsam/rtc/rtc-config.c @ ba619b7f

Last change on this file since ba619b7f was ba619b7f, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:20

bsps/arm/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH
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.org/license/LICENSE.
7 */
8
9#include <libchip/chip.h>
10#include <libchip/rtc.h>
11
12#include <bsp.h>
13
14#define ARBITRARY_DAY_OF_WEEK 1
15
16void atsam_rtc_get_time(rtems_time_of_day *tod)
17{
18  Rtc *rtc = RTC;
19  uint8_t hour;
20  uint8_t minute;
21  uint8_t second;
22  uint16_t year;
23  uint8_t month;
24  uint8_t day;
25  uint8_t week;
26
27  RTC_GetDate(rtc, &year, &month, &day, &week);
28  RTC_GetTime(rtc, &hour, &minute, &second);
29
30  tod->ticks = 0;
31  tod->second = second;
32  tod->minute = minute;
33  tod->hour = hour;
34  tod->day = day;
35  tod->month = month;
36  tod->year = year;
37}
38
39static void atsam_rtc_device_initialize(int minor)
40{
41  Rtc *rtc = RTC;
42
43  RTC_DisableIt(rtc, 0x1F);
44}
45
46static int atsam_rtc_device_get_time(int minor, rtems_time_of_day *tod)
47{
48  atsam_rtc_get_time(tod);
49
50  return 0;
51}
52
53static int atsam_rtc_device_set_time(int minor, const rtems_time_of_day *tod)
54{
55  Rtc *rtc = RTC;
56  uint8_t hour;
57  uint8_t minute;
58  uint8_t second;
59  uint16_t year;
60  uint8_t month;
61  uint8_t day;
62  uint8_t week;
63
64  second = (uint8_t) tod->second;
65  minute = (uint8_t) tod->minute;
66  hour = (uint8_t) tod->hour;
67  day = (uint8_t) tod->day;
68  month = (uint8_t) tod->month;
69  week = ARBITRARY_DAY_OF_WEEK;
70  year = (uint16_t) tod->year;
71
72  RTC_SetDate(rtc, year, month, day, week);
73  RTC_SetTime(rtc, hour, minute, second);
74
75  return 0;
76}
77
78static bool atsam_rtc_device_probe(int minor)
79{
80  return true;
81}
82
83const rtc_fns atsam_rtc_device_ops = {
84  .deviceInitialize = atsam_rtc_device_initialize,
85  .deviceGetTime = atsam_rtc_device_get_time,
86  .deviceSetTime = atsam_rtc_device_set_time
87};
88
89rtc_tbl RTC_Table[] = {
90  {
91    .sDeviceName = "/dev/rtc",
92    .deviceType = RTC_CUSTOM,
93    .pDeviceFns = &atsam_rtc_device_ops,
94    .deviceProbe = atsam_rtc_device_probe
95  }
96};
97
98size_t RTC_Count = RTEMS_ARRAY_SIZE(RTC_Table);
Note: See TracBrowser for help on using the repository browser.