LibDriver DS1307
Loading...
Searching...
No Matches
driver_ds1307_ram_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ds1307_handle_t gs_handle;
41static uint8_t gs_buf[56];
42static uint8_t gs_check_buf[56];
43
52uint8_t ds1307_ram_test(uint32_t times)
53{
54 uint8_t res;
55 uint32_t i;
56 uint8_t j;
57 ds1307_info_t info;
58
59 /* link functions */
67
68 /* get ds1307 info */
69 res = ds1307_info(&info);
70 if (res != 0)
71 {
72 ds1307_interface_debug_print("ds1307: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print ds1307 info */
79 ds1307_interface_debug_print("ds1307: chip is %s.\n", info.chip_name);
80 ds1307_interface_debug_print("ds1307: manufacturer is %s.\n", info.manufacturer_name);
81 ds1307_interface_debug_print("ds1307: interface is %s.\n", info.interface);
82 ds1307_interface_debug_print("ds1307: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 ds1307_interface_debug_print("ds1307: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 ds1307_interface_debug_print("ds1307: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 ds1307_interface_debug_print("ds1307: max current is %0.2fmA.\n", info.max_current_ma);
86 ds1307_interface_debug_print("ds1307: max temperature is %0.1fC.\n", info.temperature_max);
87 ds1307_interface_debug_print("ds1307: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start ram test */
91 ds1307_interface_debug_print("ds1307: start ram test.\n");
92
93 /* init ds1307 */
94 res = ds1307_init(&gs_handle);
95 if (res != 0)
96 {
97 ds1307_interface_debug_print("ds1307: init failed.\n");
98
99 return 1;
100 }
101
102 /* set oscillator */
103 res = ds1307_set_oscillator(&gs_handle, DS1307_BOOL_TRUE);
104 if (res != 0)
105 {
106 ds1307_interface_debug_print("ds1307: set oscillator failed.\n");
107 (void)ds1307_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 for (i = 0; i < times; i++)
113 {
114 /* rand the data */
115 for (j = 0; j < 56; j++)
116 {
117 gs_buf[j] = rand() & 0xFF;
118 }
119
120 /* write ram */
121 res = ds1307_write_ram(&gs_handle, 0x00, gs_buf, 56);
122 if (res != 0)
123 {
124 ds1307_interface_debug_print("ds1307: write ram failed.\n");
125 (void)ds1307_deinit(&gs_handle);
126
127 return 1;
128 }
129
130 /* read ram */
131 res = ds1307_read_ram(&gs_handle, 0x00, gs_check_buf, 56);
132 if (res != 0)
133 {
134 ds1307_interface_debug_print("ds1307: read ram failed.\n");
135 (void)ds1307_deinit(&gs_handle);
136
137 return 1;
138 }
139
140 /* check data */
141 for (j = 0; j < 56; j++)
142 {
143 if (gs_buf[j] != gs_check_buf[j])
144 {
145 ds1307_interface_debug_print("ds1307: check buffer failed.\n");
146 (void)ds1307_deinit(&gs_handle);
147
148 return 1;
149 }
150 }
151
152 /* output */
153 ds1307_interface_debug_print("ds1307: %d/%d check passed.\n", i + 1, times);
154 }
155
156 /* finish ram test */
157 ds1307_interface_debug_print("ds1307: finish ram test.\n");
158 (void)ds1307_deinit(&gs_handle);
159
160 return 0;
161}
driver ds1307 ram test header file
uint8_t ds1307_info(ds1307_info_t *info)
get chip's information
struct ds1307_info_s ds1307_info_t
ds1307 information structure definition
struct ds1307_handle_s ds1307_handle_t
ds1307 handle structure definition
uint8_t ds1307_read_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
read ram
uint8_t ds1307_set_oscillator(ds1307_handle_t *handle, ds1307_bool_t enable)
enable or disable the oscillator
uint8_t ds1307_init(ds1307_handle_t *handle)
initialize the chip
uint8_t ds1307_write_ram(ds1307_handle_t *handle, uint8_t addr, uint8_t *buf, uint8_t len)
write ram
uint8_t ds1307_deinit(ds1307_handle_t *handle)
close the chip
@ DS1307_BOOL_TRUE
void ds1307_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ds1307_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ds1307_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t ds1307_interface_iic_init(void)
interface iic bus init
uint8_t ds1307_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void ds1307_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ds1307_ram_test(uint32_t times)
ram test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]