2 * Copyright Droids Corporation (2007)
3 * Olivier MATZ <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: main.c,v 1.1.2.2 2007-10-28 22:31:58 zer0 Exp $
28 #include <aversive/wait.h>
29 #include <scheduler.h>
35 * The TIMER2 is used to randomly interrupt the running program and
36 * display the address of the interrupted function on the serial port.
38 * The addresses can be parsed using the python program in the same
40 * ./parse_symbols.py compiler_files/main.sym
42 * The stdin of the python script is the list of addresses. Below is
45 * 50.88% (145/285) time_wait_ms[00000b5a]
46 * 13.33% (038/285) test2[00000130]
47 * 11.23% (032/285) time_get_s[0000069e]
48 * 8.07% (023/285) main[00000156]
49 * 7.37% (021/285) test1[00000122]
50 * 4.56% (013/285) scheduler_interrupt[00000dcc]
51 * 4.56% (013/285) time_increment[000007e8]
55 #define PROFILE_TIME 10
58 void __attribute__ ((noinline)) dump_reg(uint16_t pc)
60 static volatile uint8_t cpt = PROFILE_TIME;
63 OCR2 = 0x80 + (rand()&0x7F);
79 void SIG_OUTPUT_COMPARE2(void) __attribute__ ((signal , naked, __INTR_ATTRS));
81 void SIG_OUTPUT_COMPARE2(void)
83 asm volatile("push r1" "\n\t"
84 "push __tmp_reg__" "\n\t"
87 "in __tmp_reg__,__SREG__" "\n\t"
88 "push __tmp_reg__" "\n\t"
91 /* save used regs (see avr-gcc doc about used regs) */
105 /* load sp in r30/r31 */
106 "in r30, __SP_L__" "\n\t"
107 "in r31, __SP_H__" "\n\t"
109 /* point to saved PC */
110 "subi r30, lo8(-16)" "\n\t"
111 "sbci r31, hi8(-16)" "\n\t"
113 /* load Program Counter into r24-r25 */
114 "ldd r25, Z+0" "\n\t"
115 "ldd r24, Z+1" "\n\t"
117 /* call dump_reg, params are in r24-25 */
118 "call dump_reg" "\n\t"
135 "pop __tmp_reg__" "\n\t"
136 "out __SREG__, __tmp_reg__" "\n\t"
139 "pop __tmp_reg__" "\n\t"
149 void __attribute__((noinline)) test1(void)
154 void __attribute__((noinline)) test2(void)
161 void test_sched(void * dummy)
170 fdevopen(uart0_dev_send, uart0_dev_recv);
177 printf("Start profiling during 10 secs\n");
179 scheduler_add_periodical_event(test_sched, NULL, 100000L / SCHEDULER_UNIT);
186 while(time_get_s() < 10) {
192 printf("Finished\n");