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
|
/*
* Copyright (C) 2017 Freie Universitรคt Berlin
*
* 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 evtimer_msg test application
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include "evtimer_msg.h"
#include "thread.h"
#include "msg.h"
#define WORKER_MSG_QUEUE_SIZE (8)
msg_t worker_msg_queue[WORKER_MSG_QUEUE_SIZE];
static char worker_stack[THREAD_STACKSIZE_MAIN];
static evtimer_t evtimer;
static evtimer_msg_event_t events[] = {
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "1" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "2" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "3" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "4" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "5" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "6" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "7" } } },
{ .event = { .offset = 0 }, .msg = { .content = { .ptr = "8" } } },
};
#define NEVENTS (sizeof(events) / sizeof(evtimer_msg_event_t))
/* This thread will print the drift to stdout once per second */
void *worker_thread(void *arg)
{
(void) arg;
msg_init_queue(worker_msg_queue, WORKER_MSG_QUEUE_SIZE);
while (1) {
char *ctx;
msg_t m;
msg_receive(&m);
ctx = m.content.ptr;
printf("received msg \"%s\"\n", ctx);
}
}
int main(void)
{
evtimer_init_msg(&evtimer);
/* create worker thread */
kernel_pid_t pid = thread_create(worker_stack, sizeof(worker_stack),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
worker_thread, NULL, "worker");
while (1) {
for (unsigned i = 0; i < NEVENTS; i++) {
evtimer_add_msg(&evtimer, &events[i], pid);
}
}
}
|