a752c7ab
elopes
add first test an...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief simple thread flags test application
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include "thread.h"
#include "xtimer.h"
static char stack[THREAD_STACKSIZE_MAIN];
volatile unsigned done;
static void *_thread(void *arg)
{
(void) arg;
thread_flags_t flags;
puts("thread(): waiting for 0x1...");
flags = thread_flags_wait_any(0x1);
printf("thread(): received flags: 0x%04x\n", (unsigned)flags & 0xFFFF);
puts("thread(): waiting for 0x1 || 0x64...");
flags = thread_flags_wait_any(0x1 | 0x64);
printf("thread(): received flags: 0x%04x\n", (unsigned)flags & 0xFFFF);
puts("thread(): waiting for 0x2 && 0x4...");
flags = thread_flags_wait_all(0x2 | 0x4);
printf("thread(): received flags: 0x%04x\n", (unsigned)flags & 0xFFFF);
puts("thread(): waiting for any flag, one by one");
flags = thread_flags_wait_one(0xFFFF);
printf("thread(): received flags: 0x%04x\n", (unsigned)flags & 0xFFFF);
puts("thread(): waiting for any flag, one by one");
flags = thread_flags_wait_one(0xFFFF);
printf("thread(): received flags: 0x%04x\n", (unsigned)flags & 0xFFFF);
done = 1;
return NULL;
}
static void _set(thread_t *thread, thread_flags_t flags)
{
printf("main(): setting flag 0x%04x\n", (unsigned)flags & 0xFFFF);
thread_flags_set(thread, flags);
}
int main(void)
{
puts("main starting");
kernel_pid_t pid = thread_create(stack,
sizeof(stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
_thread,
NULL,
"second_thread");
thread_t *thread = (thread_t*) thread_get(pid);
_set(thread, 0x1);
_set(thread, 0x64);
_set(thread, 0x1);
_set(thread, 0x8);
_set(thread, 0x2);
_set(thread, 0x4);
while(!done) {};
puts("main: setting 100ms timeout...");
xtimer_t t;
uint32_t before = xtimer_now_usec();
xtimer_set_timeout_flag(&t, 100000);
thread_flags_wait_any(THREAD_FLAG_TIMEOUT);
uint32_t diff = xtimer_now_usec() - before;
printf("main: timeout triggered. time passed: %uus\n", (unsigned)diff);
puts("test finished.");
return 0;
}
|