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: TCXO Sample Source. \n
16 *
17 * History: \n
18 * 2023-07-17, Create file. \n
19 */
20 #include "tcxo.h"
21 #include "common_def.h"
22 #include "soc_osal.h"
23 #include "app_init.h"
24
25 #define TCXO_DELAY_MS 1000
26 #define TCXO_DELAY_US 20000
27 #define TCXO_TASK_DURATION_MS 500
28
29 #define TCXO_TASK_PRIO 24
30 #define TCXO_TASK_STACK_SIZE 0x1000
31
tcxo_task(const char * arg)32 static void *tcxo_task(const char *arg)
33 {
34 unused(arg);
35 uint64_t count_before_get_ms;
36 uint64_t count_after_get_ms;
37 uint64_t count_before_get_us;
38 uint64_t count_after_get_us;
39
40 /* TCXO init. */
41 uapi_tcxo_init();
42
43 while (1) {
44 osal_msleep(TCXO_TASK_DURATION_MS);
45 osal_printk("tcxo delay %dms!\r\n", TCXO_DELAY_MS);
46 count_before_get_ms = uapi_tcxo_get_ms();
47 uapi_tcxo_delay_ms(TCXO_DELAY_MS);
48 count_after_get_ms = uapi_tcxo_get_ms();
49 osal_printk("count_after_get_ms = %llu, count_before_get_ms = %llu\r\n", count_after_get_ms,
50 count_before_get_ms);
51 osal_printk("count_ms = %llu\r\n", count_after_get_ms - count_before_get_ms);
52 if (count_after_get_ms > count_before_get_ms) {
53 osal_printk("tcxo get ms work normall.\r\n");
54 }
55
56 osal_printk("tcxo delay %dus!\r\n", TCXO_DELAY_US);
57 count_before_get_us = uapi_tcxo_get_us();
58 uapi_tcxo_delay_us(TCXO_DELAY_US);
59 count_after_get_us = uapi_tcxo_get_us();
60 osal_printk("count_after_get_us = %llu, count_before_get_us = %llu\r\n", count_after_get_us,
61 count_before_get_us);
62 osal_printk("count_us = %llu\r\n", count_after_get_us - count_before_get_us);
63 if (count_after_get_us > count_before_get_us) {
64 osal_printk("tcxo get us work normall.\r\n");
65 }
66 }
67
68 return NULL;
69 }
70
tcxo_entry(void)71 static void tcxo_entry(void)
72 {
73 osal_task *task_handle = NULL;
74 osal_kthread_lock();
75 task_handle = osal_kthread_create((osal_kthread_handler)tcxo_task, 0, "TcxoTask", TCXO_TASK_STACK_SIZE);
76 if (task_handle != NULL) {
77 osal_kthread_set_priority(task_handle, TCXO_TASK_PRIO);
78 osal_kfree(task_handle);
79 }
80 osal_kthread_unlock();
81 }
82
83 /* Run the tcxo_entry. */
84 app_run(tcxo_entry);