Add benchmark modules.
[bertos.git] / boards / at91sam7x-ek / benchmark / kernel_footprint_preempt / main.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 Preemptive footprint benchmark.
38  * This simple application show you the kernel footprint for a typical use. Genereally
39  * in the application that we want use the kernel, we use a process, send ad recv message
40  * from process or using signals.
41  * Compile this application and see the size of the bin file generated, typically, whitout
42  * any compile optimization, the size shold be about 4,5Kbyte (whit arm-2009q3 toolchain), if
43  * we optimize the compilation for size using the -Os gcc flag the image size result about
44  * 2,2Kbyte.
45  *
46  * Note by default this project compile without any compile optimization, so if we
47  * want to try to change it go to kernel_footprint_preempt_user.mk, and add the flag
48  * in the section kernel_footprint_preempt_USER_CPPFLAGS.
49  * To see the flag optimization effects you shoul clean the project and rebuild it.
50  */
51
52 #include <cpu/irq.h>
53 #include <kern/proc.h>
54 #include <kern/signal.h>
55 #include <kern/msg.h>
56
57 MsgPort in_port;
58
59 static void init(void)
60 {
61     IRQ_ENABLE;
62     proc_init();
63 }
64
65 static PROC_DEFINE_STACK(proc1_stack, KERN_MINSTACKSIZE);
66
67 static void proc1_main(void)
68 {
69
70 }
71
72 int main(void)
73 {
74     init();
75     // generate code for process
76     struct Process *p = proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
77     proc_setPri(p, 5);
78     proc_yield();
79     // generate code for msg
80     Msg msg;
81     msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
82     msg_put(&in_port, &msg);
83     msg_peek(&in_port);
84     Msg *msg_re = msg_get(&in_port);
85     msg_reply(msg_re);
86     // generate code for signals
87     sig_send(p, SIG_USER0);
88     sig_wait(SIG_USER0);
89
90     return 0;
91 }