Skip to content
Snippets Groups Projects
Commit bdad2ba9 authored by Hauke Petersen's avatar Hauke Petersen
Browse files

Merge pull request #1171 from haukepetersen/example_ipcpingpong_readme

examples: added README.md to ipc_pingpong example
parents e8e7f3ab 47ce60cc
No related branches found
No related tags found
No related merge requests found
IPC Pingpong!
=============
This example is to illustrate the usage of RIOTs IPC messaging system.
The application starts a second thread (in addition to the main thread) and sends messages between
these two threads. The main thread calls `thread_send_receive()` in an endless loop. The second
thread receives the message, prints `2nd: got msg from x` to stdout and sends a reply message with
an incrementing number back to the main thread. The main thread then prints the number it received
from the 2nd thread.
The correct output should look like this:
```
This is RIOT! (Version: xxx)
kernel_init(): jumping into first task...
Starting IPC Ping-pong example...
1st thread started, pid: 1
2nd thread started, pid: 2
2nd: Got msg from 1
1st: Got msg with content 2
2nd: Got msg from 1
1st: Got msg with content 3
2nd: Got msg from 1
1st: Got msg with content 4
2nd: Got msg from 1
1st: Got msg with content 5
2nd: Got msg from 1
1st: Got msg with content 6
2nd: Got msg from 1
1st: Got msg with content 7
2nd: Got msg from 1
1st: Got msg with content 8
2nd: Got msg from 1
1st: Got msg with content 9
2nd: Got msg from 1
1st: Got msg with content 10
[...]
```
/* /*
* Copyright (C) 2013 Freie Universität Berlin * Copyright (C) 2014 Freie Universität Berlin
* *
* This file is subject to the terms and conditions of the GNU Lesser General * This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more * Public License. See the file LICENSE in the top level directory for more
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* @brief IPC pingpong application * @brief IPC pingpong application
* *
* @author Kaspar Schleiser <kaspar@schleiser.de> * @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* *
* @} * @}
*/ */
...@@ -26,12 +27,12 @@ ...@@ -26,12 +27,12 @@
void second_thread(void) void second_thread(void)
{ {
printf("second_thread starting.\n"); printf("2nd thread started, pid: %i\n", thread_getpid());
msg_t m; msg_t m;
while (1) { while (1) {
msg_receive(&m); msg_receive(&m);
printf("2nd: got msg from %i\n", m.sender_pid); printf("2nd: Got msg from %i\n", m.sender_pid);
m.content.value++; m.content.value++;
msg_reply(&m, &m); msg_reply(&m, &m);
} }
...@@ -41,7 +42,8 @@ char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN]; ...@@ -41,7 +42,8 @@ char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
int main(void) int main(void)
{ {
printf("Hello world!\n"); printf("Starting IPC Ping-pong example...\n");
printf("1st thread started, pid: %i\n", thread_getpid());
msg_t m; msg_t m;
...@@ -53,6 +55,6 @@ int main(void) ...@@ -53,6 +55,6 @@ int main(void)
while (1) { while (1) {
msg_send_receive(&m, &m, pid); msg_send_receive(&m, &m, pid);
printf("Got msg with content %u\n", m.content.value); printf("1st: Got msg with content %u\n", (unsigned int)m.content.value);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment