main.c
1.42 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
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (C) 2014 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 examples
* @{
*
* @file
* @brief IPC pingpong application
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include "thread.h"
#include "msg.h"
void *second_thread(void *arg)
{
(void) arg;
printf("2nd thread started, pid: %" PRIkernel_pid "\n", thread_getpid());
msg_t m;
while (1) {
msg_receive(&m);
printf("2nd: Got msg from %" PRIkernel_pid "\n", m.sender_pid);
m.content.value++;
msg_reply(&m, &m);
}
return NULL;
}
char second_thread_stack[THREAD_STACKSIZE_MAIN];
int main(void)
{
printf("Starting IPC Ping-pong example...\n");
printf("1st thread started, pid: %" PRIkernel_pid "\n", thread_getpid());
msg_t m;
kernel_pid_t pid = thread_create(second_thread_stack, sizeof(second_thread_stack),
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
second_thread, NULL, "pong");
m.content.value = 1;
while (1) {
msg_send_receive(&m, &m, pid);
printf("1st: Got msg with content %u\n", (unsigned int)m.content.value);
}
}