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 // 参数:延时时间,如果设置为1000,表示延时1000ms(1s);返回值:osStatus。
33 printf("[Delay Test] osDelay, status: %d.\r\n", status);
34 printf("[Delay Test] Current system tick: %d.\r\n", osKernelGetTickCount());
35
36 uint32_t tick = osKernelGetTickCount();
37 tick += TICK;
38 status = osDelayUntil(tick);
39 printf("[Delay Test] osDelayUntil, status: %d.\r\n", status);
40 printf("[Delay Test] Current system tick: %d.\r\n", osKernelGetTickCount());
41 }
42
DelayTestTask(void)43 static void DelayTestTask(void)
44 {
45 osThreadAttr_t attr;
46
47 attr.name = "rtosv2_delay_main";
48 attr.attr_bits = 0U;
49 attr.cb_mem = NULL;
50 attr.cb_size = 0U;
51 attr.stack_mem = NULL;
52 attr.stack_size = ATTR.STACK_SIZE;
53 attr.priority = osPriorityNormal;
54
55 if (osThreadNew((osThreadFunc_t)rtosv2_delay_main, NULL, &attr) == NULL) {
56 printf("[DelayTestTask] Failed to create rtosv2_delay_main!\n");
57 }
58 }
59
60 APP_FEATURE_INIT(DelayTestTask);