| 1 | /* |
|---|
| 2 | OSALTest.c |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | #include "DHL_OSAL.h" |
|---|
| 7 | |
|---|
| 8 | #if COMMENT |
|---|
| 9 | ____Test1____(){} |
|---|
| 10 | #endif |
|---|
| 11 | |
|---|
| 12 | #define WAIT1 1230 |
|---|
| 13 | #define WAIT2 2580 |
|---|
| 14 | #define WAIT3 3240 |
|---|
| 15 | |
|---|
| 16 | void OS_DelayTest() |
|---|
| 17 | { |
|---|
| 18 | UINT32 cur_ms; |
|---|
| 19 | DHL_OS_Printf( "\r\n---- OS Delay Test----\r\n"); |
|---|
| 20 | |
|---|
| 21 | cur_ms = DHL_OS_GetMsCount(); |
|---|
| 22 | DHL_OS_Printf( "currnt tick is %d\r\n", cur_ms); |
|---|
| 23 | |
|---|
| 24 | DHL_OS_Printf( "delay for %d ms\r\n", WAIT1); |
|---|
| 25 | DHL_OS_Delay(WAIT1); |
|---|
| 26 | |
|---|
| 27 | cur_ms = DHL_OS_GetMsCount(); |
|---|
| 28 | DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); |
|---|
| 29 | |
|---|
| 30 | DHL_OS_Printf( "delay for %d ms\r\n", WAIT2); |
|---|
| 31 | DHL_OS_Delay(WAIT2); |
|---|
| 32 | |
|---|
| 33 | cur_ms = DHL_OS_GetMsCount(); |
|---|
| 34 | DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | DHL_OS_Printf( "delay for %d ms\r\n", WAIT3); |
|---|
| 38 | DHL_OS_Delay(WAIT3); |
|---|
| 39 | |
|---|
| 40 | cur_ms = DHL_OS_GetMsCount(); |
|---|
| 41 | DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); |
|---|
| 42 | |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | #if COMMENT |
|---|
| 47 | ____Test2____(){} |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | #define ARG_DELAY(interval, count) (((interval & 0xffff) << 16) | (count & 0xffff)) |
|---|
| 51 | |
|---|
| 52 | static void delay_task(UINT32 arg) |
|---|
| 53 | { |
|---|
| 54 | int i; |
|---|
| 55 | int count = arg & 0xffff; |
|---|
| 56 | int interval = (arg >> 16); |
|---|
| 57 | |
|---|
| 58 | DHL_OS_TASK_ID tid; |
|---|
| 59 | DHL_OS_TASK_INFO tInfo; |
|---|
| 60 | |
|---|
| 61 | tid = DHL_OS_GetTaskID(); |
|---|
| 62 | DHL_OS_GetTaskInfo(tid, &tInfo); |
|---|
| 63 | |
|---|
| 64 | DHL_OS_Printf(" --> in %s, tid 0x%x (%s): task starts.. (count %d, interval %d sec) starts..\n", |
|---|
| 65 | __func__, tid, tInfo.name, count, interval); |
|---|
| 66 | |
|---|
| 67 | for (i=0; i<count; i++) { |
|---|
| 68 | DHL_OS_Delay(interval*1000); |
|---|
| 69 | DHL_OS_Printf(" --> in %s, tid 0x%x (%s): (%d/%d) %d seconds elapsed..\n", |
|---|
| 70 | __func__, tid, tInfo.name, i+1, count, interval); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | DHL_OS_Printf(" --> in %s, tid 0x%x exits..\n", __func__, tid); |
|---|
| 74 | DHL_OS_SelfDeleteTask(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void OS_MultiTaskTest() |
|---|
| 78 | { |
|---|
| 79 | /* |
|---|
| 80 | ¸ÖƼ ŽºÅ© Å×½ºÆ® ½ÃÀÛ |
|---|
| 81 | */ |
|---|
| 82 | DHL_OS_Printf("\n**** Multi task test is started..\n\n"); |
|---|
| 83 | |
|---|
| 84 | // different interval and count, but total elapsed time is same. |
|---|
| 85 | // |
|---|
| 86 | DHL_OS_CreateTask(delay_task, "Spawn1", 10, 8192, ARG_DELAY(1, 30)); |
|---|
| 87 | DHL_OS_CreateTask(delay_task, "Spawn2", 9, 8192, ARG_DELAY(2, 15)); |
|---|
| 88 | DHL_OS_CreateTask(delay_task, "Spawn3", 8, 8192, ARG_DELAY(3, 10)); |
|---|
| 89 | DHL_OS_CreateTask(delay_task, "Spawn4", 7, 8192, ARG_DELAY(5, 6)); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | DHL_OS_Delay(31000); |
|---|
| 93 | /* |
|---|
| 94 | ŽºÅ© Å×½ºÆ® Á¾·á |
|---|
| 95 | */ |
|---|
| 96 | DHL_OS_Printf("**** Multi task test is completed\n\n"); |
|---|
| 97 | |
|---|
| 98 | DHL_OS_Delay(1000); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | BOOL g_exit = 0; |
|---|
| 102 | |
|---|
| 103 | static void wait_task(UINT32 param) |
|---|
| 104 | { |
|---|
| 105 | while(!g_exit) |
|---|
| 106 | { |
|---|
| 107 | DHL_OS_Delay(100); |
|---|
| 108 | } |
|---|
| 109 | DHL_OS_SelfDeleteTask(); |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | void OS_HowManyTaskTest(int stk_size) |
|---|
| 114 | { |
|---|
| 115 | DHL_OS_TASK_ID tid; |
|---|
| 116 | int i = 0; |
|---|
| 117 | |
|---|
| 118 | DHL_OS_Printf("OS_HowManyTaskTest is started..\n\n"); |
|---|
| 119 | while (1) |
|---|
| 120 | { |
|---|
| 121 | tid = DHL_OS_CreateTask(wait_task, "", 100, stk_size, 0); |
|---|
| 122 | if (tid == DHL_INVALID_TASK_ID) |
|---|
| 123 | break; |
|---|
| 124 | DHL_OS_Printf("Creating task is success.. (%d)\n", i); |
|---|
| 125 | i++; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | DHL_OS_Printf("The max task num is %d, and stk_size is %d", i, stk_size); |
|---|
| 129 | g_exit = 1; |
|---|
| 130 | } |
|---|