1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include "aos/hal/rtc.h"
6 #include "rx8130ce.h"
7
8
9 /**
10 * This function will initialize the on board CPU real time clock
11 *
12 *
13 * @param[in] rtc rtc device
14 *
15 * @return 0 : on success, EIO : if an error occurred with any step
16 */
hal_rtc_init(rtc_dev_t * rtc)17 int32_t hal_rtc_init(rtc_dev_t *rtc)
18 {
19 int ret = 0;
20
21 ret = rx8130ce_init();
22 if(ret)
23 {
24 printf("board rtc init fail\r\n");
25 return -1;
26 }
27
28 return 0;
29 }
30
31 /**
32 * This function will return the value of time read from the on board CPU real time clock.
33 *
34 * @param[in] rtc rtc device
35 * @param[out] time pointer to a time structure
36 *
37 * @return 0 : on success, EIO : if an error occurred with any step
38 */
hal_rtc_get_time(rtc_dev_t * rtc,rtc_time_t * time)39 int32_t hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time)
40 {
41 int ret = 0;
42
43 ret = rx8130ce_get_time(time, sizeof(rtc_time_t));
44
45 if(ret)
46 {
47 printf("board rtc get time fail\r\n");
48 return -1;
49 }
50
51 return 0;
52 }
53
54 /**
55 * This function will set MCU RTC time to a new value.
56 *
57 * @param[in] rtc rtc device
58 * @param[out] time pointer to a time structure
59 *
60 * @return 0 : on success, EIO : if an error occurred with any step
61 */
hal_rtc_set_time(rtc_dev_t * rtc,const rtc_time_t * time)62 int32_t hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time)
63 {
64 int ret = 0;
65
66 ret = rx8130ce_set_time(time, sizeof(rtc_time_t));
67
68 if(ret)
69 {
70 printf("board rtc set time fail\r\n");
71 return -1;
72 }
73
74 return 0;
75 }
76
77 /**
78 * De-initialises an RTC interface, Turns off an RTC hardware interface
79 *
80 * @param[in] RTC the interface which should be de-initialised
81 *
82 * @return 0 : on success, EIO : if an error occurred with any step
83 */
hal_rtc_finalize(rtc_dev_t * rtc)84 int32_t hal_rtc_finalize(rtc_dev_t *rtc)
85 {
86 return 0;
87 }
88
89