LibDriver BA121
Loading...
Searching...
No Matches
driver_ba121_register_test.c
Go to the documentation of this file.
1
36
38
39static ba121_handle_t gs_handle;
40
49{
50 uint8_t res;
51 ba121_status_t status;
52 ba121_info_t info;
53
54 /* link interface function */
63
64 /* get ba121 information */
65 res = ba121_info(&info);
66 if (res != 0)
67 {
68 ba121_interface_debug_print("ba121: get info failed.\n");
69
70 return 1;
71 }
72 else
73 {
74 /* print chip information */
75 ba121_interface_debug_print("ba121: chip is %s.\n", info.chip_name);
76 ba121_interface_debug_print("ba121: manufacturer is %s.\n", info.manufacturer_name);
77 ba121_interface_debug_print("ba121: interface is %s.\n", info.interface);
78 ba121_interface_debug_print("ba121: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
79 ba121_interface_debug_print("ba121: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
80 ba121_interface_debug_print("ba121: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
81 ba121_interface_debug_print("ba121: max current is %0.2fmA.\n", info.max_current_ma);
82 ba121_interface_debug_print("ba121: max temperature is %0.1fC.\n", info.temperature_max);
83 ba121_interface_debug_print("ba121: min temperature is %0.1fC.\n", info.temperature_min);
84 }
85
86 /* start register test */
87 ba121_interface_debug_print("ba121: start register test.\n");
88
89 /* ba121 init */
90 res = ba121_init(&gs_handle);
91 if (res != 0)
92 {
93 ba121_interface_debug_print("ba121: init failed.\n");
94
95 return 1;
96 }
97
98 /* ba121_set_ntc_resistance test */
99 ba121_interface_debug_print("ba121: ba121_set_ntc_resistance test.\n");
100
101 /* set ntc resistance */
102 ba121_interface_debug_print("ba121: set ntc resistance 10k.\n");
103
104 /* set ntc resistance */
105 res = ba121_set_ntc_resistance(&gs_handle, 10 * 1000);
106 if (res != 0)
107 {
108 ba121_interface_debug_print("ba121: set ntc resistance failed.\n");
109 (void)ba121_deinit(&gs_handle);
110
111 return 1;
112 }
113 ba121_interface_debug_print("ba121: check ntc resistance %s.\n", res == 0 ? "ok" : "error");
114
115 /* ba121_set_ntc_b test */
116 ba121_interface_debug_print("ba121: ba121_set_ntc_b test.\n");
117
118 /* set ntc b */
119 ba121_interface_debug_print("ba121: set ntc b 3435.\n");
120
121 /* set ntc b */
122 res = ba121_set_ntc_b(&gs_handle, 3435);
123 if (res != 0)
124 {
125 ba121_interface_debug_print("ba121: set ntc b failed.\n");
126 (void)ba121_deinit(&gs_handle);
127
128 return 1;
129 }
130 ba121_interface_debug_print("ba121: check ntc b %s.\n", res == 0 ? "ok" : "error");
131
132#if (BA121_ENABLE_BASELINE_TEST != 0)
133 /* ba121_baseline_calibration test */
134 ba121_interface_debug_print("ba121: ba121_baseline_calibration test.\n");
135
136 /* baseline calibration */
137 ba121_interface_debug_print("ba121: baseline calibration.\n");
138
139 /* baseline calibration */
140 res = ba121_baseline_calibration(&gs_handle);
141 if (res != 0)
142 {
143 ba121_interface_debug_print("ba121: baseline calibration failed.\n");
144 (void)ba121_deinit(&gs_handle);
145
146 return 1;
147 }
148 ba121_interface_debug_print("ba121: check baseline calibration %s.\n", res == 0 ? "ok" : "error");
149#endif
150
151 /* ba121_get_last_status test */
152 ba121_interface_debug_print("ba121: ba121_get_last_status test.\n");
153
154 /* get last status */
155 res = ba121_get_last_status(&gs_handle, &status);
156 if (res != 0)
157 {
158 ba121_interface_debug_print("ba121: get last status failed.\n");
159 (void)ba121_deinit(&gs_handle);
160
161 return 1;
162 }
163 ba121_interface_debug_print("ba121: last status is 0x%02X.\n", (uint8_t)status);
164
165 /* finish register test */
166 ba121_interface_debug_print("ba121: finish register test.\n");
167 (void)ba121_deinit(&gs_handle);
168
169 return 0;
170}
driver ba121 register test header file
struct ba121_handle_s ba121_handle_t
ba121 handle structure definition
uint8_t ba121_baseline_calibration(ba121_handle_t *handle)
baseline calibration
uint8_t ba121_get_last_status(ba121_handle_t *handle, ba121_status_t *status)
get last status
uint8_t ba121_init(ba121_handle_t *handle)
initialize the chip
struct ba121_info_s ba121_info_t
ba121 information structure definition
uint8_t ba121_info(ba121_info_t *info)
get chip's information
ba121_status_t
ba121 status enumeration definition
uint8_t ba121_set_ntc_resistance(ba121_handle_t *handle, uint32_t ohm)
set ntc resistance
uint8_t ba121_set_ntc_b(ba121_handle_t *handle, uint16_t value)
set ntc b
uint8_t ba121_deinit(ba121_handle_t *handle)
close the chip
uint8_t ba121_interface_uart_flush(void)
interface uart flush
void ba121_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ba121_interface_uart_deinit(void)
interface uart deinit
void ba121_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ba121_interface_uart_init(void)
interface uart init
uint8_t ba121_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint16_t ba121_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t ba121_register_test(void)
register test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]