]> git.cryptolib.org Git - avr-crypto-lib.git/blob - performance_test.c
91d4f1cdb5c7164e1ca01ce5a697acd3d152aacc
[avr-crypto-lib.git] / performance_test.c
1 /*
2  * 
3  * 
4  * 
5  */
6
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <avr/io.h>
10 #include <avr/interrupt.h>
11 #include "performance_test.h"
12
13 uint32_t ovfcounter;
14
15 uint16_t const_overhead=0;
16 uint16_t int_overhead=0;
17
18 ISR(TIMER1_OVF_vect){
19         ovfcounter++;
20 }
21
22 void calibrateTimer(void){
23         startTimer(1);
24         stopTimer();
25         const_overhead = TCNT1;
26         startTimer(1);
27         TCNT1=0xFFFE;
28         ; ; ; ;
29 //      asm volatile("NOP\n"::); asm volatile("NOP\n"::);
30         stopTimer();
31         int_overhead = TCNT1;
32 }
33
34 void startTimer(uint8_t granularity){
35         TCCR1B = 0; /* stop timer */
36         TCNT1  = 0;
37         ovfcounter = 0;
38         TCCR1A = 0x00;
39         TIMSK &= 0xC3;
40         TIMSK |= _BV(2); /* enable TOIE1 */
41         TCCR1B = granularity & 0x7;     /* start timer */
42 }
43
44 uint64_t stopTimer(void){
45         TCCR1B = 0; /* stop timer */
46         uint64_t ret;
47         ret = (ovfcounter<<16) | TCNT1;
48         ret -= const_overhead;
49         ret -= ovfcounter * int_overhead;
50         return ret;
51 }
52
53 void getOverhead(uint16_t* constoh, uint16_t* intoh){
54         *constoh = const_overhead;
55         *intoh   = int_overhead; 
56 }
57
58
59
60