1 | struct task_structure //Es wird eine Struktur erstellt, die den count Wert enthält und die ID des Tasks
|
2 | {
|
3 | int id;
|
4 | int rohmaterial;
|
5 | int produzierte_stueck;
|
6 | int status; // 1 = produktion ; 0 = service
|
7 | };
|
8 |
|
9 | void init_status(struct task_structure *pTask,int id);
|
10 |
|
11 | //! Message Mailboxe - Parameters
|
12 |
|
13 | OS_EVENT *CommMbox;
|
14 | char CommRxBuf[100];
|
15 |
|
16 |
|
17 | //! Message Queue - Parameters
|
18 |
|
19 | OS_EVENT *CommQ;
|
20 | void *CommMsg[10];
|
21 |
|
22 | //! Mutex - Paramters
|
23 |
|
24 | OS_EVENT *mutex_sem;
|
25 |
|
26 | //! Memoryblock
|
27 |
|
28 | OS_MEM *pMemBuf;
|
29 | INT32U CommBuf[16][32];
|
30 | OS_STK CommMemoryStk[8*sizeof(struct task_structure)];
|
31 |
|
32 | int main(void)
|
33 | {
|
34 | INT8U ErrVar;
|
35 | #if 0
|
36 | BSP_IntDisAll(); /* For an embedded target, disable all interrupts until we are ready to accept them */
|
37 | #endif
|
38 |
|
39 | OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
|
40 |
|
41 | //! Create Message Mailboxes
|
42 |
|
43 | CommMbox = OSMboxCreate((void *)0);
|
44 |
|
45 | //! Create Message Queue
|
46 |
|
47 | CommQ = OSQCreate(&CommMsg[0], 10);
|
48 |
|
49 | //! Create Mutex
|
50 |
|
51 | mutex_sem=OSMutexCreate(1, &ErrVar);
|
52 | if (ErrVar == OS_ERR_NONE)
|
53 | printf("\nMutex erfolgreich erstellt...\n");
|
54 | else
|
55 | printf("\nMutex erstellung failed...\n");
|
56 |
|
57 | if (ErrVar == OS_ERR_NONE)
|
58 | printf("\nMemoryblock erfolgreich erstellt...\n\n##################################################################\n\n\n");
|
59 | else
|
60 | printf("\nFlags erstellung failed...\n");
|
61 |
|
62 | //! Create Tasks
|
63 |
|
64 | ErrVar = OSTaskCreate(serviceTask, (void *) 0, &pAppStartTask1[0], 11);
|
65 |
|
66 | ErrVar = OSTaskCreate(genericTask, (void *) 1, &pAppStartTask2[0], 3);
|
67 | ErrVar = OSTaskCreate(genericTask, (void *) 2, &pAppStartTask3[0], 4);
|
68 | ErrVar = OSTaskCreate(genericTask, (void *) 3, &pAppStartTask4[0], 5);
|
69 | ErrVar = OSTaskCreate(genericTask, (void *) 4, &pAppStartTask5[0], 6);
|
70 | ErrVar = OSTaskCreate(genericTask, (void *) 5, &pAppStartTask6[0], 7);
|
71 | ErrVar = OSTaskCreate(genericTask, (void *) 6, &pAppStartTask7[0], 8);
|
72 | ErrVar = OSTaskCreate(genericTask, (void *) 7, &pAppStartTask8[0], 9);
|
73 | ErrVar = OSTaskCreate(genericTask, (void *) 8, &pAppStartTask9[0], 10);
|
74 |
|
75 | //! Create Memory
|
76 |
|
77 | pMemBuf = OSMemCreate(&CommMemoryStk[0], 8, sizeof(struct task_structure), &ErrVar);
|
78 | printf("%d Byte",sizeof(struct task_structure));
|
79 |
|
80 | //CommMemory = OSMemCreate(&CommMemoryStk[0], 8, sizeof(Production_Data), &ErrVar);
|
81 |
|
82 | #if OS_TASK_NAME_SIZE > 11
|
83 | OSTaskNameSet(APP_TASK_START_PRIO, (INT8U *)"Start Task", &ErrVar);
|
84 | #endif
|
85 |
|
86 | #if OS_TASK_NAME_SIZE > 14
|
87 | OSTaskNameSet(OS_IDLE_PRIO, (INT8U *)"uC/OS-II Idle", &ErrVar);
|
88 | #endif
|
89 |
|
90 | #if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
|
91 | OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat", &ErrVar);
|
92 | #endif
|
93 |
|
94 | OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
|
95 | return 0; /* should never be reached */
|
96 | }
|
97 |
|
98 | void genericTask(void *p_arg)
|
99 | {
|
100 | int *pIdentification;
|
101 | INT8U ErrVar2;
|
102 | pIdentification=(int *)p_arg;
|
103 | char array[50];
|
104 |
|
105 | struct task_structure *pTask;
|
106 |
|
107 | pTask=OSMemGet(pMemBuf, &ErrVar2);
|
108 | if(pTask==NULL)
|
109 | {
|
110 | printf("Speicherallokation fuer Task %d fehlgeschlagen",pIdentification);
|
111 | return;
|
112 | }
|
113 | else
|
114 | {
|
115 | init_status(pTask,pIdentification);
|
116 | }
|
117 |
|
118 | #if OS_TASK_STAT_EN > 0
|
119 | OSStatInit(); /* Determine CPU capacity */
|
120 | #endif
|
121 |
|
122 | while(1) /* Task body, always written as an infinite loop.*/
|
123 | {
|
124 | if(pTask->status==1)
|
125 | {
|
126 | pTask->rohmaterial=pTask->rohmaterial-1;
|
127 | pTask->produzierte_stueck=pTask->produzierte_stueck+1;
|
128 | }
|
129 | else if(pTask->rohmaterial==0)
|
130 | pTask->status=0;
|
131 | printf("%d\n",pTask->id);
|
132 | // sprintf(array,"%d",5);
|
133 |
|
134 | //ErrVar2=OSQPost(CommQ,(void *)&array[0]);
|
135 | ErrVar2=OSQPost(CommQ,pTask);
|
136 |
|
137 | OSTimeDlyHMSM(0, 0, 1, 0);
|
138 | }
|
139 | }
|
140 |
|
141 | void serviceTask(void *p_arg)
|
142 | {
|
143 | INT8U ErrVar3;
|
144 | p_arg = p_arg;
|
145 |
|
146 | struct task_structure *pPointer;
|
147 |
|
148 | while(1) /* Task body, always written as an infinite loop.*/
|
149 | {
|
150 | pPointer=OSQPend(CommQ, 3, &ErrVar3);//!pPointer zeigt auf NULL -> WARUM??
|
151 | if(ErrVar3!=OS_ERR_NONE)
|
152 | {
|
153 | printf("Task %d Rohmaterial: %d",pPointer->id,pPointer->rohmaterial);
|
154 | OSMemPut(pMemBuf, pPointer);
|
155 | }
|
156 | else
|
157 | break;
|
158 | OSTimeDlyHMSM(0, 0, 1, 0);
|
159 | }
|
160 | }
|