1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/projects/test_sleep/main.c

48 lines
1.1 KiB
C
Raw Normal View History

#include <stdio.h>
#include <thread.h>
#include <kernel.h>
#include <hwtimer.h>
2010-11-02 17:23:10 +01:00
#include <ps.h>
int integer = 0;
int i = 0;
void second_thread(void) {
printf("Woke up!\n");
while(1) {
integer++;
printf("sleeper: running. integer=%i, i=%i.\n", integer, i);
2010-11-02 17:23:10 +01:00
if (integer % 1 == 0) {
printf("Going to sleep.\n");
thread_sleep();
}
}
}
tcb second_thread_tcb;
2010-11-02 17:23:10 +01:00
char second_thread_stack[KERNEL_CONF_STACKSIZE_DEFAULT*2];
int main(void)
{
hwtimer_init();
int pid = thread_create(&second_thread_tcb, second_thread_stack, sizeof(second_thread_stack), PRIORITY_MAIN-1, CREATE_STACKTEST | CREATE_SLEEPING | CREATE_WOUT_YIELD, second_thread, "sleeper");
if (pid < 0) {
puts("Error creating second_thread! Stopping test.");
while(1);
}
while(1) {
i++;
printf(" main: running. integer=%i, i=%i.\n", integer, i);
2010-11-02 17:23:10 +01:00
if (i % 1 == 0) {
thread_print_all();
printf("Waking up sleeper.\n");
thread_wakeup(pid);
2010-11-02 17:23:10 +01:00
thread_print_all();
2010-10-28 11:22:57 +02:00
thread_yield();
}
}
}