source: svn/trunk/newcon3bcm2_21bu/dst/dhl/api/test/OSTaskTest.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 10.8 KB
Line 
1/*
2        OSALTest.c     
3*/
4
5
6#include "DHL_OSAL.h"
7
8/*
9        110401 cafrii comment
10       
11        EMMA3 ¿ë OSAL ¿¡¼­ DHL_OS_GetTaskID ÇÔ¼ö°¡ ISR ³»¿¡¼­ ºÒ¸± °æ¿ì ¹®Á¦°¡ ÀÖ´Â °Í °°À½.
12       
13        ¸ðµç task°¡ idle »óÅÂÀÎ °æ¿ì -> Å×½ºÆ® °á°ú´Â ¾øÀ½.
14        ISR È£Ãâ Á÷Àü¿¡ ƯÁ¤ task°¡ active »óÅ¿´´ø °æ¿ì -> ±× task id °¡ ¸®ÅϵǴ °Í °°À½.
15
16        --> ¹ö±× ¼öÁ¤. Å×½ºÆ® ÀýÂ÷¿¡ À̸¦ Å×½ºÆ® ÇÏ´Â ÄÚµå Ãß°¡.
17*/
18
19
20
21#if COMMENT
22____Test1____(){}
23#endif
24
25#define WAIT1 1000
26#define WAIT2 2000
27#define WAIT3 3000
28
29void OS_DelayTest()
30{
31        UINT32 cur_ms;
32        DHL_OS_Printf( "\r\n---- OS Delay Test----\r\n");
33
34        cur_ms = DHL_OS_GetMsCount();
35        DHL_OS_Printf( "currnt tick is %d\r\n", cur_ms); 
36
37        DHL_OS_Printf( "delay for %d ms\r\n", WAIT1);
38        DHL_OS_Delay(WAIT1);
39
40        cur_ms = DHL_OS_GetMsCount();
41        DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms);
42       
43        DHL_OS_Printf( "delay for %d ms\r\n", WAIT2);
44        DHL_OS_Delay(WAIT2);
45
46        cur_ms = DHL_OS_GetMsCount();
47        DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms);
48
49       
50        DHL_OS_Printf( "delay for %d ms\r\n", WAIT3);
51        DHL_OS_Delay(WAIT3);
52
53        cur_ms = DHL_OS_GetMsCount();
54        DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms);
55       
56}
57
58
59#if COMMENT
60____Test2____(){}
61#endif
62
63#define ARG_DELAY(interval, count) (((interval & 0xffff) << 16) | (count & 0xffff))
64
65static void delay_task(void* input)
66{
67        int i;
68        UINT32 arg = (UINT32)input;
69        int count = arg & 0xffff;
70        int interval = (arg >> 16);
71       
72        DHL_OS_TASK_ID tid;
73        DHL_OS_TASK_INFO tInfo;
74        DHL_OS_Printf("delay_task with %x\n", arg);
75        tid = DHL_OS_GetTaskID();
76        DHL_OS_GetTaskInfo(tid, &tInfo);
77       
78        DHL_OS_Printf("  --> in %s, tid 0x%x (%s) prio (%d) : task starts.. (count %d, interval %d sec) starts..\n", 
79                        __func__, tid, tInfo.name, tInfo.priority, count, interval);
80
81        for (i=0; i<count; i++) {
82                DHL_OS_Delay(interval*1000);
83                DHL_OS_Printf("  --> in %s, tid 0x%x (%s) prio (%d) : (%d/%d) %d seconds elapsed..\n", 
84                        __func__, tid, tInfo.name, tInfo.priority, i+1, count, interval);
85
86        }
87
88        DHL_OS_Printf("  --> in %s, tid 0x%x exits..\n", __func__, tid);
89        DHL_OS_SelfDeleteTask();
90}
91
92void OS_TaskTest()
93{
94        DHL_OS_TASK_ID tid;
95        DHL_OS_TASK_INFO tInfo;
96        UINT32 old_prio;
97        const int task1_prio = 40;
98        const int task1_stk_size = 8192;
99       
100        tInfo.name = (const char*)DHL_OS_Malloc(8);
101
102        /*
103                ŽºÅ© Å×½ºÆ® ½ÃÀÛ
104        */
105        DHL_OS_Printf("\n**** Task test is started.. with %x\n\n", ARG_DELAY(2, 10));
106
107        /*
108                ŽºÅ© »ý¼º ¹× À̸§À¸·Î ŽºÅ© ID °Ë»ö Å×½ºÆ®
109        */
110        tid = DHL_OS_CreateTask(delay_task, "Task1", task1_prio, task1_stk_size, ARG_DELAY(2, 10));
111        DHL_OS_GetTaskInfo(tid, &tInfo);
112        DHL_OS_Printf("\ntid 0x%x (%s) is created successfully.\n", tid, tInfo.name);
113       
114        if (DHL_OS_FindTaskByName(tInfo.name, &tid) != DHL_OK)
115                DHL_OS_Printf("!!!! cannot find task by name \"%s\"\n", tInfo.name);
116        else
117                DHL_OS_Printf("tid 0x%x is found by name \"%s\"\n", tid, tInfo.name);
118
119        DHL_OS_Delay(1000);
120
121
122        /*
123                ¿ì¼± ¼øÀ§ º¯°æ ¹× ¿ø»óº¹±Í Å×½ºÆ®
124        */
125
126        DHL_OS_GetTaskInfo(tid, &tInfo);
127        DHL_OS_Printf("\ntid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority);
128
129        DHL_OS_Printf("Increase the priority of the %s.\n", tInfo.name);
130        DHL_OS_SetTaskPriority(tid, tInfo.priority + 1, &old_prio);
131
132        DHL_OS_GetTaskInfo(tid, &tInfo);
133        DHL_OS_Printf("tid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority);
134
135        DHL_OS_Printf("Get back the priority.\n");
136        DHL_OS_SetTaskPriority(tid, old_prio, &tInfo.priority);
137
138        DHL_OS_GetTaskInfo(tid, &tInfo);
139        DHL_OS_Printf("tid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority);
140
141
142        DHL_OS_Delay(1000);
143        /*
144                ŽºÅ© Å×½ºÆ® Á¾·á
145        */
146        DHL_OS_Printf("**** Task test is completed\n\n");
147       
148}
149
150void OS_MultiTaskTest()
151{
152        /*
153                ¸ÖƼ ŽºÅ© Å×½ºÆ® ½ÃÀÛ
154        */
155        DHL_OS_Printf("\n**** Multi task test is started..\n\n");
156
157        // different interval and count, but total elapsed time is same.
158#if 1   // BKNOTE: not permitted same priority task in case of ucos-II
159        DHL_OS_CreateTask(delay_task, "Spawn1", 40, 8192, ARG_DELAY(1, 30));
160        DHL_OS_CreateTask(delay_task, "Spawn2", 41, 8192, ARG_DELAY(2, 15));
161        DHL_OS_CreateTask(delay_task, "Spawn3", 42, 8192, ARG_DELAY(3, 10));
162        DHL_OS_CreateTask(delay_task, "Spawn4", 43, 8192, ARG_DELAY(5, 6));     
163#else
164        DHL_OS_CreateTask(delay_task, "Spawn1", 50, 8192, ARG_DELAY(1, 30));
165        DHL_OS_CreateTask(delay_task, "Spawn2", 50, 8192, ARG_DELAY(2, 15));
166        DHL_OS_CreateTask(delay_task, "Spawn3", 50, 8192, ARG_DELAY(3, 10));
167        DHL_OS_CreateTask(delay_task, "Spawn4", 50, 8192, ARG_DELAY(5, 6)); 
168#endif
169
170        DHL_OS_Delay(31000);
171        /*
172                ŽºÅ© Å×½ºÆ® Á¾·á
173        */
174        DHL_OS_Printf("**** Multi task test is completed\n\n");
175}
176
177BOOL g_exit = 0;
178
179static void wait_task(void* param)
180{
181        while(!g_exit)
182        {
183                DHL_OS_Delay(100);
184        }
185        DHL_OS_SelfDeleteTask();
186}
187
188void OS_HowManyTaskTest(int stk_size)
189{
190        DHL_OS_TASK_ID tid;
191        int i = 0;
192
193        DHL_OS_Printf("OS_HowManyTaskTest is started..\n\n");
194        while (1)
195        {
196                tid = DHL_OS_CreateTask(wait_task, "", 50, stk_size, 0);
197                if (tid == DHL_INVALID_TASK_ID)
198                        break;
199                DHL_OS_Printf("Creating task is success.. (%d)\n", i);
200                i++;
201        }
202       
203        DHL_OS_Printf("The max task num is %d, and stk_size is %d", i, stk_size);
204        g_exit = 1;
205}
206
207static void self_delete_task(void* arg)
208{
209        int count = 10;
210        int i = 0;
211        DHL_OS_TASK_ID tid;
212        DHL_OS_TASK_INFO tInfo;
213
214        tid = DHL_OS_GetTaskID();
215        DHL_OS_GetTaskInfo(tid, &tInfo);
216
217        DHL_OS_Printf("  --> in %s, tid 0x%x (%s): task starts.. (count %d) starts..\n", 
218                        __func__, tid, tInfo.name, count);
219       
220        while(1)
221        {
222                if (i == count)
223                        DHL_OS_SelfDeleteTask();
224               
225                if (i == count + 1)
226                        break;                 
227               
228                DHL_OS_Delay(100);
229                DHL_OS_Printf("  --> in %s, tid 0x%x (%s): (%d/%d)..\n", 
230                        __func__, tid, tInfo.name, i+1, count);
231                i++;           
232        }       
233
234        DHL_OS_Printf("  --> in %s, tid 0x%x (%s): self delete task failed..\n",
235                __func__, tid, tInfo.name);
236        DHL_OS_SelfDeleteTask();
237}
238
239void OS_TaskSelfDeleteTest()
240{
241        /*
242                Self Delete Å×½ºÆ® ½ÃÀÛ
243        */
244        DHL_OS_Printf("\n**** Self delete task test is started..\n\n");
245
246        DHL_OS_CreateTask(self_delete_task, "selfdel", 40, 8192, 0);
247
248        DHL_OS_Delay(2000);
249        /*
250                ŽºÅ© Å×½ºÆ® Á¾·á
251        */
252        DHL_OS_Printf("**** Self delete task test is completed\n\n");
253}
254
255#if COMMENT
256____Test3____(){}
257#endif
258
259void OS_InterruptTest()
260{
261        UINT32 mask;
262        DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal");
263        mask = DHL_OS_DisableInterrupts();
264        DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal");
265        DHL_OS_RestoreInterrupts(mask);
266        DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal");
267#if 0
268        UINT32 mask1, mask2;
269        // intlock test
270        DHL_OS_Printf( "\n---- int lock test ----\n");
271        DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "INT" : "normal");
272        DHL_OS_DisableInterrupts();
273        DHL_OS_Printf( "after int disable -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
274        DHL_OS_RestoreInterrupts(0);
275        DHL_OS_Printf( "after int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
276
277        DHL_OS_Delay(1000);
278
279        // multiple intlock test
280        DHL_OS_Printf("\n---- multiple int lock test ----\n");
281        DHL_OS_Printf("currently %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
282        mask1 = DHL_OS_DisableInterrupts();
283        DHL_OS_Printf("after 1st int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask1);
284        mask2 = DHL_OS_DisableInterrupts();
285        DHL_OS_Printf("after 2nd int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask2);
286
287        DHL_OS_RestoreInterrupts(mask2);
288        DHL_OS_Printf("after 2nd int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
289        DHL_OS_RestoreInterrupts(mask1);
290        DHL_OS_Printf("after 1st int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
291
292        DHL_OS_Delay(1000);
293
294        // error check if pending API called during intLock
295        DHL_OS_Printf("\n---- pending api block test ----\n");
296
297        DHL_OS_Printf("currently %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
298        mask1 = DHL_OS_DisableInterrupts();
299        DHL_OS_Printf("after int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask1);
300        DHL_OS_Printf("call OS_Delay..\n");
301        DHL_OS_Delay(100000);
302        DHL_OS_RestoreInterrupts(mask1);
303        DHL_OS_Printf( "after int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal");
304#endif
305
306}
307
308
309
310#if COMMENT
311____Test4____(){}
312#endif
313
314/*
315        Å×½ºÆ® ÀýÂ÷:
316          ƯÁ¤ task¸¦ ÀÏÁ¤ ½Ã°£ µ¿¾È ¹«ÇÑ ·çÇÁ µ¿ÀÛ ½Ã۰í,
317          ´Ù¸¥ task¿¡¼­ ISR ¹ß»ý½ÃÅ´.
318          ISR ³»¿¡¼­ GetTaskID ÇÏ¿© Ãâ·Â.
319          task Á¤º¸°¡ Ãâ·ÂµÇ¸é FAIL! INVALID_ID °¡ Ãâ·ÂµÇ¾î¾ß ÇÔ.
320*/
321
322static void my_test_isr(void)
323{
324        DHL_OS_Printf("-");
325        DHL_OS_Printf("*");
326        DHL_OS_Printf("%x\n", DHL_OS_GetTaskID());     
327}
328
329/*
330        ¸ÕÀú durationÀ» º¯°æÇØ °¡¸é¼­ 5ÃÊ Á¤µµ delay°¡ µÇ´Â °ªÀ» ã´Â´Ù.
331
332        duration ¿¡ 600 ¸¦ ÀÔ·ÂÇÏ´Ï ¾à 5ÃÊ Á¤µµ µÇ¾úÀ½.
333*/
334void OS_ISRTest_Loop(UINT32 duration)
335{
336        UINT32 data=0;
337        UINT32 i, j, k;
338        UINT32 start = DHL_OS_GetMsCount();
339
340        DHL_OS_Printf("tid %x\n", DHL_OS_GetTaskID());
341        DHL_OS_Printf("entering loop..\n");
342
343        // ¾Æ·¡ loop ¿¡´Â pendingÀ» À¯¹ßÇÒ °¡´É¼º ÀÖ´Â ¾î¶°ÇÑ ÇÔ¼ö È£Ãâµµ ÇÏÁö ¸»ÀÚ. printf µµ ±ÝÁö.
344        for (i=0; i<duration; i++)
345                for (j=0; j<duration; j++)
346                        for (k=0; k<duration; k++)
347                                data += (i+j+k);
348       
349        DHL_OS_Printf("loop end, %d sec\n", (DHL_OS_GetMsCount()-start)/1000, data);
350}
351
352/*
353        ISRÀ» ¸¸µé¾î ³¾ ¼ö ÀÖ´Â ¹æ¹ýÀÌ ÇÊ¿äÇÔ. ÀϹÝÀûÀÎ UART RX ISR À̳ª GPIO ISRÀ» Ȱ¿ëÇϸé ÁÁÀ» µí.
354*/
355
356void OS_ISRTest(UINT32 duration)
357{
358#if 0
359        // cafrii 110901 remove
360        // ¾Æ·¡ dhl_console_set_test_isr() ÇÔ¼ö´Â hal ¿¡¼­ °ø½ÄÀûÀ¸·Î ±¸ÇöÇØ¾ß ÇÏ´Â api°¡ ¾Æ´Ï¶ó¼­
361        // ÀÏ¹Ý ¹ü¿ë Å×½ºÆ® Äڵ忡 ÀÌ·± api¸¦ »ç¿ëÇÏ´Â °ÍÀº ¹®Á¦°¡ µÉ ¼ö ÀÖÀ½.
362        // isrÀ» ¹ß»ý½Ãų ¼ö ÀÖ´Â ´Ù¸¥ ¹æ¾ÈÀ» ¸ð»öÇØ º¼°Í!
363
364        extern void dhl_console_set_test_isr(void *isr);
365
366        // ÀÌ api¸¦ ºÎ¸¥ ÈÄ Å°º¸µå ÀÔ·ÂÀ» ¹ÞÀ¸¸é isrÀÌ È£ÃâµÈ´Ù.
367        dhl_console_set_test_isr(my_test_isr);
368
369        // ¾à 5ÃÊ Á¤µµÀÇ ½Ã°£ µ¿¾È Ű ÀÔ·ÂÀ» ÇÑ´Ù.
370        OS_ISRTest_Loop(duration);
371
372        dhl_console_set_test_isr(0);
373#endif
374}
375
376
377
378#if COMMENT
379____Test5____(){}
380#endif
381
382/*
383        ´Ü¼ø console input test
384        ÇϳªÀÇ ÀÚÆÇ ÀÔ·ÂÀ» ¹Þ¾Æ Ãâ·Â.
385*/
386void OS_GetCharTest(void)
387{
388        int i;
389        int value;
390
391        for(i=0;i<10;i++)
392        {
393                value = DHL_OS_GetChar();
394
395                DHL_OS_Printf("console input(%d) value = 0x%x, '%c' \n", i, value, value);
396        }
397
398        DHL_OS_Printf("console input test complete !!!\n");
399
400}
401
402#include "DHL_DBG.h"
403
404static DHL_SymbolTable OSTaskTestSymbols[] =
405{
406        //---- functions
407       
408        DHL_FNC_SYM_ENTRY(OS_DelayTest),
409        DHL_FNC_SYM_ENTRY(OS_TaskTest),
410        DHL_FNC_SYM_ENTRY(OS_MultiTaskTest),
411        DHL_FNC_SYM_ENTRY(OS_HowManyTaskTest),
412        DHL_FNC_SYM_ENTRY(OS_TaskSelfDeleteTest),
413        DHL_FNC_SYM_ENTRY(OS_InterruptTest),
414        DHL_FNC_SYM_ENTRY(OS_ISRTest_Loop),
415        DHL_FNC_SYM_ENTRY(OS_ISRTest),
416        DHL_FNC_SYM_ENTRY(OS_GetCharTest),
417};
418
419void OSTaskTestInit()
420{
421        DHL_DBG_RegisterSymbols(OSTaskTestSymbols, DHL_NUMSYMBOLS(OSTaskTestSymbols));
422
423
424}
425
426
Note: See TracBrowser for help on using the repository browser.