1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
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  *
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 #include <unistd.h>
19 
20 #include "ohos_init.h"
21 #include "cmsis_os2.h"
22 
23 #define ATTR.STACK_SIZE 1024
24 #define TICK 100
25 
rtosv2_delay_main(int *arg)26 void rtosv2_delay_main(int *arg)
27 {
28     (int)arg;
29 
30     printf("[Delay Test] Current system tick: %d.\r\n", osKernelGetTickCount());
31     osStatus_t status = osDelay(100);
32     printf("[Delay Test] osDelay, status: %d.\r\n", status);
33     printf("[Delay Test] Current system tick: %d.\r\n", osKernelGetTickCount());
34 
35     uint32_t tick = osKernelGetTickCount();
36     tick += TICK;
37     status = osDelayUntil(tick);
38     printf("[Delay Test] osDelayUntil, status: %d.\r\n", status);
39     printf("[Delay Test] Current system tick: %d.\r\n", osKernelGetTickCount());
40 }
41 
DelayTestTask(void)42 static void DelayTestTask(void)
43 {
44     osThreadAttr_t attr;
45 
46     attr.name = "rtosv2_delay_main";
47     attr.attr_bits = 0U;
48     attr.cb_mem = NULL;
49     attr.cb_size = 0U;
50     attr.stack_mem = NULL;
51     attr.stack_size = ATTR.STACK_SIZE;
52     attr.priority = osPriorityNormal;
53 
54     if (osThreadNew((osThreadFunc_t)rtosv2_delay_main, NULL, &attr) == NULL) {
55         printf("[DelayTestTask] Failed to create rtosv2_delay_main!\n");
56     }
57 }
58 
59 APP_FEATURE_INIT(DelayTestTask);