• 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  * Description: SYSTICK Sample Source. \n
16  *
17  * History: \n
18  * 2023-07-17, Create file. \n
19  */
20 #include "pinctrl.h"
21 #include "systick.h"
22 #include "common_def.h"
23 #include "soc_osal.h"
24 #include "app_init.h"
25 
26 #define SYSTICK_DELAY_S                2
27 #define SYSTICK_DELAY_MS               1000
28 #define SYSTICK_DELAY_US               20000
29 #define SYSTICK_TASK_DURATION_MS       500
30 
31 #define SYSTICK_TASK_PRIO              24
32 #define SYSTICK_TASK_STACK_SIZE        0x1000
33 
systick_task(const char * arg)34 static void *systick_task(const char *arg)
35 {
36     unused(arg);
37     uint64_t count_before_get_s;
38     uint64_t count_after_get_s;
39     uint64_t count_before_get_ms;
40     uint64_t count_after_get_ms;
41     uint64_t count_before_get_us;
42     uint64_t count_after_get_us;
43 
44     /* SYSTICK init. */
45     uapi_systick_init();
46 
47     while (1) {
48         osal_msleep(SYSTICK_TASK_DURATION_MS);
49         osal_printk("systick delay %ds!\r\n", SYSTICK_DELAY_S);
50         count_before_get_s = uapi_systick_get_s();
51         uapi_systick_delay_s(SYSTICK_DELAY_S);
52         count_after_get_s = uapi_systick_get_s();
53         osal_printk("count_after_get_s = %llu, count_before_get_s = %llu\r\n", count_after_get_s, count_before_get_s);
54         osal_printk("count_s = %llu\r\n", count_after_get_s - count_before_get_s);
55         if (count_after_get_s > count_before_get_s) {
56             osal_printk("systick get s work normall.\r\n");
57         }
58 
59         osal_printk("systick delay %dms!\r\n", SYSTICK_DELAY_MS);
60         count_before_get_ms = uapi_systick_get_ms();
61         uapi_systick_delay_ms(SYSTICK_DELAY_MS);
62         count_after_get_ms = uapi_systick_get_ms();
63         osal_printk("count_after_get_ms = %llu, count_before_get_ms = %llu\r\n", count_after_get_ms,
64                     count_before_get_ms);
65         osal_printk("count_ms = %llu\r\n", count_after_get_ms - count_before_get_ms);
66         if (count_after_get_ms > count_before_get_ms) {
67             osal_printk("systick get ms work normall.\r\n");
68         }
69 
70         osal_printk("systick delay %dus!\r\n", SYSTICK_DELAY_US);
71         count_before_get_us = uapi_systick_get_us();
72         uapi_systick_delay_us(SYSTICK_DELAY_US);
73         count_after_get_us = uapi_systick_get_us();
74         osal_printk("count_after_get_us = %llu, count_before_get_us = %llu\r\n", count_after_get_us,
75                     count_before_get_us);
76         osal_printk("count_us = %llu\r\n", count_after_get_us - count_before_get_us);
77         if (count_after_get_us > count_before_get_us) {
78             osal_printk("systick get us work normall.\r\n");
79         }
80     }
81 
82     return NULL;
83 }
84 
systick_entry(void)85 static void systick_entry(void)
86 {
87     osal_task *task_handle = NULL;
88     osal_kthread_lock();
89     task_handle = osal_kthread_create((osal_kthread_handler)systick_task, 0, "SystickTask", SYSTICK_TASK_STACK_SIZE);
90     if (task_handle != NULL) {
91         osal_kthread_set_priority(task_handle, SYSTICK_TASK_PRIO);
92         osal_kfree(task_handle);
93     }
94     osal_kthread_unlock();
95 }
96 
97 /* Run the systick_entry. */
98 app_run(systick_entry);