4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
33 * \brief Message test.
37 * \author Daniele Basile <asterix@develer.com>
40 #include <cfg/cfg_timer.h>
41 #include <cfg/debug.h>
43 #include <cfg/compiler.h>
46 #include <kern/proc.h>
49 #include <drv/timer.h>
53 static MsgPort test_port;
55 // A test message with two parameters and a result.
65 // Receive messages and do something boring with them.
66 static void receiver_proc(void)
71 kprintf("Proc[%d]..\n", 1);
73 kprintf("Proc[%d] get message\n", 1);
74 rec_msg = containerof(msg_get(&test_port), TestMsg, msg);
75 // Do something with the message
76 rec_msg->result = rec_msg->x + rec_msg->y;
77 kprintf("Proc[%d] process message x[%d],y[%d],res[%d]\n", 1, rec_msg->x, rec_msg->y, rec_msg->result);
78 msg_reply(&rec_msg->msg);
79 kprintf("Proc[%d] reply\n", 1);
83 static cpu_stack_t receiver_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)];
90 kprintf("Run Message test..\n");
92 MsgPort test_reply_port;
96 struct Process *recv = proc_new(receiver_proc, NULL, sizeof(receiver_stack), receiver_stack);
97 msg_initPort(&test_port, event_createSignal(recv, SIG_SINGLE));
98 msg_initPort(&test_reply_port, event_createSignal(proc_current(), SIG_SINGLE));
100 // Fill-in first message and send it out.
103 kprintf("invio il msg..\n");
104 msg1.msg.replyPort = &test_reply_port;
105 msg_put(&test_port, &msg1.msg);
107 // Wait for a reply...
108 kprintf("prima sig wait..\n");
109 sig_wait(SIG_SINGLE);
110 kprintf("dopo sig wait..\n");
111 reply = containerof(msg_get(&test_reply_port), TestMsg, msg);
112 ASSERT(reply != NULL);
113 ASSERT(reply->result == 5);
118 int msg_testSetup(void)
122 #if CONFIG_KERN_PREEMPT
123 kprintf("Init Interrupt (preempt mode)..");
128 kprintf("Init Timer..");
132 kprintf("Init Process..");
138 int msg_testTearDown(void)
140 kputs("TearDown Message test.\n");