/* OSALTest.c */ #include "DHL_OSAL.h" /* 110401 cafrii comment EMMA3 ¿ë OSAL ¿¡¼­ DHL_OS_GetTaskID ÇÔ¼ö°¡ ISR ³»¿¡¼­ ºÒ¸± °æ¿ì ¹®Á¦°¡ ÀÖ´Â °Í °°À½. ¸ðµç task°¡ idle »óÅÂÀÎ °æ¿ì -> Å×½ºÆ® °á°ú´Â ¾øÀ½. ISR È£Ãâ Á÷Àü¿¡ ƯÁ¤ task°¡ active »óÅ¿´´ø °æ¿ì -> ±× task id °¡ ¸®ÅϵǴ °Í °°À½. --> ¹ö±× ¼öÁ¤. Å×½ºÆ® ÀýÂ÷¿¡ À̸¦ Å×½ºÆ® ÇÏ´Â ÄÚµå Ãß°¡. */ #if COMMENT ____Test1____(){} #endif #define WAIT1 1000 #define WAIT2 2000 #define WAIT3 3000 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(void* input) { int i; UINT32 arg = (UINT32)input; int count = arg & 0xffff; int interval = (arg >> 16); DHL_OS_TASK_ID tid; DHL_OS_TASK_INFO tInfo; DHL_OS_Printf("delay_task with %x\n", arg); tid = DHL_OS_GetTaskID(); DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf(" --> in %s, tid 0x%x (%s) prio (%d) : task starts.. (count %d, interval %d sec) starts..\n", __func__, tid, tInfo.name, tInfo.priority, count, interval); for (i=0; i in %s, tid 0x%x (%s) prio (%d) : (%d/%d) %d seconds elapsed..\n", __func__, tid, tInfo.name, tInfo.priority, i+1, count, interval); } DHL_OS_Printf(" --> in %s, tid 0x%x exits..\n", __func__, tid); DHL_OS_SelfDeleteTask(); } void OS_TaskTest() { DHL_OS_TASK_ID tid; DHL_OS_TASK_INFO tInfo; UINT32 old_prio; const int task1_prio = 40; const int task1_stk_size = 8192; tInfo.name = (const char*)DHL_OS_Malloc(8); /* ŽºÅ© Å×½ºÆ® ½ÃÀÛ */ DHL_OS_Printf("\n**** Task test is started.. with %x\n\n", ARG_DELAY(2, 10)); /* ŽºÅ© »ý¼º ¹× À̸§À¸·Î ŽºÅ© ID °Ë»ö Å×½ºÆ® */ tid = DHL_OS_CreateTask(delay_task, "Task1", task1_prio, task1_stk_size, ARG_DELAY(2, 10)); DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf("\ntid 0x%x (%s) is created successfully.\n", tid, tInfo.name); if (DHL_OS_FindTaskByName(tInfo.name, &tid) != DHL_OK) DHL_OS_Printf("!!!! cannot find task by name \"%s\"\n", tInfo.name); else DHL_OS_Printf("tid 0x%x is found by name \"%s\"\n", tid, tInfo.name); DHL_OS_Delay(1000); /* ¿ì¼± ¼øÀ§ º¯°æ ¹× ¿ø»óº¹±Í Å×½ºÆ® */ DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf("\ntid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority); DHL_OS_Printf("Increase the priority of the %s.\n", tInfo.name); DHL_OS_SetTaskPriority(tid, tInfo.priority + 1, &old_prio); DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf("tid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority); DHL_OS_Printf("Get back the priority.\n"); DHL_OS_SetTaskPriority(tid, old_prio, &tInfo.priority); DHL_OS_GetTaskInfo(tid, &tInfo); DHL_OS_Printf("tid 0x%x (%s), prio %d\n", tid, tInfo.name, tInfo.priority); DHL_OS_Delay(1000); /* ŽºÅ© Å×½ºÆ® Á¾·á */ DHL_OS_Printf("**** Task test is completed\n\n"); } void OS_MultiTaskTest() { /* ¸ÖƼ ŽºÅ© Å×½ºÆ® ½ÃÀÛ */ DHL_OS_Printf("\n**** Multi task test is started..\n\n"); // different interval and count, but total elapsed time is same. #if 1 // BKNOTE: not permitted same priority task in case of ucos-II DHL_OS_CreateTask(delay_task, "Spawn1", 40, 8192, ARG_DELAY(1, 30)); DHL_OS_CreateTask(delay_task, "Spawn2", 41, 8192, ARG_DELAY(2, 15)); DHL_OS_CreateTask(delay_task, "Spawn3", 42, 8192, ARG_DELAY(3, 10)); DHL_OS_CreateTask(delay_task, "Spawn4", 43, 8192, ARG_DELAY(5, 6)); #else DHL_OS_CreateTask(delay_task, "Spawn1", 50, 8192, ARG_DELAY(1, 30)); DHL_OS_CreateTask(delay_task, "Spawn2", 50, 8192, ARG_DELAY(2, 15)); DHL_OS_CreateTask(delay_task, "Spawn3", 50, 8192, ARG_DELAY(3, 10)); DHL_OS_CreateTask(delay_task, "Spawn4", 50, 8192, ARG_DELAY(5, 6)); #endif DHL_OS_Delay(31000); /* ŽºÅ© Å×½ºÆ® Á¾·á */ DHL_OS_Printf("**** Multi task test is completed\n\n"); } BOOL g_exit = 0; static void wait_task(void* 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, "", 50, 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; } static void self_delete_task(void* arg) { int count = 10; int i = 0; 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) starts..\n", __func__, tid, tInfo.name, count); while(1) { if (i == count) DHL_OS_SelfDeleteTask(); if (i == count + 1) break; DHL_OS_Delay(100); DHL_OS_Printf(" --> in %s, tid 0x%x (%s): (%d/%d)..\n", __func__, tid, tInfo.name, i+1, count); i++; } DHL_OS_Printf(" --> in %s, tid 0x%x (%s): self delete task failed..\n", __func__, tid, tInfo.name); DHL_OS_SelfDeleteTask(); } void OS_TaskSelfDeleteTest() { /* Self Delete Å×½ºÆ® ½ÃÀÛ */ DHL_OS_Printf("\n**** Self delete task test is started..\n\n"); DHL_OS_CreateTask(self_delete_task, "selfdel", 40, 8192, 0); DHL_OS_Delay(2000); /* ŽºÅ© Å×½ºÆ® Á¾·á */ DHL_OS_Printf("**** Self delete task test is completed\n\n"); } #if COMMENT ____Test3____(){} #endif void OS_InterruptTest() { UINT32 mask; DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal"); mask = DHL_OS_DisableInterrupts(); DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal"); DHL_OS_RestoreInterrupts(mask); DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "intlock" : "normal"); #if 0 UINT32 mask1, mask2; // intlock test DHL_OS_Printf( "\n---- int lock test ----\n"); DHL_OS_Printf( "currently %s state\r\n", DHL_OS_GetIntState()? "INT" : "normal"); DHL_OS_DisableInterrupts(); DHL_OS_Printf( "after int disable -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); DHL_OS_RestoreInterrupts(0); DHL_OS_Printf( "after int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); DHL_OS_Delay(1000); // multiple intlock test DHL_OS_Printf("\n---- multiple int lock test ----\n"); DHL_OS_Printf("currently %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); mask1 = DHL_OS_DisableInterrupts(); DHL_OS_Printf("after 1st int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask1); mask2 = DHL_OS_DisableInterrupts(); DHL_OS_Printf("after 2nd int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask2); DHL_OS_RestoreInterrupts(mask2); DHL_OS_Printf("after 2nd int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); DHL_OS_RestoreInterrupts(mask1); DHL_OS_Printf("after 1st int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); DHL_OS_Delay(1000); // error check if pending API called during intLock DHL_OS_Printf("\n---- pending api block test ----\n"); DHL_OS_Printf("currently %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); mask1 = DHL_OS_DisableInterrupts(); DHL_OS_Printf("after int disable -> %s state, mask %08x\n", DHL_OS_GetIntState() ? "INT" : "normal", mask1); DHL_OS_Printf("call OS_Delay..\n"); DHL_OS_Delay(100000); DHL_OS_RestoreInterrupts(mask1); DHL_OS_Printf( "after int resume -> %s state\n", DHL_OS_GetIntState() ? "INT" : "normal"); #endif } #if COMMENT ____Test4____(){} #endif /* Å×½ºÆ® ÀýÂ÷: ƯÁ¤ task¸¦ ÀÏÁ¤ ½Ã°£ µ¿¾È ¹«ÇÑ ·çÇÁ µ¿ÀÛ ½Ã۰í, ´Ù¸¥ task¿¡¼­ ISR ¹ß»ý½ÃÅ´. ISR ³»¿¡¼­ GetTaskID ÇÏ¿© Ãâ·Â. task Á¤º¸°¡ Ãâ·ÂµÇ¸é FAIL! INVALID_ID °¡ Ãâ·ÂµÇ¾î¾ß ÇÔ. */ static void my_test_isr(void) { DHL_OS_Printf("-"); DHL_OS_Printf("*"); DHL_OS_Printf("%x\n", DHL_OS_GetTaskID()); } /* ¸ÕÀú durationÀ» º¯°æÇØ °¡¸é¼­ 5ÃÊ Á¤µµ delay°¡ µÇ´Â °ªÀ» ã´Â´Ù. duration ¿¡ 600 ¸¦ ÀÔ·ÂÇÏ´Ï ¾à 5ÃÊ Á¤µµ µÇ¾úÀ½. */ void OS_ISRTest_Loop(UINT32 duration) { UINT32 data=0; UINT32 i, j, k; UINT32 start = DHL_OS_GetMsCount(); DHL_OS_Printf("tid %x\n", DHL_OS_GetTaskID()); DHL_OS_Printf("entering loop..\n"); // ¾Æ·¡ loop ¿¡´Â pendingÀ» À¯¹ßÇÒ °¡´É¼º ÀÖ´Â ¾î¶°ÇÑ ÇÔ¼ö È£Ãâµµ ÇÏÁö ¸»ÀÚ. printf µµ ±ÝÁö. for (i=0; i