Skip to content

Commit f7fb8f7

Browse files
author
FindHao
committed
init
0 parents  commit f7fb8f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+41115
-0
lines changed

09-ucos-sem.pptx

1.06 MB
Binary file not shown.
3.86 MB
Binary file not shown.

Examples/POSIX/GNU/OS3/app.c

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
/*
2+
*********************************************************************************************************
3+
* EXAMPLE CODE
4+
*
5+
* (c) Copyright 2003-2013; Micrium, Inc.; Weston, FL
6+
*
7+
* All rights reserved. Protected by international copyright laws.
8+
* Knowledge of the source code may NOT be used to develop a similar product.
9+
* Please help us continue to provide the Embedded community with the finest
10+
* software available. Your honesty is greatly appreciated.
11+
*********************************************************************************************************
12+
*/
13+
14+
/*
15+
*********************************************************************************************************
16+
*
17+
* EXAMPLE CODE
18+
*
19+
* uC/OS-III on POSIX
20+
*
21+
*
22+
* Filename : app.c
23+
* Version : V1.00
24+
* Programmer(s) : DC
25+
* SB
26+
*********************************************************************************************************
27+
*/
28+
29+
/*
30+
*********************************************************************************************************
31+
* INCLUDE FILES
32+
*********************************************************************************************************
33+
*/
34+
35+
#include <app_cfg.h>
36+
#include <os.h>
37+
#include <stdio.h>
38+
39+
#include <lib_mem.h>
40+
#include <lib_math.h>
41+
42+
43+
/*
44+
*********************************************************************************************************
45+
* LOCAL DEFINES
46+
*********************************************************************************************************
47+
*/
48+
49+
50+
/*
51+
*********************************************************************************************************
52+
* LOCAL GLOBAL VARIABLES
53+
*********************************************************************************************************
54+
*/
55+
56+
static OS_TCB App_TaskStartTCB;
57+
static OS_TCB App_ProducerTCB;
58+
static OS_TCB App_ConsumerTCB;
59+
static OS_TCB App_Consumer2TCB;
60+
static CPU_STK App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
61+
static CPU_STK AppProducer_Stk[128];
62+
static CPU_STK AppConsumer_Stk[128];
63+
static CPU_STK AppConsumer2_Stk[128];
64+
OS_SEM sem_full; OS_SEM sem_empty;
65+
66+
/*
67+
*********************************************************************************************************
68+
* LOCAL FUNCTION PROTOTYPES
69+
*********************************************************************************************************
70+
*/
71+
72+
static void App_TaskStart (void *p_arg);
73+
static void producer(void * p_arg);
74+
static void consumer(void * p_arg);
75+
static void consumer2(void * p_arg);
76+
/*
77+
*********************************************************************************************************
78+
* main()
79+
*
80+
* Description : This is the standard entry point for C code. It is assumed that your code will call
81+
* main() once you have performed all necessary initialization.
82+
*
83+
* Argument(s) : none.
84+
*
85+
* Return(s) : none.
86+
*
87+
* Caller(s) : This the main standard entry point.
88+
*
89+
* Note(s) : none.
90+
*********************************************************************************************************
91+
*/
92+
93+
int main (void)
94+
{
95+
OS_ERR err;
96+
97+
OSInit(&err); /* Initialize "uC/OS-III, The Real-Time Kernel" */
98+
99+
OSTaskCreate((OS_TCB *)&App_TaskStartTCB, /* Create the start task */
100+
(CPU_CHAR *)"App Task Start",
101+
(OS_TASK_PTR ) App_TaskStart,
102+
(void *) 0,
103+
(OS_PRIO ) APP_CFG_TASK_START_PRIO,
104+
(CPU_STK *)&App_TaskStartStk[0],
105+
(CPU_STK )(APP_CFG_TASK_START_STK_SIZE / 10u),
106+
(CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE,
107+
(OS_MSG_QTY ) 0,
108+
(OS_TICK ) 0,
109+
(void *) 0,
110+
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
111+
(OS_ERR *)&err);
112+
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
113+
114+
while(DEF_ON){ /* Should Never Get Here */
115+
printf("永远不出现");
116+
};
117+
}
118+
119+
120+
void producer (void *p_arg)
121+
{
122+
OS_ERR err;
123+
CPU_TS ts;
124+
while (DEF_ON) {
125+
OSSemPend(&sem_empty, 0,OS_OPT_PEND_BLOCKING,&ts,&err);
126+
OSSemPost(&sem_full, OS_OPT_POST_1 ,&err);
127+
printf("生产者:食物数量:%d\t", sem_full.Ctr);
128+
OSTimeDlyHMSM(0u, 0u, 1u, 0u,
129+
OS_OPT_TIME_HMSM_STRICT,
130+
&err);
131+
/* Check ’err” */
132+
}
133+
}
134+
135+
136+
void consumer (void *p_arg)
137+
{
138+
OS_ERR err;
139+
CPU_TS ts;
140+
141+
while (DEF_ON) {
142+
OSSemPend(&sem_full, 0,OS_OPT_PEND_BLOCKING,&ts,&err);
143+
OSSemPost(&sem_empty, OS_OPT_POST_1 ,&err);
144+
printf("消费者:食物数量:%d\t", sem_full.Ctr);
145+
OSTimeDlyHMSM(0u, 0u, 2u, 0u,
146+
OS_OPT_TIME_HMSM_STRICT,
147+
&err);
148+
/* Check ’err” */
149+
}
150+
}
151+
void consumer2 (void *p_arg)
152+
{
153+
OS_ERR err;
154+
CPU_TS ts;
155+
156+
while (DEF_ON) {
157+
OSSemPend(&sem_full, 0,OS_OPT_PEND_BLOCKING,&ts,&err);
158+
OSSemPost(&sem_empty, OS_OPT_POST_1 ,&err);
159+
printf("消费者2:食物数量:%d\t", sem_full.Ctr );
160+
OSTimeDlyHMSM(0u, 0u, 3u, 0u,
161+
OS_OPT_TIME_HMSM_STRICT,
162+
&err);
163+
/* Check ’err” */
164+
}
165+
}
166+
/*
167+
*********************************************************************************************************
168+
* App_TaskStart()
169+
*
170+
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
171+
* initialize the ticker only once multitasking has started.
172+
*
173+
* Argument(s) : p_arg is the argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
174+
*
175+
* Return(s) : none.
176+
*
177+
* Caller(s) : This is a task.
178+
*
179+
* Notes : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
180+
* used. The compiler should not generate any code for this statement.
181+
*********************************************************************************************************
182+
*/
183+
184+
static void App_TaskStart (void *p_arg)
185+
{
186+
OS_ERR os_err;
187+
188+
(void)p_arg; /* See Note #1 */
189+
190+
CPU_Init();
191+
Mem_Init(); /* Initialize the Memory Management Module */
192+
Math_Init(); /* Initialize the Mathematical Module */
193+
OS_CPU_SysTickInit();
194+
OSSemCreate(&sem_full, "full", 0, &os_err);
195+
OSSemCreate(&sem_empty, "empty", 10, &os_err);
196+
OSTaskCreate((OS_TCB *)&App_ProducerTCB, /* Create the start task */
197+
(CPU_CHAR *)"Producer Start",
198+
(OS_TASK_PTR ) producer,
199+
(void *) 0,
200+
(OS_PRIO ) 13,
201+
(CPU_STK *)&AppProducer_Stk[0],
202+
(CPU_STK )0,
203+
(CPU_STK_SIZE) 128,
204+
(OS_MSG_QTY ) 0,
205+
(OS_TICK ) 0,
206+
(void *) 0,
207+
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
208+
(OS_ERR *)&os_err);
209+
OSTaskCreate((OS_TCB *)&App_ConsumerTCB, /* Create the start task */
210+
(CPU_CHAR *)"Consumer Start",
211+
(OS_TASK_PTR ) consumer,
212+
(void *) 0,
213+
(OS_PRIO ) 15,
214+
(CPU_STK *)&AppConsumer_Stk[0],
215+
(CPU_STK )0,
216+
(CPU_STK_SIZE) 128,
217+
(OS_MSG_QTY ) 0,
218+
(OS_TICK ) 0,
219+
(void *) 0,
220+
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
221+
(OS_ERR *)&os_err);
222+
OSTaskCreate((OS_TCB *)&App_Consumer2TCB, /* Create the start task */
223+
(CPU_CHAR *)"Consumer2 Start",
224+
(OS_TASK_PTR ) consumer2,
225+
(void *) 0,
226+
(OS_PRIO ) 16,
227+
(CPU_STK *)&AppConsumer2_Stk[0],
228+
(CPU_STK )0,
229+
(CPU_STK_SIZE) 128,
230+
(OS_MSG_QTY ) 0,
231+
(OS_TICK ) 0,
232+
(void *) 0,
233+
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
234+
(OS_ERR *)&os_err);
235+
236+
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
237+
printf("\nuCOS-III is running.\n");
238+
OSTimeDlyHMSM(0u, 0u, 1u, 0u,
239+
OS_OPT_TIME_HMSM_STRICT,
240+
&os_err);
241+
242+
}
243+
}
244+
245+
246+

Examples/POSIX/GNU/OS3/app_cfg.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
*********************************************************************************************************
3+
* EXAMPLE CODE
4+
*
5+
* (c) Copyright 2009-2013; Micrium, Inc.; Weston, FL
6+
*
7+
* All rights reserved. Protected by international copyright laws.
8+
*
9+
* Please feel free to use any application code labeled as 'EXAMPLE CODE' in
10+
* your application products. Example code may be used as is, in whole or in
11+
* part, or may be used as a reference only.
12+
*
13+
* Please help us continue to provide the Embedded community with the finest
14+
* software available. Your honesty is greatly appreciated.
15+
*
16+
* You can contact us at www.micrium.com.
17+
*********************************************************************************************************
18+
*/
19+
20+
/*
21+
*********************************************************************************************************
22+
*
23+
* APPLICATION CONFIGURATION
24+
*
25+
* uC/OS-III on POSIX
26+
*
27+
* Filename : app.c
28+
* Version : V1.00
29+
* Programmer(s) : EJ
30+
*
31+
*********************************************************************************************************
32+
*/
33+
34+
35+
/*
36+
*********************************************************************************************************
37+
* MODULE
38+
*********************************************************************************************************
39+
*/
40+
41+
#ifndef APP_CFG_MODULE_PRESENT
42+
#define APP_CFG_MODULE_PRESENT
43+
44+
45+
/*
46+
*********************************************************************************************************
47+
* INCLUDE
48+
*********************************************************************************************************
49+
*/
50+
51+
52+
/*
53+
*********************************************************************************************************
54+
* TASK PRIORITIES
55+
*********************************************************************************************************
56+
*/
57+
58+
#define APP_CFG_TASK_START_PRIO 33
59+
60+
#define OS_TASK_TMR_PRIO (OS_LOWEST_PRIO - 2)
61+
62+
63+
/*
64+
*********************************************************************************************************
65+
* TASK STACK SIZES
66+
* Size of the task stacks (# of OS_STK entries)
67+
*********************************************************************************************************
68+
*/
69+
70+
#define APP_CFG_TASK_START_STK_SIZE 4096
71+
72+
73+
/*
74+
*********************************************************************************************************
75+
* uC/TCP-IP v2.10
76+
*********************************************************************************************************
77+
*/
78+
79+
80+
/*
81+
*********************************************************************************************************
82+
* TRACE / DEBUG CONFIGURATION
83+
*********************************************************************************************************
84+
*/
85+
#ifndef TRACE_LEVEL_OFF
86+
#define TRACE_LEVEL_OFF 0
87+
#endif
88+
89+
#ifndef TRACE_LEVEL_INFO
90+
#define TRACE_LEVEL_INFO 1
91+
#endif
92+
93+
#ifndef TRACE_LEVEL_DEBUG
94+
#define TRACE_LEVEL_DEBUG 2
95+
#endif
96+
97+
#define APP_TRACE_LEVEL TRACE_LEVEL_OFF
98+
#define APP_TRACE printf
99+
100+
#define APP_TRACE_INFO(x) ((APP_TRACE_LEVEL >= TRACE_LEVEL_INFO) ? (void)(APP_TRACE x) : (void)0)
101+
#define APP_TRACE_DBG(x) ((APP_TRACE_LEVEL >= TRACE_LEVEL_DEBUG) ? (void)(APP_TRACE x) : (void)0)
102+
103+
#define APP_TRACE_DEBUG(x) APP_TRACE_DBG(x)
104+
105+
#endif

0 commit comments

Comments
 (0)