]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/performance_test.c
fixing some bugs of performance measurment
[avr-crypto-lib.git] / test_src / performance_test.c
index ad745fc4c96a0b6480bb25fb563500f911040689..a5e897f16702a9ebdc3e4e13b334ab60c620f578 100644 (file)
  * author: Daniel Otte
  * email:  daniel.otte@rub.de
  * license: GPLv3
- * 
- * 
+ *
+ *
  **/
+
 #include "config.h"
 #include <string.h>
 #include <stdint.h>
 
 
 
-uint32_t ovfcounter;
+static volatile uint32_t ovfcounter;
 
-uint16_t const_overhead=0;
-uint16_t int_overhead=0;
+static uint16_t const_overhead=0;
+static uint16_t int_overhead=0;
 
 ISR(TIMER1_OVF_vect){
        ovfcounter++;
 }
 
 void calibrateTimer(void){
-       volatile uint8_t i;
+       volatile uint8_t i=0;
        startTimer(1);
        stopTimer();
        const_overhead = TCNT1;
@@ -67,15 +67,14 @@ void startTimer(uint8_t granularity){
        TCNT1  = 0;
        ovfcounter = 0;
        TCCR1A = 0x00;
-       TIMSK &= 0xC3;
-       TIMSK |= _BV(TOIE1); /* enable TOIE1 */
+       TIMSK  = _BV(TOIE1); /* enable TOIE1 */
        TCCR1B = granularity & 0x7;     /* start timer */
 }
 
 uint64_t stopTimer(void){
        TCCR1B = 0; /* stop timer */
        uint64_t ret;
-       ret = (ovfcounter<<16) | TCNT1;
+       ret = (((uint64_t)ovfcounter)<<16) | TCNT1;
        ret -= const_overhead;
        ret -= ovfcounter * int_overhead;
        return ret;
@@ -83,7 +82,7 @@ uint64_t stopTimer(void){
 
 void getOverhead(uint16_t* constoh, uint16_t* intoh){
        *constoh = const_overhead;
-       *intoh   = int_overhead; 
+       *intoh   = int_overhead;
 }
 
 void print_time_P(PGM_P s, uint64_t t){