00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027
00028 #include <aversive/wait.h>
00029 #include <scheduler.h>
00030 #include <timer.h>
00031 #include <time.h>
00032 #include <uart.h>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #define PROFILE_TIME 10
00056 volatile int a = 0;
00057
00058 void __attribute__ ((noinline)) dump_reg(uint16_t pc)
00059 {
00060 static volatile uint8_t cpt = PROFILE_TIME;
00061
00062 if (cpt == 1) {
00063 OCR2 = 0x80 + (rand()&0x7F);
00064
00065 TCCR2 = 2;
00066 TCNT2 = 0;
00067 }
00068 else if (cpt == 0) {
00069 OCR2 = 0;
00070 TCCR2 = 4;
00071 TCNT2 = 0;
00072 cpt = PROFILE_TIME;
00073 printf("%.4x\n", pc);
00074 }
00075 cpt--;
00076 }
00077
00078
00079 void SIG_OUTPUT_COMPARE2(void) __attribute__ ((signal , naked, __INTR_ATTRS));
00080
00081 void SIG_OUTPUT_COMPARE2(void)
00082 {
00083 asm volatile("push r1" "\n\t"
00084 "push __tmp_reg__" "\n\t"
00085
00086
00087 "in __tmp_reg__,__SREG__" "\n\t"
00088 "push __tmp_reg__" "\n\t"
00089 "eor r1, r1" "\n\t"
00090
00091
00092 "push r18" "\n\t"
00093 "push r19" "\n\t"
00094 "push r20" "\n\t"
00095 "push r21" "\n\t"
00096 "push r22" "\n\t"
00097 "push r23" "\n\t"
00098 "push r24" "\n\t"
00099 "push r25" "\n\t"
00100 "push r26" "\n\t"
00101 "push r27" "\n\t"
00102 "push r30" "\n\t"
00103 "push r31" "\n\t"
00104
00105
00106 "in r30, __SP_L__" "\n\t"
00107 "in r31, __SP_H__" "\n\t"
00108
00109
00110 "subi r30, lo8(-16)" "\n\t"
00111 "sbci r31, hi8(-16)" "\n\t"
00112
00113
00114 "ldd r25, Z+0" "\n\t"
00115 "ldd r24, Z+1" "\n\t"
00116
00117
00118 "call dump_reg" "\n\t"
00119
00120
00121 "pop r31" "\n\t"
00122 "pop r30" "\n\t"
00123 "pop r27" "\n\t"
00124 "pop r26" "\n\t"
00125 "pop r25" "\n\t"
00126 "pop r24" "\n\t"
00127 "pop r23" "\n\t"
00128 "pop r22" "\n\t"
00129 "pop r21" "\n\t"
00130 "pop r20" "\n\t"
00131 "pop r19" "\n\t"
00132 "pop r18" "\n\t"
00133
00134
00135 "pop __tmp_reg__" "\n\t"
00136 "out __SREG__, __tmp_reg__" "\n\t"
00137
00138
00139 "pop __tmp_reg__" "\n\t"
00140 "pop r1" "\n\t"
00141
00142 "reti" "\n\t"
00143 :
00144 :
00145 );
00146 }
00147
00148
00149 void __attribute__((noinline)) test1(void)
00150 {
00151 a=2;
00152 }
00153
00154 void __attribute__((noinline)) test2(void)
00155 {
00156 a=1;
00157 a=2;
00158 a=3;
00159 }
00160
00161 void test_sched(void * dummy)
00162 {
00163 time_wait_ms(50);
00164 }
00165
00166
00167 int main(void)
00168 {
00169 uart_init();
00170 fdevopen(uart0_dev_send, uart0_dev_recv);
00171 timer_init();
00172 scheduler_init();
00173 time_init(200);
00174
00175 srand(0x1337);
00176 sei();
00177 printf("Start profiling during 10 secs\n");
00178
00179 scheduler_add_periodical_event(test_sched, NULL, 100000L / SCHEDULER_UNIT);
00180
00181 OCR2 = 0;
00182 TCNT2 = 0;
00183 TCCR2 = 4;
00184 sbi(TIMSK, OCIE2);
00185
00186 while(time_get_s() < 10) {
00187 test1();
00188 test2();
00189 };
00190
00191 TCCR2=0;
00192 printf("Finished\n");
00193 while(1);
00194
00195 return 0;
00196 }