111b7910b4191dcb23f827120dbca59e6ac48350
[bertos.git] / bertos / benchmark / kernel_footprint.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Luca Ottaviano <lottaviano@develer.com>
34  * \author Andrea Righi <arighi@develer.com>
35  * \author Daniele Basile <asterix@develer.com>
36  *
37  * \brief Kernel footprint benchmark.
38  */
39
40 #include "kernel_footprint.h"
41
42 #include <cpu/irq.h>
43
44 #include <kern/proc.h>
45 #include <kern/signal.h>
46 #include <kern/msg.h>
47
48 MsgPort in_port;
49
50 static void init(void)
51 {
52     IRQ_ENABLE;
53     proc_init();
54 }
55
56 static PROC_DEFINE_STACK(proc1_stack, KERN_MINSTACKSIZE);
57
58 static NORETURN void proc1_main(void)
59 {
60         int i;
61         for(;;)
62         {
63                 i++;
64         }
65 }
66
67 void kernel_footprint(void)
68 {
69     init();
70
71         // generate code for process
72     struct Process *p = proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
73     proc_setPri(p, 5);
74     proc_yield();
75
76         // generate code for msg
77     Msg msg;
78     msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
79     msg_put(&in_port, &msg);
80     msg_peek(&in_port);
81     Msg *msg_re = msg_get(&in_port);
82     msg_reply(msg_re);
83
84     // generate code for signals
85     sig_send(p, SIG_USER0);
86     sig_wait(SIG_USER0);
87 }