Add benchmark for preempt kernel.
[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  */
50
51 #include <cpu/irq.h>
52 #include <kern/proc.h>
53 #include <kern/signal.h>
54 #include <kern/msg.h>
55
56 MsgPort in_port;
57
58 static void init(void)
59 {
60     IRQ_ENABLE;
61     proc_init();
62 }
63
64 static PROC_DEFINE_STACK(proc1_stack, KERN_MINSTACKSIZE);
65
66 static void proc1_main(void)
67 {
68
69 }
70
71 int main(void)
72 {
73     init();
74     // generate code for process
75     struct Process *p = proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
76     proc_setPri(p, 5);
77     proc_yield();
78     // generate code for msg
79     Msg msg;
80     msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
81     msg_put(&in_port, &msg);
82     msg_peek(&in_port);
83     Msg *msg_re = msg_get(&in_port);
84     msg_reply(msg_re);
85     // generate code for signals
86     sig_send(p, SIG_USER0);
87     sig_wait(SIG_USER0);
88
89     return 0;
90 }