1 /*
2 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
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
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19
20 #include "cmsis_os2.h"
21 #include "ohos_init.h"
22
23 #define THREAD_STACK_SIZE (1024 * 4)
24 #define THREAD_PRIO 25
25 #define THREAD_DELAY_1S 1000000
26 #define THREAD_DELAY_500MS 500000
27
28 /**
29 * @brief Thread1 entry
30 *
31 */
Thread1(void)32 void Thread1(void)
33 {
34 int sum = 0;
35
36 while (1) {
37 printf("This is BearPi-HM_Nano Thread1----%d\n", sum++);
38 usleep(THREAD_DELAY_1S);
39 }
40 }
41
42 /**
43 * @brief Thread2 entry
44 *
45 */
Thread2(void)46 void Thread2(void)
47 {
48 int sum = 0;
49
50 while (1) {
51 printf("This is BearPi-HM_Nano Thread2----%d\n", sum++);
52 usleep(THREAD_DELAY_500MS);
53 }
54 }
55
56 /**
57 * @brief Main Entry of the Thread Example
58 *
59 */
ThreadExample(void)60 static void ThreadExample(void)
61 {
62 osThreadAttr_t attr;
63
64 attr.name = "Thread1";
65 attr.attr_bits = 0U;
66 attr.cb_mem = NULL;
67 attr.cb_size = 0U;
68 attr.stack_mem = NULL;
69 attr.stack_size = THREAD_STACK_SIZE;
70 attr.priority = THREAD_PRIO;
71
72 // Create the Thread1 task
73 if (osThreadNew((osThreadFunc_t)Thread1, NULL, &attr) == NULL) {
74 printf("Failed to create Thread1!\n");
75 }
76
77 // Create the Thread2 task
78 attr.name = "Thread2";
79 if (osThreadNew((osThreadFunc_t)Thread2, NULL, &attr) == NULL) {
80 printf("Failed to create Thread2!\n");
81 }
82 }
83
84 APP_FEATURE_INIT(ThreadExample);
85