1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/xtimer_msg_receive_timeout/main.c
Oleg Hahm 91432faccb tests: remove timer after each loop
...in xtimer_msg_receive_timeout
2016-03-01 21:44:19 +01:00

52 lines
1.3 KiB
C

/*
* Copyright (C) 2015 INRIA
*
* 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()
*
* This test will start sequentially start 10 xtimers to send a
* IPC msg, alternating with an interval of 900ms and 1100ms
* respectively. Everytime a timer was set, it will wait for a
* message for at most 1000ms. This should succeed and fail in an
* alternating manner.
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
*
* @}
*/
#include "thread.h"
#include "msg.h"
#include "xtimer.h"
#include "timex.h"
int main(void)
{
msg_t m, tmsg;
xtimer_t t;
int64_t offset = -1000;
tmsg.type = 44;
for (int i = 0; i < 10; i++) {
xtimer_set_msg(&t, SEC_IN_USEC + offset, &tmsg, sched_active_pid);
if (xtimer_msg_receive_timeout(&m, SEC_IN_USEC) < 0) {
puts("Timeout!");
}
else {
printf("Message received: %" PRIu16 "\n", m.type);
}
offset = (offset < 0) ? 1000 : -1000;
xtimer_remove(&t);
}
return 0;
}