]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
some minor improvments and bug fixes
authorbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 04:07:04 +0000 (06:07 +0200)
committerbg <daniel.otte@rub.de>
Tue, 18 Sep 2012 04:07:04 +0000 (06:07 +0200)
Makefile_m644_conf.inc
bcal/bcal-performance.c
bigint/bigint.c
mkfiles/001_cli_std.mk
stack_measuring.S
test_src/cli-core.S
test_src/cli-stub.c
test_src/cli.h
test_src/main-test-common.c
test_src/uart_i-asm.S
test_src/uart_i.h

index 601463560e9fed456b6b118d3a0ab98295721d53..1aa297f4a5b54cf3ce56c5595c417e79602b286e 100644 (file)
@@ -14,7 +14,7 @@ override ASFLAGS         = -mmcu=$(MCU_TARGET) -Wa,--gdwarf-2
 
 #PROGRAMMER     = avr911
 #PROG_PORT      = /dev/ttyUSB1
-PROGRAMMER     = usbasp
+PROGRAMMER     = avrispmkII
 PROG_PORT      = usb
 DEFS           = -D$(call uc, $(MCU_TARGET)) -DF_CPU=$(F_CPU)
 FLASHCMD       = avrdude -p $(MCU_TARGET) -P $(PROG_PORT) -c $(PROGRAMMER) -U flash:w:# no space at the end
index feeda105d716d7da0df967e00660f183d76603ee..267ec1c1aa6bde23a6d2520e31711575249d1c39 100644 (file)
 #include "performance_test.h"
 #include "stack_measuring.h"
 #include "cli.h"
+#include "uart_i.h"
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 #include <avr/pgmspace.h>
 
 #define PATTERN_A 0xAA
 #define PATTERN_B 0x55
 
-
+/*
 static
 void printvalue(unsigned long v){
        char str[20];
@@ -51,6 +53,7 @@ void printvalue(unsigned long v){
        }
        cli_putstr(str);
 }
+*/
 
 void bcal_performance(const bcdesc_t* bcd){
        bcdesc_t bc;
@@ -62,30 +65,22 @@ void bcal_performance(const bcdesc_t* bcd){
        uint64_t t;
        uint8_t i;
 
-       if(bc.type!=BCDESC_TYPE_BLOCKCIPHER)
+       if(bc.type != BCDESC_TYPE_BLOCKCIPHER)
                return;
        calibrateTimer();
        print_overhead();
-       cli_putstr_P(PSTR("\r\n\r\n === "));
-       cli_putstr_P(bc.name);
-       cli_putstr_P(PSTR(" performance === "
-                         "\r\n    type:             blockcipher"
-                         "\r\n    keysize (bits):     "));
-       printvalue(keysize);
-
-       cli_putstr_P(PSTR("\r\n    ctxsize (bytes):    "));
-       printvalue(bc.ctxsize_B);
-
-       cli_putstr_P(PSTR("\r\n    blocksize (bits):   "));
-       printvalue(bc.blocksize_b);
-
-
-
+       printf_P(PSTR("\n\n === %S"), bc.name);
+       printf_P(PSTR(" performance === \n"
+                     "    type:             blockcipher\n"
+                     "    keysize (bits):     %5"PRIu16"\n"), keysize);
+       printf_P(PSTR("    ctxsize (bytes):    %5"PRIu16"\n"), bc.ctxsize_B);
+       printf_P(PSTR("    blocksize (bits):   %5"PRIu16"\n"), bc.blocksize_b);
+       uart0_flush();
        t=0;
        if(bc.init.init1){
-               if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
+               if((bc.flags & BC_INIT_TYPE) == BC_INIT_TYPE_1){
                        for(i=0; i<32; ++i){
-                               startTimer(0);
+                               startTimer(1);
                                START_TIMER;
                                (bc.init.init1)(key, &ctx);
                                STOP_TIMER;
@@ -96,7 +91,7 @@ void bcal_performance(const bcdesc_t* bcd){
                        }
                } else {
                        for(i=0; i<32; ++i){
-                               startTimer(0);
+                               startTimer(1);
                                START_TIMER;
                                (bc.init.init2)(key, keysize, &ctx);
                                STOP_TIMER;
@@ -107,9 +102,10 @@ void bcal_performance(const bcdesc_t* bcd){
                        }
                }
                t>>=5;
-               cli_putstr_P(PSTR("\r\n    init (cycles):      "));
-               printvalue(t);
+               printf_P(PSTR("    init (cycles):      %5"PRIu16"\n"), t);
        }
+
+    uart0_flush();
        t=0;
        for(i=0; i<32; ++i){
                startTimer(0);
@@ -119,9 +115,9 @@ void bcal_performance(const bcdesc_t* bcd){
                t += stopTimer();
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    encrypt (cycles):   "));
-       printvalue(t);
+       printf_P(PSTR("    encrypt (cycles):   %5"PRIu16"\n"), t);
 
+    uart0_flush();
        t=0;
        for(i=0; i<32; ++i){
                startTimer(0);
@@ -131,10 +127,11 @@ void bcal_performance(const bcdesc_t* bcd){
                t += stopTimer();
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    decrypt (cycles):   "));
-       printvalue(t);
+       printf_P(PSTR("    decrypt (cycles):   %5"PRIu16"\n"), t);
+    uart0_flush();
 
        if(bc.free){
+           uart0_flush();
                bc.free(&ctx);
        }
 }
@@ -147,17 +144,17 @@ void bcal_stacksize(const bcdesc_t* bcd){
        uint8_t data[(bc.blocksize_b+7)/8];
        uint16_t keysize = get_keysize(bc.valid_keysize_desc);
        uint8_t key[(keysize+7)/8];
-       uint16_t t1, t2;
+       uint16_t t1 = 0, t2 = 0;
 
-       if(bc.type!=BCDESC_TYPE_BLOCKCIPHER)
+       if(bc.type != BCDESC_TYPE_BLOCKCIPHER)
                return;
-       cli_putstr_P(PSTR("\r\n\r\n === "));
-       cli_putstr_P(bc.name);
-       cli_putstr_P(PSTR(" stack-usage === "));
+       printf_P(PSTR("\n === %S stack-usage ===\n"),bc.name);
+
+       uart0_flush();
 
        if(bc.init.init1){
-               if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
-                       cli();
+               if((bc.flags & BC_INIT_TYPE) == BC_INIT_TYPE_1){
+               cli();
                        stack_measure_init(&smctx, PATTERN_A);
                        bc.init.init1(&ctx, key);
                        t1 = stack_measure_final(&smctx);
@@ -166,18 +163,18 @@ void bcal_stacksize(const bcdesc_t* bcd){
                        t2 = stack_measure_final(&smctx);
                        sei();
                } else {
-                       cli();
+               cli();
                        stack_measure_init(&smctx, PATTERN_A);
                        bc.init.init2(&ctx, keysize, key);
                        t1 = stack_measure_final(&smctx);
                        stack_measure_init(&smctx, PATTERN_B);
                        bc.init.init2(&ctx, keysize, key);
-                       t2 = stack_measure_final(&smctx);
-                       sei();
-               }
+            t2 = stack_measure_final(&smctx);
+            sei();
+        }
+
                t1 = (t1>t2)?t1:t2;
-               cli_putstr_P(PSTR("\r\n    init (bytes):       "));
-               printvalue((unsigned long)t1);
+               printf_P(PSTR("    init (bytes):       %5"PRIu16"\n"), t1);
        }
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -189,8 +186,7 @@ void bcal_stacksize(const bcdesc_t* bcd){
        sei();
 
        t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    encBlock (bytes):   "));
-       printvalue((unsigned long)t1);
+       printf_P(PSTR("    encBlock (bytes):   %5"PRIu16"\n"), t1);
 
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -202,8 +198,7 @@ void bcal_stacksize(const bcdesc_t* bcd){
        sei();
 
        t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    decBlock (bytes):   "));
-       printvalue((unsigned long)t1);
+       printf_P(PSTR("    decBlock (bytes):   %5"PRIu16"\n"), t1);
 
        if(bc.free){
                bc.free(&ctx);
@@ -215,7 +210,7 @@ void bcal_performance_multiple(const bcdesc_t* const* bcd_list){
        for(;;){
                bcd = (void*)pgm_read_word(bcd_list);
                if(!bcd){
-                       cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
+                       puts_P(PSTR("\n End of performance figures\n"));
                        return;
                }
                bcal_performance(bcd);
index 6ac39cb197a9552e085439c7c41c219c948ff7b4..a21163e8fd0d078aac7af190f495e8e50d3ec4b0 100644 (file)
@@ -315,7 +315,7 @@ int8_t bigint_cmp_u(const bigint_t* a, const bigint_t* b){
        if(a->length_W < b->length_W){
                return -1;
        }
-       if(a->length_W==0){
+       if(a->length_W == 0){
                return 0;
        }
        uint16_t i;
index b8c72fbd7bbc0165e24c50e575f67b32e5722af5..01f01022846af74d83aaf8eb14213058bc0561d0 100644 (file)
@@ -1,3 +1,8 @@
 CLI_STD =  cli-stub.o cli-basics.o cli-core.o cli-hexdump.o debug.o hexdigit_tab.o \
            dbz_strings.o string-extras-asm.o uart_i-asm.o circularbytebuffer-asm.o \
            main-test-common.o
+
+#CLI_STD = cli.o debug.o hexdigit_tab.o \
+#          dbz_strings.o string-extras-asm.o uart_i-asm.o circularbytebuffer-asm.o \
+#          main-test-common.o
+
index a70f32d949c09c417247fb49ad3271741bd286ae..8698c4ecdbf84c76766f874c283cc0300f705808 100644 (file)
 stack_measure_init:
        movw r30, r24
        lds r20, __brkval
-       lds r21, __brkval+1
+       lds r21, __brkval + 1
        in r0, _SFR_IO_ADDR(SREG)
        cli
        in r26, _SFR_IO_ADDR(SPL)
        out _SFR_IO_ADDR(SREG), r0
        in r27, _SFR_IO_ADDR(SPH)
+       cp r20, r26
+       cpc r21, r27
+       brlo 10f
+       ldi r20, lo8(__bss_end)
+       ldi r21, hi8(__bss_end)
+       cp r20, r26
+       cpc r21, r27
+       brlo 10f
+       ldi r21, 1
+       clr r20
+10:
        st Z+, r20
        st Z+, r21
        st Z+, r26
@@ -41,23 +52,31 @@ stack_measure_init:
        sbc r25, r21
        sbiw r24, 1
        st X, r22
-1:  st -X, r22
+50: st -X, r22
        sbiw r24, 1
-       brne 1b
+       brne 50b
        ret
 
 .global stack_measure_final
 stack_measure_final:
        movw r30, r24
        lds r20, __brkval
-       lds r21, __brkval+1
+       lds r21, __brkval + 1
        ld r26, Z+
        ld r27, Z+
+
        cp r20, r26
        cpc r21, r27
-       brlo 1f
-       movw r26, r20
-1:
+       brlo 10f
+       ldi r20, lo8(__bss_end)
+       ldi r21, hi8(__bss_end)
+       cp r20, r26
+       cpc r21, r27
+       brlo 10f
+       ldi r21, 1
+       clr r20
+10:
+
        adiw r26, 1
        ld r24, Z+
        ld r25, Z+
index 573997e66f78d7e7f179ad6460594c47654ddd24..2c572e53e5b31ff0c1be3b692dabb7f9604b78d4 100644 (file)
@@ -392,6 +392,7 @@ cli_auto_help:
 99:
        pop_range 28, 29
        pop_range 14, 17
+       ori r24, 1
        ret
 ahelphead_str:
 .asciz "\r\n[auto help] available commands:\r\n <command> - <params> - <address>\r\n"
index 1db56168a59baf2c5f097c17ac5bd42b7193906b..cb3d27103c0df6fc075db3c96e482bcd73a87705 100644 (file)
@@ -98,7 +98,7 @@ int8_t cmd_interface(PGM_VOID_P cmd_desc){
                c = cli_rx();
                switch (c){
                case CLI_ENTER:
-                       if((exit_code=search_and_call(cli_buffer, maxcmdlength, cmd_desc))<=0){
+                       if((exit_code = search_and_call(cli_buffer, maxcmdlength, cmd_desc)) <=0 ){
                                free(cli_buffer);
                                return exit_code;
                        }
index f95f26e84a0f1e4ee82ae1d2c17039d40a372314..70c421072ab1018c8e52fc225adf12f59c218747 100644 (file)
@@ -57,15 +57,15 @@ extern uint8_t cli_echo;
 void cli_putc(char c);
 uint16_t cli_getc(void);
 uint16_t cli_getc_cecho(void);
-uint8_t cli_getsn(char* s, uint16_t n);
+uint8_t cli_getsn(char* s, size_t n);
 uint8_t cli_getsn_cecho(char* s, uint16_t n);
 void cli_putstr(const char* s);
 void cli_putstr_P(PGM_P s);
 void cli_hexdump_byte(uint8_t byte);
-void cli_hexdump(const void* data, uint16_t length);
-void cli_hexdump_rev(const void* data, uint16_t length);
-void cli_hexdump2(const void* data, uint16_t length);
-void cli_hexdump_block(const void* data, uint16_t length, uint8_t indent, uint8_t width);
+void cli_hexdump(const void* data, size_t length);
+void cli_hexdump_rev(const void* data, size_t length);
+void cli_hexdump2(const void* data, size_t length);
+void cli_hexdump_block(const void* data, size_t length, uint8_t indent, uint8_t width);
 
 void echo_ctrl(char* s);
 int8_t cmd_interface(PGM_VOID_P cmd_desc);
index 51dc8a3f161fa47155ec289ab5e8ad30bd526acf..f5aed4a03563bfa41fa0282c3f57eb137d298158 100644 (file)
@@ -52,5 +52,5 @@ void welcome_msg(const char* algoname){
        cli_putstr(__TIME__);
        cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
 */
-    printf_P(PSTR("\n\nAVR-Crypto-Lib VS(%s; %s %s)\nloaded and running\n"), algoname, __DATE__, __TIME__);
+    printf_P(PSTR("\n\nAVR-Crypto-Lib VS (%s; %s %s)\nloaded and running\n"), algoname, __DATE__, __TIME__);
 }
index be0aee64b554cf009b7d8d67ee3a38337569cd49..862cdfeb58fa5e2074c206968dff511f97267164 100644 (file)
@@ -192,6 +192,11 @@ uart0_init:
        std Z+UART0_TXON_OFFSET, r24
        std Z+UART0_RXON_OFFSET, r24
 #endif 
+#if UART0_HOOK
+       std Z+UART0_HOOK_OFFSET,   r1
+       std Z+UART0_HOOK_OFFSET+1, r1
+       std Z+UART0_HOOKR_OFFSET,  r1
+#endif
        ldi r24, UBRRH_VALUE
        STORE_IO UBRR0H, r24
        ldi r24, UBRRL_VALUE
@@ -496,5 +501,16 @@ uart0_sethook:
        st X+, r25
        ret
 #endif
+
+.global uart0_flush
+uart0_flush:
+10:
+       ldi r24, lo8(uart0_ctx+UART0_CBB_TX_OFFSET)
+       ldi r25, hi8(uart0_ctx+UART0_CBB_TX_OFFSET)
+       rcall circularbytebuffer_cnt
+       tst r24
+       brne 10b
+       ret
+
        
 #endif /* UART0_I */
index b9a65c0ba5694b71bc15e052a041373d5885574e..097cfcc988403f007ee1805701815ab9273f1d5c 100644 (file)
@@ -115,7 +115,7 @@ typedef struct{
 #endif
 #if UART1_SWFLOWCTRL
        volatile uint8_t txon;  /**< flag indicating if we are allowed to send data */
-       volatile uint8_t rxon;  /**< flag indicating if we have send an \a XOFF */
+       volatile uint8_t rxon;  /**< flag indicating if we have send a XOFF */
 #endif
 } uart1_ctx_t;
 
@@ -156,6 +156,15 @@ uint16_t uart0_getc(void);
  */
 uint8_t uart0_dataavail(void);
 
+/**
+ * \brief flushes the internal transmit buffer.
+ *
+ * This function function waits until all data was send (the transmit-buffer
+ * does not contain any data).
+ */
+void uart0_flush(void);
+
+
 #if    UART0_HOOK
 /**
  * \brief sets the hook for uart0.