1 #include <rtthread.h> 2 #include "tc_comm.h" 3 4 /* 5 * This is an example for delay thread 6 */ 7 static struct rt_thread thread; 8 static char thread_stack[THREAD_STACK_SIZE]; thread_entry(void * parameter)9static void thread_entry(void* parameter) 10 { 11 rt_tick_t tick; 12 rt_kprintf("thread inited ok\n"); 13 14 rt_kprintf("thread delay 10 tick\n"); 15 tick = rt_tick_get(); 16 rt_thread_delay(10); 17 if (rt_tick_get() - tick > 11) 18 { 19 tc_done(TC_STAT_FAILED); 20 return; 21 } 22 23 rt_kprintf("thread delay 15 tick\n"); 24 tick = rt_tick_get(); 25 rt_thread_delay(15); 26 if (rt_tick_get() - tick > 16) 27 { 28 tc_done(TC_STAT_FAILED); 29 return; 30 } 31 32 rt_kprintf("thread exit\n"); 33 34 tc_done(TC_STAT_PASSED); 35 } 36 thread_delay_init()37rt_err_t thread_delay_init() 38 { 39 rt_err_t result; 40 41 result = rt_thread_init(&thread, 42 "test", 43 thread_entry, RT_NULL, 44 &thread_stack[0], sizeof(thread_stack), 45 THREAD_PRIORITY, 10); 46 47 if (result == RT_EOK) 48 rt_thread_startup(&thread); 49 else 50 tc_stat(TC_STAT_END | TC_STAT_FAILED); 51 52 return result; 53 } 54 55 #ifdef RT_USING_TC _tc_thread_delay()56int _tc_thread_delay() 57 { 58 thread_delay_init(); 59 60 return 30; 61 } 62 FINSH_FUNCTION_EXPORT(_tc_thread_delay, a thread delay test); 63 #else rt_application_init()64int rt_application_init() 65 { 66 thread_delay_init(); 67 68 return 0; 69 } 70 #endif 71