2014-02-03 22:47:31 +01:00
|
|
|
/*
|
2014-05-14 15:11:01 +02:00
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
2014-02-03 22:47:31 +01:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* 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.
|
2014-02-03 22:47:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup examples
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief IPC pingpong application
|
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2014-05-14 15:11:01 +02:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2014-02-03 22:47:31 +01:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2014-01-06 10:10:47 +01:00
|
|
|
#include <stdio.h>
|
2014-03-24 11:08:42 +01:00
|
|
|
|
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
2014-01-06 10:10:47 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
void *second_thread(void *arg)
|
2014-01-25 11:22:09 +01:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("2nd thread started, pid: %" PRIkernel_pid "\n", thread_getpid());
|
2014-01-06 10:10:47 +01:00
|
|
|
msg_t m;
|
|
|
|
|
2014-01-25 11:22:09 +01:00
|
|
|
while (1) {
|
2014-01-06 10:10:47 +01:00
|
|
|
msg_receive(&m);
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("2nd: Got msg from %" PRIkernel_pid "\n", m.sender_pid);
|
2014-01-06 10:10:47 +01:00
|
|
|
m.content.value++;
|
|
|
|
msg_reply(&m, &m);
|
|
|
|
}
|
2014-03-04 20:20:01 +01:00
|
|
|
|
|
|
|
return NULL;
|
2014-01-06 10:10:47 +01:00
|
|
|
}
|
|
|
|
|
2015-04-28 20:02:05 +02:00
|
|
|
char second_thread_stack[THREAD_STACKSIZE_MAIN];
|
2014-01-06 10:10:47 +01:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2014-05-14 15:11:01 +02:00
|
|
|
printf("Starting IPC Ping-pong example...\n");
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("1st thread started, pid: %" PRIkernel_pid "\n", thread_getpid());
|
2014-01-06 10:10:47 +01:00
|
|
|
|
|
|
|
msg_t m;
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
kernel_pid_t pid = thread_create(second_thread_stack, sizeof(second_thread_stack),
|
2015-12-02 11:59:53 +01:00
|
|
|
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
|
2014-03-04 20:20:01 +01:00
|
|
|
second_thread, NULL, "pong");
|
2014-01-25 11:22:09 +01:00
|
|
|
|
2014-01-06 10:10:47 +01:00
|
|
|
m.content.value = 1;
|
|
|
|
|
2014-01-25 11:22:09 +01:00
|
|
|
while (1) {
|
|
|
|
msg_send_receive(&m, &m, pid);
|
2014-05-14 15:11:01 +02:00
|
|
|
printf("1st: Got msg with content %u\n", (unsigned int)m.content.value);
|
2014-01-06 10:10:47 +01:00
|
|
|
}
|
|
|
|
}
|