LibDriver CS1238
Loading...
Searching...
No Matches
driver_cs1238_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static cs1238_handle_t gs_handle;
41
50{
51 uint8_t res;
52 cs1238_bool_t enable;
54 cs1238_pga_t pga;
55 cs1238_channel_t channel;
56 cs1238_info_t info;
57
58 /* link interface function */
70
71 /* get information */
72 res = cs1238_info(&info);
73 if (res != 0)
74 {
75 cs1238_interface_debug_print("cs1238: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 cs1238_interface_debug_print("cs1238: chip is %s.\n", info.chip_name);
83 cs1238_interface_debug_print("cs1238: manufacturer is %s.\n", info.manufacturer_name);
84 cs1238_interface_debug_print("cs1238: interface is %s.\n", info.interface);
85 cs1238_interface_debug_print("cs1238: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 cs1238_interface_debug_print("cs1238: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 cs1238_interface_debug_print("cs1238: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 cs1238_interface_debug_print("cs1238: max current is %0.2fmA.\n", info.max_current_ma);
89 cs1238_interface_debug_print("cs1238: max temperature is %0.1fC.\n", info.temperature_max);
90 cs1238_interface_debug_print("cs1238: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start register test */
94 cs1238_interface_debug_print("cs1238: start register test.\n");
95
96 /* init */
97 res = cs1238_init(&gs_handle);
98 if (res != 0)
99 {
100 cs1238_interface_debug_print("cs1238: init failed.\n");
101
102 return 1;
103 }
104
105 /* wake up */
106 res = cs1238_wake_up(&gs_handle);
107 if (res != 0)
108 {
109 cs1238_interface_debug_print("cs1238: wake up failed.\n");
110 (void)cs1238_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* cs1238_set_reference_voltage_output/cs1238_get_reference_voltage_output test */
116 cs1238_interface_debug_print("cs1238: cs1238_set_reference_voltage_output/cs1238_get_reference_voltage_output test.\n");
117
118 /* enable reference voltage output */
120 if (res != 0)
121 {
122 cs1238_interface_debug_print("cs1238: set reference voltage output failed.\n");
123 (void)cs1238_deinit(&gs_handle);
124
125 return 1;
126 }
127 cs1238_interface_debug_print("cs1238: enable reference voltage output.\n");
128 res = cs1238_get_reference_voltage_output(&gs_handle, &enable);
129 if (res != 0)
130 {
131 cs1238_interface_debug_print("cs1238: get reference voltage output failed.\n");
132 (void)cs1238_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* output */
138 cs1238_interface_debug_print("cs1238: check reference voltage output %s.\n", (enable == CS1238_BOOL_TRUE) ? "ok" : "error");
139
140 /* disable reference voltage output */
142 if (res != 0)
143 {
144 cs1238_interface_debug_print("cs1238: set reference voltage output failed.\n");
145 (void)cs1238_deinit(&gs_handle);
146
147 return 1;
148 }
149 cs1238_interface_debug_print("cs1238: disable reference voltage output.\n");
150 res = cs1238_get_reference_voltage_output(&gs_handle, &enable);
151 if (res != 0)
152 {
153 cs1238_interface_debug_print("cs1238: get reference voltage output failed.\n");
154 (void)cs1238_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* output */
160 cs1238_interface_debug_print("cs1238: check reference voltage output %s.\n", (enable == CS1238_BOOL_FALSE) ? "ok" : "error");
161
162 /* cs1238_set_adc_rate/cs1238_get_adc_rate test */
163 cs1238_interface_debug_print("cs1238: cs1238_set_adc_rate/cs1238_get_adc_rate test.\n");
164
165 /* set adc rate 10hz */
166 res = cs1238_set_adc_rate(&gs_handle, CS1238_ADC_RATE_10HZ);
167 if (res != 0)
168 {
169 cs1238_interface_debug_print("cs1238: set adc rate failed.\n");
170 (void)cs1238_deinit(&gs_handle);
171
172 return 1;
173 }
174 cs1238_interface_debug_print("cs1238: set adc rate 10hz.\n");
175 res = cs1238_get_adc_rate(&gs_handle, &rate);
176 if (res != 0)
177 {
178 cs1238_interface_debug_print("cs1238: get adc rate failed.\n");
179 (void)cs1238_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* output */
185 cs1238_interface_debug_print("cs1238: check adc rate %s.\n", (rate == CS1238_ADC_RATE_10HZ) ? "ok" : "error");
186
187 /* set adc rate 40hz */
188 res = cs1238_set_adc_rate(&gs_handle, CS1238_ADC_RATE_40HZ);
189 if (res != 0)
190 {
191 cs1238_interface_debug_print("cs1238: set adc rate failed.\n");
192 (void)cs1238_deinit(&gs_handle);
193
194 return 1;
195 }
196 cs1238_interface_debug_print("cs1238: set adc rate 40hz.\n");
197 res = cs1238_get_adc_rate(&gs_handle, &rate);
198 if (res != 0)
199 {
200 cs1238_interface_debug_print("cs1238: get adc rate failed.\n");
201 (void)cs1238_deinit(&gs_handle);
202
203 return 1;
204 }
205
206 /* output */
207 cs1238_interface_debug_print("cs1238: check adc rate %s.\n", (rate == CS1238_ADC_RATE_40HZ) ? "ok" : "error");
208
209 /* set adc rate 640hz */
211 if (res != 0)
212 {
213 cs1238_interface_debug_print("cs1238: set adc rate failed.\n");
214 (void)cs1238_deinit(&gs_handle);
215
216 return 1;
217 }
218 cs1238_interface_debug_print("cs1238: set adc rate 640hz.\n");
219 res = cs1238_get_adc_rate(&gs_handle, &rate);
220 if (res != 0)
221 {
222 cs1238_interface_debug_print("cs1238: get adc rate failed.\n");
223 (void)cs1238_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* output */
229 cs1238_interface_debug_print("cs1238: check adc rate %s.\n", (rate == CS1238_ADC_RATE_640HZ) ? "ok" : "error");
230
231 /* set adc rate 1280hz */
233 if (res != 0)
234 {
235 cs1238_interface_debug_print("cs1238: set adc rate failed.\n");
236 (void)cs1238_deinit(&gs_handle);
237
238 return 1;
239 }
240 cs1238_interface_debug_print("cs1238: set adc rate 1280hz.\n");
241 res = cs1238_get_adc_rate(&gs_handle, &rate);
242 if (res != 0)
243 {
244 cs1238_interface_debug_print("cs1238: get adc rate failed.\n");
245 (void)cs1238_deinit(&gs_handle);
246
247 return 1;
248 }
249
250 /* output */
251 cs1238_interface_debug_print("cs1238: check adc rate %s.\n", (rate == CS1238_ADC_RATE_1280HZ) ? "ok" : "error");
252
253 /* cs1238_set_pga/cs1238_get_pga test */
254 cs1238_interface_debug_print("cs1238: cs1238_set_pga/cs1238_get_pga test.\n");
255
256 /* set pga 1 */
257 res = cs1238_set_pga(&gs_handle, CS1238_PGA_1);
258 if (res != 0)
259 {
260 cs1238_interface_debug_print("cs1238: set pga failed.\n");
261 (void)cs1238_deinit(&gs_handle);
262
263 return 1;
264 }
265 cs1238_interface_debug_print("cs1238: set pga 1.\n");
266 res = cs1238_get_pga(&gs_handle, &pga);
267 if (res != 0)
268 {
269 cs1238_interface_debug_print("cs1238: get pga failed.\n");
270 (void)cs1238_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* output */
276 cs1238_interface_debug_print("cs1238: check pga %s.\n", (pga == CS1238_PGA_1) ? "ok" : "error");
277
278 /* set pga 2 */
279 res = cs1238_set_pga(&gs_handle, CS1238_PGA_2);
280 if (res != 0)
281 {
282 cs1238_interface_debug_print("cs1238: set pga failed.\n");
283 (void)cs1238_deinit(&gs_handle);
284
285 return 1;
286 }
287 cs1238_interface_debug_print("cs1238: set pga 2.\n");
288 res = cs1238_get_pga(&gs_handle, &pga);
289 if (res != 0)
290 {
291 cs1238_interface_debug_print("cs1238: get pga failed.\n");
292 (void)cs1238_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* output */
298 cs1238_interface_debug_print("cs1238: check pga %s.\n", (pga == CS1238_PGA_2) ? "ok" : "error");
299
300 /* set pga 64 */
301 res = cs1238_set_pga(&gs_handle, CS1238_PGA_64);
302 if (res != 0)
303 {
304 cs1238_interface_debug_print("cs1238: set pga failed.\n");
305 (void)cs1238_deinit(&gs_handle);
306
307 return 1;
308 }
309 cs1238_interface_debug_print("cs1238: set pga 64.\n");
310 res = cs1238_get_pga(&gs_handle, &pga);
311 if (res != 0)
312 {
313 cs1238_interface_debug_print("cs1238: get pga failed.\n");
314 (void)cs1238_deinit(&gs_handle);
315
316 return 1;
317 }
318
319 /* output */
320 cs1238_interface_debug_print("cs1238: check pga %s.\n", (pga == CS1238_PGA_64) ? "ok" : "error");
321
322 /* set pga 128 */
323 res = cs1238_set_pga(&gs_handle, CS1238_PGA_128);
324 if (res != 0)
325 {
326 cs1238_interface_debug_print("cs1238: set pga failed.\n");
327 (void)cs1238_deinit(&gs_handle);
328
329 return 1;
330 }
331 cs1238_interface_debug_print("cs1238: set pga 128.\n");
332 res = cs1238_get_pga(&gs_handle, &pga);
333 if (res != 0)
334 {
335 cs1238_interface_debug_print("cs1238: get pga failed.\n");
336 (void)cs1238_deinit(&gs_handle);
337
338 return 1;
339 }
340
341 /* output */
342 cs1238_interface_debug_print("cs1238: check pga %s.\n", (pga == CS1238_PGA_128) ? "ok" : "error");
343
344 /* cs1238_set_channel/cs1238_get_channel test */
345 cs1238_interface_debug_print("cs1238: cs1238_set_channel/cs1238_get_channel test.\n");
346
347 /* set channel short circuit */
349 if (res != 0)
350 {
351 cs1238_interface_debug_print("cs1238: set channel failed.\n");
352 (void)cs1238_deinit(&gs_handle);
353
354 return 1;
355 }
356 cs1238_interface_debug_print("cs1238: set channel short circuit.\n");
357 res = cs1238_get_channel(&gs_handle, &channel);
358 if (res != 0)
359 {
360 cs1238_interface_debug_print("cs1238: get channel failed.\n");
361 (void)cs1238_deinit(&gs_handle);
362
363 return 1;
364 }
365
366 /* output */
367 cs1238_interface_debug_print("cs1238: check channel %s.\n", (channel == CS1238_CHANNEL_SHORT_CIRCUIT) ? "ok" : "error");
368
369 /* set channel temperature */
371 if (res != 0)
372 {
373 cs1238_interface_debug_print("cs1238: set channel failed.\n");
374 (void)cs1238_deinit(&gs_handle);
375
376 return 1;
377 }
378 cs1238_interface_debug_print("cs1238: set channel temperature.\n");
379 res = cs1238_get_channel(&gs_handle, &channel);
380 if (res != 0)
381 {
382 cs1238_interface_debug_print("cs1238: get channel failed.\n");
383 (void)cs1238_deinit(&gs_handle);
384
385 return 1;
386 }
387
388 /* output */
389 cs1238_interface_debug_print("cs1238: check channel %s.\n", (channel == CS1238_CHANNEL_TEMPERATURE) ? "ok" : "error");
390
391 /* set channel b */
392 res = cs1238_set_channel(&gs_handle, CS1238_CHANNEL_B);
393 if (res != 0)
394 {
395 cs1238_interface_debug_print("cs1238: set channel failed.\n");
396 (void)cs1238_deinit(&gs_handle);
397
398 return 1;
399 }
400 cs1238_interface_debug_print("cs1238: set channel b.\n");
401 res = cs1238_get_channel(&gs_handle, &channel);
402 if (res != 0)
403 {
404 cs1238_interface_debug_print("cs1238: get channel failed.\n");
405 (void)cs1238_deinit(&gs_handle);
406
407 return 1;
408 }
409
410 /* output */
411 cs1238_interface_debug_print("cs1238: check channel %s.\n", (channel == CS1238_CHANNEL_B) ? "ok" : "error");
412
413 /* set channel a */
414 res = cs1238_set_channel(&gs_handle, CS1238_CHANNEL_A);
415 if (res != 0)
416 {
417 cs1238_interface_debug_print("cs1238: set channel failed.\n");
418 (void)cs1238_deinit(&gs_handle);
419
420 return 1;
421 }
422 cs1238_interface_debug_print("cs1238: set channel a.\n");
423 res = cs1238_get_channel(&gs_handle, &channel);
424 if (res != 0)
425 {
426 cs1238_interface_debug_print("cs1238: get channel failed.\n");
427 (void)cs1238_deinit(&gs_handle);
428
429 return 1;
430 }
431
432 /* output */
433 cs1238_interface_debug_print("cs1238: check channel %s.\n", (channel == CS1238_CHANNEL_A) ? "ok" : "error");
434
435 /* cs1238_wake_up test */
436 cs1238_interface_debug_print("cs1238: cs1238_wake_up test.\n");
437
438 /* wake up */
439 res = cs1238_wake_up(&gs_handle);
440 if (res != 0)
441 {
442 cs1238_interface_debug_print("cs1238: wake up failed.\n");
443 (void)cs1238_deinit(&gs_handle);
444
445 return 1;
446 }
447
448 /* output */
449 cs1238_interface_debug_print("cs1238: check wake up %s.\n", (res == 0) ? "ok" : "error");
450
451 /* cs1238_power_down test */
452 cs1238_interface_debug_print("cs1238: cs1238_wake_up test.\n");
453
454 /* power down */
455 res = cs1238_power_down(&gs_handle);
456 if (res != 0)
457 {
458 cs1238_interface_debug_print("cs1238: power down failed.\n");
459 (void)cs1238_deinit(&gs_handle);
460
461 return 1;
462 }
463
464 /* output */
465 cs1238_interface_debug_print("cs1238: check power down %s.\n", (res == 0) ? "ok" : "error");
466
467 /* finish register test */
468 cs1238_interface_debug_print("cs1238: finish register test.\n");
469 (void)cs1238_deinit(&gs_handle);
470
471 return 0;
472}
driver cs1238 register test header file
uint8_t cs1238_get_channel(cs1238_handle_t *handle, cs1238_channel_t *channel)
get adc channel
struct cs1238_handle_s cs1238_handle_t
cs1238 handle structure definition
uint8_t cs1238_wake_up(cs1238_handle_t *handle)
wake up
cs1238_bool_t
cs1238 bool enumeration definition
uint8_t cs1238_set_adc_rate(cs1238_handle_t *handle, cs1238_adc_rate_t rate)
set adc rate
uint8_t cs1238_get_pga(cs1238_handle_t *handle, cs1238_pga_t *pga)
get adc pga
cs1238_adc_rate_t
cs1238 adc rate enumeration definition
uint8_t cs1238_info(cs1238_info_t *info)
get chip's information
uint8_t cs1238_init(cs1238_handle_t *handle)
initialize the chip
uint8_t cs1238_set_pga(cs1238_handle_t *handle, cs1238_pga_t pga)
set adc pga
uint8_t cs1238_set_reference_voltage_output(cs1238_handle_t *handle, cs1238_bool_t enable)
enable or disable reference voltage output
struct cs1238_info_s cs1238_info_t
cs1238 information structure definition
uint8_t cs1238_get_adc_rate(cs1238_handle_t *handle, cs1238_adc_rate_t *rate)
get adc rate
uint8_t cs1238_get_reference_voltage_output(cs1238_handle_t *handle, cs1238_bool_t *enable)
get reference voltage output status
uint8_t cs1238_power_down(cs1238_handle_t *handle)
power down
cs1238_pga_t
cs1238 pga enumeration definition
uint8_t cs1238_deinit(cs1238_handle_t *handle)
close the chip
uint8_t cs1238_set_channel(cs1238_handle_t *handle, cs1238_channel_t channel)
set adc channel
cs1238_channel_t
cs1238 channel enumeration definition
@ CS1238_BOOL_FALSE
@ CS1238_BOOL_TRUE
@ CS1238_ADC_RATE_40HZ
@ CS1238_ADC_RATE_1280HZ
@ CS1238_ADC_RATE_10HZ
@ CS1238_ADC_RATE_640HZ
@ CS1238_PGA_2
@ CS1238_PGA_1
@ CS1238_PGA_64
@ CS1238_PGA_128
@ CS1238_CHANNEL_TEMPERATURE
@ CS1238_CHANNEL_B
@ CS1238_CHANNEL_A
@ CS1238_CHANNEL_SHORT_CIRCUIT
uint8_t cs1238_interface_sclk_gpio_deinit(void)
interface sclk gpio deinit
void cs1238_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t cs1238_interface_dout_gpio_read(uint8_t *level)
interface dout gpio read
uint8_t cs1238_interface_sclk_gpio_write(uint8_t level)
interface sclk gpio write
uint8_t cs1238_interface_dout_gpio_write(uint8_t level)
interface dout gpio write
uint8_t cs1238_interface_sclk_gpio_init(void)
interface sclk gpio init
uint8_t cs1238_interface_dout_gpio_init(void)
interface dout gpio init
uint8_t cs1238_interface_dout_gpio_deinit(void)
interface dout gpio deinit
void cs1238_interface_delay_us(uint32_t us)
interface delay us
void cs1238_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t cs1238_register_test(void)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]