main.c
1.19 KB
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
/*
* Copyright (C) 2015 INRIA
* 2017 HAW Hamburg
*
* 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 test application for xtimer_msg_receive_timeout()
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#include <stdio.h>
#include "thread.h"
#include "msg.h"
#include "xtimer.h"
#include "timex.h"
#define TEST_PERIOD (100LU * US_PER_MS) /* 100ms in US */
#define TEST_COUNT (10LU)
int main(void)
{
msg_t m, tmsg;
xtimer_t t;
int64_t offset = -(TEST_PERIOD/10);
tmsg.type = 42;
puts("[START]");
for (unsigned i = 0; i < TEST_COUNT; i++) {
xtimer_set_msg(&t, TEST_PERIOD + offset, &tmsg, sched_active_pid);
if (xtimer_msg_receive_timeout(&m, TEST_PERIOD) < 0) {
puts("Timeout!");
msg_receive(&m);
}
else {
printf("Message: %" PRIu16 "\n", m.type);
}
/* flip sign */
offset *= (-1);
}
puts("[SUCCESS]");
return 0;
}