1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2011-04-16 first version
9 */
10
11 #include <rtthread.h>
12
13 #define THREAD_STACK_SIZE 1024
14
15 #if 0
16 struct rt_semaphore sem1, sem2;
17 static struct rt_thread thread1;
18 rt_align(4)
19 static rt_uint8_t thread1_stack[THREAD_STACK_SIZE];
20 static struct rt_thread thread2;
21 rt_align(4)
22 static rt_uint8_t thread2_stack[THREAD_STACK_SIZE];
23
24 static void thread1_entry(void* parameter)
25 {
26 while (1)
27 {
28 rt_sem_release(&sem2);
29 rt_kprintf("thread1..: %s\n", rt_thread_self()->parent.name);
30 rt_sem_take(&sem1, RT_WAITING_FOREVER);
31 rt_kprintf("thread1..: %s\n", rt_thread_self()->parent.name);
32 }
33 }
34
35 static void thread2_entry(void* parameter)
36 {
37 while (1)
38 {
39 rt_sem_take(&sem2, RT_WAITING_FOREVER);
40 rt_kprintf("thread2--->: %s\n", rt_thread_self()->parent.name);
41 rt_sem_release(&sem1);
42 }
43 }
44
45 /* user application */
46 int rt_application_init()
47 {
48 rt_err_t result;
49
50 rt_sem_init(&sem1, "s1", 0, RT_IPC_FLAG_FIFO);
51 rt_sem_init(&sem2, "s2", 0, RT_IPC_FLAG_FIFO);
52
53 result = rt_thread_init(&thread1, "t1", thread1_entry, RT_NULL,
54 &thread1_stack[0], sizeof(thread1_stack), 10, 10);
55 if (result == RT_EOK)
56 rt_thread_startup(&thread1);
57
58 result = rt_thread_init(&thread2, "t2", thread2_entry, RT_NULL,
59 &thread2_stack[0], sizeof(thread2_stack), 18, 10);
60 if (result == RT_EOK)
61 rt_thread_startup(&thread2);
62
63 return 0;
64 }
65 #else
66 static struct rt_thread thread1;
67 rt_align(4)
68 static rt_uint8_t thread1_stack[THREAD_STACK_SIZE];
69 rt_timer_t ttimer;
70
thread1_entry(void * parameter)71 static void thread1_entry(void* parameter)
72 {
73 rt_uint32_t count = 0;
74 while (1)
75 {
76 rt_kprintf("%s: count = %d\n", rt_thread_self()->parent.name, count ++);
77
78 rt_thread_delay(10);
79 }
80 }
81
82 /* user application */
rt_application_init()83 int rt_application_init()
84 {
85 rt_err_t result;
86
87 result = rt_thread_init(&thread1, "t1", thread1_entry, RT_NULL,
88 &thread1_stack[0], sizeof(thread1_stack), 10, 10);
89
90 ttimer = &(thread1.thread_timer);
91 if (result == RT_EOK)
92 rt_thread_startup(&thread1);
93
94 return 0;
95 }
96 #endif
97