some minor improvments and bug fixes
This commit is contained in:
parent
fdbda6486d
commit
7edc452f93
|
@ -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
|
||||
|
|
|
@ -32,15 +32,17 @@
|
|||
#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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -25,12 +25,23 @@
|
|||
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+
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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__);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue