Contiki 2.5
sprofiling_arch.c
1 #include <stdio.h>
2 #include <string.h>
3 
4 #include "contiki.h"
5 #include <avr/interrupt.h>
6 
7 #include "sys/sprofiling.h"
8 
9 
10 /* For the INGA platform */
11 #if defined (__AVR_ATmega1284P__) && AVR_CONF_USE32KCRYSTAL
12 ISR(TIMER2_COMPB_vect) __attribute__ ((no_instrument_function));
13 
14 ISR(TIMER2_COMPB_vect)
15 {
16  uint8_t i;
17  void *pc;
18  uint8_t tccr;
19 
20  /* Move the interrupt around to avoid aliasing effects*/
21  OCR2B = (OCR2B + 29)%(32768/8/CLOCK_CONF_SECOND);
22  tccr = TCCR2B;
23 
24  TCCR2B &= ~(_BV(CS20)|_BV(CS21)|_BV(CS22));
25  for (i=0;i<OCR2B%7;i++)
26  asm volatile("nop");
27  TCCR2B = tccr;
28 
29  pc = __builtin_return_address(0);
30 
31  /* The AVR stores the word offset - not the address itself
32  * in the PC - beware when editing */
33  sprofiling_add_sample(pc);
34 }
35 
36 inline void sprofiling_arch_start(void)
37 {
38  /* Clear any pending interrupt and activate the interrupt again */
39  TIFR2 |= _BV(OCF2B);
40  TIMSK2 |= _BV(OCIE2B);
41 }
42 
43 inline void sprofiling_arch_stop(void)
44 {
45  TIMSK2 &= ~_BV(OCIE2B);
46 }
47 
48 void sprofiling_arch_init(void)
49 {
50  /* Call the interrupt at the same time the time is updated */
51  OCR2B = 32768/8/CLOCK_CONF_SECOND - 1;
52 }
53 
54 #else
55 #error "Please define your own arch specific profiling functions."
56 #endif