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