• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define APP_DEMO_ADC
17 #ifdef APP_DEMO_ADC
18 #include <app_demo_adc.h>
19 
20 hi_u16 g_adc_buf[ADC_TEST_LENGTH] = { 0 };
21 
test_para(hi_void)22 hi_void test_para(hi_void)
23 {
24     hi_u32 ret;
25     hi_u16 data = 0;
26     printf("********ADC Test Para Set Start********\n");
27     ret = hi_adc_read(HI_ADC_CHANNEL_BUTT, &data, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0);
28     if (ret == HI_ERR_ADC_PARAMETER_WRONG) {
29         printf("ADC TEST WRONG Channel SUCCESS!\n");
30     }
31     ret = hi_adc_read(HI_ADC_CHANNEL_7, HI_NULL, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0);
32     if (ret == HI_ERR_ADC_PARAMETER_WRONG) {
33         printf("ADC TEST WRONG Data point SUCCESS!\n");
34     }
35     ret = hi_adc_read(HI_ADC_CHANNEL_7, &data, HI_ADC_EQU_MODEL_BUTT, HI_ADC_CUR_BAIS_DEFAULT, 0);
36     if (ret == HI_ERR_ADC_PARAMETER_WRONG) {
37         printf("ADC TEST WRONG Average Algorithm SUCCESS!\n");
38     }
39     ret = hi_adc_read(HI_ADC_CHANNEL_7, &data, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_BUTT, 0);
40     if (ret == HI_ERR_ADC_PARAMETER_WRONG) {
41         printf("ADC TEST WRONG Analog Power Control SUCCESS!\n");
42     }
43     ret = hi_adc_read(HI_ADC_CHANNEL_7, &data, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0xFFF);
44     if (ret == HI_ERR_ADC_PARAMETER_WRONG) {
45         printf("ADC TEST WRONG Reset Count SUCCESS!\n");
46     }
47 }
48 
49 /* asic adc test  */
convert_to_voltage(hi_u32 data_len)50 hi_void convert_to_voltage(hi_u32 data_len)
51 {
52     hi_u32 i;
53     float vlt_max = 0;
54     float vlt_min = VLT_MIN;
55     hi_u16 vlt;
56     for (i = 0; i < data_len; i++) {
57         vlt = g_adc_buf[i];
58         float voltage = (float)vlt * 1.8 * 4 / 4096.0;  /* vlt * 1.8 * 4 / 4096.0: Convert code into voltage */
59         vlt_max = (voltage > vlt_max) ? voltage : vlt_max;
60         vlt_min = (voltage < vlt_min) ? voltage : vlt_min;
61     }
62     printf("vlt_min:%.3f, vlt_max:%.3f \n", vlt_min, vlt_max);
63 }
64 
app_demo_adc_test(hi_void)65 hi_void app_demo_adc_test(hi_void)
66 {
67     hi_u32 ret, i;
68     hi_u16 data;  /* 10 */
69     printf("ADC Test Start\n");
70 
71     memset_s(g_adc_buf, sizeof(g_adc_buf), 0x0, sizeof(g_adc_buf));
72     for (hi_u8 ch = 0; ch < HI_ADC_CHANNEL_BUTT; ch++) {
73         for (i = 0; i < ADC_TEST_LENGTH; i++) {
74             ret = hi_adc_read((hi_adc_channel_index)ch, &data, HI_ADC_EQU_MODEL_1, HI_ADC_CUR_BAIS_DEFAULT, 0);
75             if (ret != HI_ERR_SUCCESS) {
76                 printf("ADC Read Fail\n");
77                 return;
78             }
79             g_adc_buf[i] = data;
80         }
81         convert_to_voltage(ADC_TEST_LENGTH);
82     }
83     printf("ADC Test Channels End\n");
84 
85     memset_s(g_adc_buf, sizeof(g_adc_buf), 0x0, sizeof(g_adc_buf));
86     for (hi_u8 em = 0; em < HI_ADC_EQU_MODEL_BUTT; em++) {
87         for (i = 0; i < ADC_TEST_LENGTH; i++) {
88             ret = hi_adc_read(HI_ADC_CHANNEL_7, &data, (hi_adc_equ_model_sel)em, HI_ADC_CUR_BAIS_DEFAULT, 0);
89             if (ret != HI_ERR_SUCCESS) {
90                 printf("ADC Read Fail\n");
91                 return;
92             }
93             g_adc_buf[i] = data;
94         }
95         convert_to_voltage(ADC_TEST_LENGTH);
96     }
97     printf("ADC Test Average Mode End\n");
98 
99     memset_s(g_adc_buf, sizeof(g_adc_buf), 0x0, sizeof(g_adc_buf));
100     for (hi_u16 rc = 0; rc <= 0xFF0; rc += 0xF) {
101         for (i = 0; i < ADC_TEST_LENGTH; i++) {
102             ret = hi_adc_read(HI_ADC_CHANNEL_7, &data, HI_ADC_EQU_MODEL_8, HI_ADC_CUR_BAIS_DEFAULT, rc);
103             if (ret != HI_ERR_SUCCESS) {
104                 printf("ADC Read Fail\n");
105                 return;
106             }
107             g_adc_buf[i] = data;
108         }
109         convert_to_voltage(ADC_TEST_LENGTH);
110     }
111     printf("ADC Test Reset Count End\n");
112 
113     test_para();
114 
115     printf("ADC Test End!\n");
116 }
117 
118 #endif
119