2 * Copyright (C) 2007 Anton Blad
3 * Copyright (C) 2007 Fredrik Kuivinen
4 * Copyright (C) 2007 Jakob Rosén
6 * This file is licensed under GPL v2.
11 #include "trutprofile.h"
14 #include <avr/interrupt.h>
16 static uint16_t profile_stamps
[NPROFILE
];
17 static uint16_t profile_mwc
[NPROFILE
];
19 volatile static uint8_t timer0_high
;
21 // Allocated measurements:
22 // 0 - TIMER1_COMPA interrupt
23 // 1 - TIMER1_OVF interrupt
24 // 2 - TIMER1_CAPT interrupt
26 // Atomic read of timer stamp.
27 static inline uint16_t profile_stamp()
29 // Save interrupt enable flag.
37 if(low
< 0xf0 && (TIFR0
& _BV(TOV0
)))
38 high
= timer0_high
+ 1;
42 // Reenable interrupts.
45 return (high
<< 8) | low
;
52 for(i
= 0; i
< NPROFILE
; i
++)
54 profile_stamps
[i
] = profile_mwc
[i
] = 0;
60 #if PROFILE_PRESCALE == 1
62 #elif PROFILE_PRESCALE == 8
64 #elif PROFILE_PRESCALE == 64
65 TCCR0B
= _BV(CS00
) | _BV(CS01
);
66 #elif PROFILE_PRESCALE == 256
69 #error Invalid PROFILE_PRESCALE value
74 void profile_start(uint8_t m
)
76 profile_stamps
[m
] = profile_stamp();
79 void profile_stop(uint8_t m
)
81 uint16_t len
= profile_stamp() - profile_stamps
[m
];
83 if(len
> profile_mwc
[m
])
87 uint16_t profile_wc(uint8_t m
)
89 return profile_mwc
[m
];
97 #endif // TRUT_PROFILE