summaryrefslogtreecommitdiff
path: root/bsp/taihu/applications/application.c
blob: fde951b663cd4e3a506200815e9592ef1c96857e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Develop Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-04-16         first version
 */

#include <rtthread.h>

#define THREAD_STACK_SIZE	1024

#if 0
struct rt_semaphore sem1, sem2;
static struct rt_thread thread1;
ALIGN(4)
static rt_uint8_t thread1_stack[THREAD_STACK_SIZE];
static struct rt_thread thread2;
ALIGN(4)
static rt_uint8_t thread2_stack[THREAD_STACK_SIZE];

static void thread1_entry(void* parameter)
{
	while (1)
	{
		rt_sem_release(&sem2);
		rt_kprintf("thread1..: %s\n", rt_thread_self()->name);
		rt_sem_take(&sem1, RT_WAITING_FOREVER);
		rt_kprintf("get semaphore: %s!\n", rt_thread_self()->name);
	}
}

static void thread2_entry(void* parameter)
{
	while (1)
	{
		rt_sem_take(&sem2, RT_WAITING_FOREVER);
		rt_kprintf("thread2--->: %s\n", rt_thread_self()->name);
		rt_sem_release(&sem1);
	}
}

/* user application */
int rt_application_init()
{
	rt_err_t result;

	rt_sem_init(&sem1, "s1", 0, RT_IPC_FLAG_FIFO);
	rt_sem_init(&sem2, "s2", 0, RT_IPC_FLAG_FIFO);

	result = rt_thread_init(&thread1, "t1",	thread1_entry, RT_NULL,
		&thread1_stack[0], sizeof(thread1_stack), 10, 10);
	if (result == RT_EOK)
		rt_thread_startup(&thread1);

	result = rt_thread_init(&thread2, "t2", thread2_entry, RT_NULL,
		&thread2_stack[0], sizeof(thread2_stack), 18, 10);
	if (result == RT_EOK)
		rt_thread_startup(&thread2);

	return 0;
}
#else
static struct rt_thread thread1;
ALIGN(4)
static rt_uint8_t thread1_stack[THREAD_STACK_SIZE];
rt_timer_t ttimer;

static void thread1_entry(void* parameter)
{
	rt_uint32_t count = 0;
	while (1)
	{
		rt_kprintf("%s: count = %d\n", rt_thread_self()->name, count ++);

		rt_thread_delay(10);
	}
}

/* user application */
int rt_application_init()
{
	rt_err_t result;

	result = rt_thread_init(&thread1, "t1",	thread1_entry, RT_NULL,
		&thread1_stack[0], sizeof(thread1_stack), 10, 10);

	ttimer = &(thread1.thread_timer);
	if (result == RT_EOK)
		rt_thread_startup(&thread1);

	return 0;
}
#endif