-
-
Save hduffddybz/31174950438a49cc60c8 to your computer and use it in GitHub Desktop.
rtt & rms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <rtthread.h> | |
#define THREAD_PRIORITY 25 | |
#define THREAD_STACK_SIZE 512 | |
#define THREAD_TIMESLICE 5 | |
static rt_thread_t tid1 = RT_NULL, tid2 = RT_NULL; | |
static rt_rms_t rms1 = RT_NULL, rms2 = RT_NULL; | |
static void thread_entry(void* parameter) | |
{ | |
rt_tick_t now, last, diff = 0; | |
int a; | |
rms1 = rt_rms_create("rms1", 10); | |
last = rt_tick_get(); | |
while(1) | |
{ | |
for(a = 0; a < 10000; a++); | |
if(rt_rms_endcycle(rms1) != RT_EOK) | |
{ | |
return; | |
} | |
now = rt_tick_get(); | |
diff = now; | |
diff = diff - last; | |
last = now; | |
rt_kprintf("thread1:%d\n", diff); | |
// if(rt_rms_delete(rms1) == RT_EOK) | |
// break; | |
} | |
} | |
static void thread2_entry(void* parameter) | |
{ | |
rt_tick_t now, last, diff = 0; | |
int a; | |
rms2 = rt_rms_create("rms2", 20); | |
last = rt_tick_get(); | |
while(1) | |
{ | |
for(a = 0; a < 10000; a++); | |
if(rt_rms_endcycle(rms2) != RT_EOK) | |
{ | |
return; | |
} | |
now = rt_tick_get(); | |
diff = now; | |
diff = diff - last; | |
last = now; | |
rt_kprintf("thread2:%d\n", diff); | |
} | |
} | |
int rt_application_init() | |
{ | |
tid1 = rt_thread_create("t1", | |
thread_entry, (void*)1, | |
THREAD_STACK_SIZE, THREAD_PRIORITY + 1, THREAD_TIMESLICE); | |
if (tid1 != RT_NULL) | |
rt_thread_startup(tid1); | |
else | |
return -1; | |
tid2 = rt_thread_create("t2", | |
thread2_entry, (void *)1, | |
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); | |
if(tid2 != RT_NULL) | |
rt_thread_startup(tid2); | |
else | |
return -1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment