/* OSALTest.c */ #include "DHL_OSAL.h" #if COMMENT ____Test1____(){} #endif #define WAIT1 1230 #define WAIT2 2580 #define WAIT3 3240 void OS_DelayTest() { UINT32 cur_ms; DHL_OS_Printf( "\r\n---- OS Delay Test----\r\n"); cur_ms = DHL_OS_GetMsCount(); DHL_OS_Printf( "currnt tick is %d\r\n", cur_ms); DHL_OS_Printf( "delay for %d ms\r\n", WAIT1); DHL_OS_Delay(WAIT1); cur_ms = DHL_OS_GetMsCount(); DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); DHL_OS_Printf( "delay for %d ms\r\n", WAIT2); DHL_OS_Delay(WAIT2); cur_ms = DHL_OS_GetMsCount(); DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); DHL_OS_Printf( "delay for %d ms\r\n", WAIT3); DHL_OS_Delay(WAIT3); cur_ms = DHL_OS_GetMsCount(); DHL_OS_Printf( "this task woke up at %d\r\n", cur_ms); } #if COMMENT ____Test2____(){} #endif #define ARG_DELAY(interval, count) (((interval & 0xffff) << 16) | (count & 0xffff)) static void delay_task(UINT32 arg) { int i; int count = arg & 0xffff; int interval = (arg >> 16); DHL_OS_TASK_ID tid; DHL_OS_TASK_INFO tInfo; tid = DHL_OS_GetTaskID(); DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf(" --> in %s, tid 0x%x (%s): task starts.. (count %d, interval %d sec) starts..\n", __func__, tid, tInfo.name, count, interval); for (i=0; i in %s, tid 0x%x (%s): (%d/%d) %d seconds elapsed..\n", __func__, tid, tInfo.name, i+1, count, interval); } DHL_OS_Printf(" --> in %s, tid 0x%x exits..\n", __func__, tid); DHL_OS_SelfDeleteTask(); } void OS_MultiTaskTest() { /* ¸ÖƼ ŽºÅ© Å×½ºÆ® ½ÃÀÛ */ DHL_OS_Printf("\n**** Multi task test is started..\n\n"); // different interval and count, but total elapsed time is same. // DHL_OS_CreateTask(delay_task, "Spawn1", 10, 8192, ARG_DELAY(1, 30)); DHL_OS_CreateTask(delay_task, "Spawn2", 9, 8192, ARG_DELAY(2, 15)); DHL_OS_CreateTask(delay_task, "Spawn3", 8, 8192, ARG_DELAY(3, 10)); DHL_OS_CreateTask(delay_task, "Spawn4", 7, 8192, ARG_DELAY(5, 6)); DHL_OS_Delay(31000); /* ŽºÅ© Å×½ºÆ® Á¾·á */ DHL_OS_Printf("**** Multi task test is completed\n\n"); DHL_OS_Delay(1000); } BOOL g_exit = 0; static void wait_task(UINT32 param) { while(!g_exit) { DHL_OS_Delay(100); } DHL_OS_SelfDeleteTask(); } void OS_HowManyTaskTest(int stk_size) { DHL_OS_TASK_ID tid; int i = 0; DHL_OS_Printf("OS_HowManyTaskTest is started..\n\n"); while (1) { tid = DHL_OS_CreateTask(wait_task, "", 100, stk_size, 0); if (tid == DHL_INVALID_TASK_ID) break; DHL_OS_Printf("Creating task is success.. (%d)\n", i); i++; } DHL_OS_Printf("The max task num is %d, and stk_size is %d", i, stk_size); g_exit = 1; }