• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Talkweb 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 "ohos_run.h"
21 #include "cmsis_os2.h"
22 
thread_entry1(void)23 void thread_entry1(void)
24 {
25     int sum = 0;
26     while (1) {
27         printf("This is Niobe407 Thread1----%d\r\n", sum++);
28         usleep(500000);
29     }
30 }
31 
thread_entry2(void)32 void thread_entry2(void)
33 {
34     int sum = 0;
35     while (1) {
36         printf("This is Niobe407 Thread2----%d\r\n", sum++);
37         usleep(500000);
38     }
39 }
40 
OS_Thread_example(void)41 static void OS_Thread_example(void)
42 {
43     osThreadAttr_t attr;
44 
45     attr.name = "thread1";
46     attr.attr_bits = 0U;
47     attr.cb_mem = NULL;
48     attr.cb_size = 0U;
49     attr.stack_mem = NULL;
50     attr.stack_size = 1024 * 4;
51     attr.priority = 25;
52 
53     if (osThreadNew((osThreadFunc_t)thread_entry1, NULL, &attr) == NULL) {
54         printf("Failed to create thread1!\n");
55     }
56 
57     attr.name = "thread2";
58 
59     if (osThreadNew((osThreadFunc_t)thread_entry2, NULL, &attr) == NULL) {
60         printf("Failed to create thread2!\n");
61     }
62 }
63 
64 OHOS_APP_RUN(OS_Thread_example);
65