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

5
Last change on this file since 350b07a0 was 4fb1b79, checked in by Sebastian Huber <sebastian.huber@…>, on 04/23/18 at 07:55:15

bsps: Move RTC drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

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