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
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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"
|
|
|
|
#include "kernel.h"
|
2014-01-06 10:10:47 +01:00
|
|
|
|
2014-01-25 11:22:09 +01:00
|
|
|
void second_thread(void)
|
|
|
|
{
|
2014-05-14 15:11:01 +02:00
|
|
|
printf("2nd thread started, pid: %i\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-05-14 15:11:01 +02:00
|
|
|
printf("2nd: Got msg from %i\n", m.sender_pid);
|
2014-01-06 10:10:47 +01:00
|
|
|
m.content.value++;
|
|
|
|
msg_reply(&m, &m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char second_thread_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2014-05-14 15:11:01 +02:00
|
|
|
printf("Starting IPC Ping-pong example...\n");
|
|
|
|
printf("1st thread started, pid: %i\n", thread_getpid());
|
2014-01-06 10:10:47 +01:00
|
|
|
|
|
|
|
msg_t m;
|
|
|
|
|
2014-01-25 11:22:09 +01:00
|
|
|
int pid = thread_create(second_thread_stack, sizeof(second_thread_stack),
|
2014-03-16 19:18:25 +01:00
|
|
|
PRIORITY_MAIN - 1, CREATE_STACKTEST,
|
2014-01-25 11:22:09 +01:00
|
|
|
second_thread, "pong");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|