1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include "rx8130ce.h"
6 #include <stdint.h>
7 #if AOS_COMP_CLI
8 #include "aos/cli.h"
9 #endif
10
rx8130ce_comp_example(int argc,char ** argv)11 static void rx8130ce_comp_example(int argc, char **argv)
12 {
13 (void)argc;
14 (void)argv;
15
16 int ret = 0;
17 uint8_t data[7] = {8, 25, 18, 7, 3, 1, 21};
18 uint8_t data_rtn[7] = {0};
19 uint16_t size = 7;
20 uint8_t reg_rtn;
21
22 printf("\r\n=====RTC test : set rtc time for RX8130CE=====\r\n");
23
24 ret = rx8130ce_init();
25 if (ret) {
26 printf("=====RTC test : RX8130CE test: init FAIL=====\r\n");
27 ret = -1;
28 }
29
30 /*ret = hal_rtc_set_time(NULL, (rtc_time_t*)data);*/
31 ret = rx8130ce_set_time(data, sizeof(rtc_time_t));
32 if (ret) {
33 printf("=====RTC test : RX8130CE test: write FAIL=====\r\n");
34 ret = -1;
35 }
36
37 osDelay(3000);
38
39 printf("=====RTC test : RX8130CE test: get time=====\r\n");
40
41 /*ret = hal_rtc_get_time(NULL, (rtc_time_t*)data_rtn);*/
42 ret = rx8130ce_get_time(data_rtn, sizeof(rtc_time_t));
43 if (ret) {
44 printf("=====RTC test : RX8130CE test: write FAIL=====\r\n");
45 ret = -1;
46 }
47
48 printf("get time: %us %um %uh %uw %ud %um %uy\r\n", (unsigned int)data_rtn[0],
49 (unsigned int)data_rtn[1], (unsigned int)data_rtn[2],
50 (unsigned int)data_rtn[3], (unsigned int)data_rtn[4],
51 (unsigned int)data_rtn[5], (unsigned int)data_rtn[6]);
52
53 for (uint8_t i = 0; i < 7; i++) {
54 if (data[i] != data_rtn[i]) {
55 if (((data[0] + 2) == data_rtn[0]) || ((data[0] + 3) == data_rtn[0])) {
56 printf("=====RTC test : RX8130CE test: time is correct=====\r\n");
57 continue;
58 } else {
59 printf("=====RTC test : RX8130CE test: time is wrong, set %u, get %u "
60 "=====\r\n",
61 (unsigned int)data[0], (unsigned int)data_rtn[0]);
62 ret = -1;
63 }
64
65 if (i > 0) {
66 printf("=====RTC test : RX8130CE test: loopback FAIL=====\r\n");
67 ret = -1;
68 }
69 }
70 }
71
72 osDelay(20);
73
74 if (ret) {
75 printf("rx8130ce comp test failed!\r\n");
76 return -1;
77 } else {
78 printf("rx8130ce comp test success!\r\n");
79 return;
80 }
81 }
82
83 #if AOS_COMP_CLI
84 /* reg args: fun, cmd, description*/
85 ALIOS_CLI_CMD_REGISTER(rx8130ce_comp_example, rx8130ce_example,
86 rx8130ce component example)
87 #endif
88