LibDriver MB85RCXX
Loading...
Searching...
No Matches
driver_mb85rcxx_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static mb85rcxx_handle_t gs_handle;
41
52{
53 uint8_t res, i, j;
54 uint8_t buf[12];
55 uint8_t buf_check[12];
56 uint32_t inc;
57 mb85rcxx_info_t info;
58
59 /* link interface function */
69
70 /* get information */
71 res = mb85rcxx_info(&info);
72 if (res != 0)
73 {
74 mb85rcxx_interface_debug_print("mb85rcxx: get info failed.\n");
75
76 return 1;
77 }
78 else
79 {
80 /* print chip information */
81 mb85rcxx_interface_debug_print("mb85rcxx: chip is %s.\n", info.chip_name);
82 mb85rcxx_interface_debug_print("mb85rcxx: manufacturer is %s.\n", info.manufacturer_name);
83 mb85rcxx_interface_debug_print("mb85rcxx: interface is %s.\n", info.interface);
84 mb85rcxx_interface_debug_print("mb85rcxx: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
85 mb85rcxx_interface_debug_print("mb85rcxx: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
86 mb85rcxx_interface_debug_print("mb85rcxx: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
87 mb85rcxx_interface_debug_print("mb85rcxx: max current is %0.2fmA.\n", info.max_current_ma);
88 mb85rcxx_interface_debug_print("mb85rcxx: max temperature is %0.1fC.\n", info.temperature_max);
89 mb85rcxx_interface_debug_print("mb85rcxx: min temperature is %0.1fC.\n", info.temperature_min);
90 }
91
92 /* set chip type */
93 res = mb85rcxx_set_type(&gs_handle, type);
94 if (res != 0)
95 {
96 mb85rcxx_interface_debug_print("mb85rcxx: set type failed.\n");
97
98 return 1;
99 }
100
101 /* set iic addr pin */
102 res = mb85rcxx_set_addr_pin(&gs_handle, address);
103 if (res != 0)
104 {
105 mb85rcxx_interface_debug_print("mb85rcxx: set address pin failed.\n");
106
107 return 1;
108 }
109
110 /* mb85rcxx init */
111 res = mb85rcxx_init(&gs_handle);
112 if (res != 0)
113 {
114 mb85rcxx_interface_debug_print("mb85rcxx: init failed.\n");
115
116 return 1;
117 }
118
119 /* start read test */
120 mb85rcxx_interface_debug_print("mb85rcxx: start read test.\n");
121 inc = ((uint32_t)type + 1) / 8;
122 for (i = 0; i < 8; i++)
123 {
124 for (j = 0; j < 12; j++)
125 {
126 buf[j] = (uint8_t)(rand() % 256);
127 }
128
129 /* write data */
130 res = mb85rcxx_write(&gs_handle, i*inc, (uint8_t *)buf, 12);
131 if (res != 0)
132 {
133 mb85rcxx_interface_debug_print("mb85rcxx: write failed.\n");
134 (void)mb85rcxx_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* read data */
140 res = mb85rcxx_read(&gs_handle, i*inc, (uint8_t *)buf_check, 12);
141 if (res != 0)
142 {
143 mb85rcxx_interface_debug_print("mb85rcxx: read failed.\n");
144 (void)mb85rcxx_deinit(&gs_handle);
145
146 return 1;
147 }
148 for (j = 0; j < 12; j++)
149 {
150 /* check data */
151 if (buf[j] != buf_check[j])
152 {
153 mb85rcxx_interface_debug_print("mb85rcxx: check error.\n");
154 (void)mb85rcxx_deinit(&gs_handle);
155
156 return 1;
157 }
158 }
159 mb85rcxx_interface_debug_print("mb85rcxx: 0x%04X read write test passed.\n", i*inc);
160 }
161
162 /* finish read test */
163 mb85rcxx_interface_debug_print("mb85rcxx: finish read test.\n");
164 (void)mb85rcxx_deinit(&gs_handle);
165
166 return 0;
167}
driver mb85rcxx read test header file
uint8_t mb85rcxx_deinit(mb85rcxx_handle_t *handle)
close the chip
uint8_t mb85rcxx_set_addr_pin(mb85rcxx_handle_t *handle, mb85rcxx_address_t addr_pin)
set the chip address pin
mb85rcxx_address_t
mb85rcxx address enumeration definition
mb85rcxx_t
mb85rcxx type enumeration definition
struct mb85rcxx_info_s mb85rcxx_info_t
mb85rcxx information structure definition
uint8_t mb85rcxx_write(mb85rcxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len)
write bytes to the chip
uint8_t mb85rcxx_info(mb85rcxx_info_t *info)
get chip's information
uint8_t mb85rcxx_set_type(mb85rcxx_handle_t *handle, mb85rcxx_t type)
set the chip type
uint8_t mb85rcxx_init(mb85rcxx_handle_t *handle)
initialize the chip
uint8_t mb85rcxx_read(mb85rcxx_handle_t *handle, uint32_t address, uint8_t *buf, uint16_t len)
read bytes from the chip
struct mb85rcxx_handle_s mb85rcxx_handle_t
mb85rcxx handle structure definition
uint8_t mb85rcxx_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void mb85rcxx_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t mb85rcxx_interface_iic_init(void)
interface iic bus init
uint8_t mb85rcxx_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mb85rcxx_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mb85rcxx_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
uint8_t mb85rcxx_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
void mb85rcxx_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t mb85rcxx_read_test(mb85rcxx_t type, mb85rcxx_address_t address)
read test
char manufacturer_name[32]