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 * Description: ADC Sample Source. \n
16 *
17 * History: \n
18 * 2023-07-06, Create file. \n
19 */
20 #include "pinctrl.h"
21 #include "adc.h"
22 #include "adc_porting.h"
23 #include "common_def.h"
24 #include "soc_osal.h"
25 #include "app_init.h"
26 #include "tcxo.h"
27
28 #define DELAY_1000MS 1000
29 #define ADC_TASK_PRIO 26
30 #define ADC_TASK_STACK_SIZE 0x1000
31
32 #if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN)
test_adc_callback(uint8_t ch,uint32_t * buffer,uint32_t length,bool * next)33 static void test_adc_callback(uint8_t ch, uint32_t *buffer, uint32_t length, bool *next)
34 {
35 unused(next);
36 for (uint32_t i = 0; i < length; i++) {
37 osal_printk("[IRQ]channel: %d, voltage: %dmv\r\n", ch, buffer[i]);
38 }
39 }
40 #endif
41
adc_task(const char * arg)42 static void *adc_task(const char *arg)
43 {
44 unused(arg);
45 osal_printk("start adc sample\r\n");
46 #if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN)
47 uapi_adc_init(ADC_CLOCK_NONE);
48 uint8_t adc_channel = 0;
49 uapi_adc_power_en(AFE_GADC_MODE, true);
50 adc_scan_config_t config = {
51 .type = 0,
52 .threshold_l = 0.5,
53 .threshold_h = 1.5,
54 .freq = 0,
55 #if defined(CONFIG_ADC_SUPPORT_LONG_SAMPLE)
56 .long_sample_time = 0,
57 #endif
58 };
59 uapi_adc_auto_scan_ch_enable(adc_channel, config, test_adc_callback);
60 osal_mdelay(DELAY_1000MS);
61 uapi_adc_auto_scan_ch_disable(adc_channel);
62 #endif
63 return NULL;
64 }
65
adc_entry(void)66 static void adc_entry(void)
67 {
68 osal_task *task_handle = NULL;
69 osal_kthread_lock();
70 task_handle = osal_kthread_create((osal_kthread_handler)adc_task, 0, "AdcTask", ADC_TASK_STACK_SIZE);
71 if (task_handle != NULL) {
72 osal_kthread_set_priority(task_handle, ADC_TASK_PRIO);
73 }
74 osal_kthread_unlock();
75 }
76
77 /* Run the adc_entry. */
78 app_run(adc_entry);