Commit 3c9a3635 authored by yids's avatar yids

- added debugger entries in the makefile, "make simulavr" starts simulavr and connects gdb to it

- some more tests in lib-test
- keygen prints hex arrays of the keys again
- added function in things.c to write to uart
parent c4f40483
#include /usr/share/arduino/Arduino.mk
#include /home/yids/src/avr/simavr/Makefile.common
CFILES=blink.c
OBJS=../libs/avrnacl/avrnacl_small/obj/randombytes.o ../libs/avrnacl/avrnacl_small/obj/libnacl.a
CFLAGS=-Os -pedantic -std=gnu99 -DARDUINO -I../libs/avrnacl/randombytes -I../libs/avrnacl/avrnacl_small/include
CFLAGS=-Os -g3 -pedantic -std=gnu99 -DARDUINO -I../libs/avrnacl/randombytes -I../libs/avrnacl/avrnacl_small/include
OPTIMIZE = -O3
CC=avr-gcc
MCU=atmega328p
MCU=atmega328
F_CPU=F_CPU=16000000UL
AVRDUDE_PROGRAMMERID=stk200 /* Programmer ids are listed in /etc/avrdude.conf */
AVRDUDE_PORT=/dev/ttyUSB4
AVRDUDE_PORT=/dev/ttyUSB1
all: lib-test
......@@ -18,15 +19,26 @@ all: lib-test
lib-test: lib-test.c
$(CC) lib-test.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c $(OBJS) $(OPTIMZE) -g -I AVRLIB/ -mmcu=$(MCU) -D$(F_CPU) $(CFLAGS) -o lib-test.elf
avr-objcopy -j .text -j .data -O ihex lib-test.elf lib-test.hex
rm lib-test.elf
upload:
avrdude -carduino -p atmega328p -P /dev/ttyUSB1 -b57600 -U flash:w:lib-test.hex
avrdude -carduino -p atmega328p -P $(AVRDUDE_PORT) -b57600 -U flash:w:lib-test.hex
simulavr:
simulavr -G -d $(MCU) --file lib-test.elf &
sleep 1
avr-gdb -se lib-test.elf --eval-command="target remote localhost:1212" --eval-command="load"
killall simulavr
simulavr-ddd:
simulavr -G -d $(MCU) --file lib-test.elf &
sleep 1
ddd --debugger 'avr-gdb -se lib-test.elf --eval-command="target remote localhost:1212" --eval-command="load"'
killall simulavr
debugger: lib-test
ddd --debugger avr-gdb -x gdb.conf
ddd --debugger avr-gdb -x gdb.conf
clean:
rm -r *.elf *.hex
include /home/yids/src/avr/simavr/Makefile.common
/* build test for avr, to test if the libs build */
#define F_CPU 16000000UL
#define BAUD 9600
#define ARDUINO
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include "../libs/pagerlib/pagerlib.h"
#include "../libs/pagerlib/things.h"
#include <util/delay.h>
#include <util/setbaud.h>
#include </usr/local/include/simavr/avr/avr_mcu_section.h>
char tx_priv_key[crypto_box_SECRETKEYBYTES] = {0x23, 0x4D, 0x77, 0xFFFFFFF7, 0x09, 0x70, 0x46, 0xFFFFFF82, 0xFFFFFFC7, 0x0B, 0x70, 0x39, 0xFFFFFFDA, 0x24, 0x4A, 0xFFFFFF9C, 0x28, 0x7A, 0xFFFFFFD8, 0xFFFFFFCE, 0x7B, 0xFFFFFFEF, 0xFFFFFFFB, 0x75, 0x7E, 0x34, 0x16, 0xFFFFFF99, 0xFFFFFFF6, 0x60, 0x08, 0x0A };
......@@ -22,11 +24,39 @@ char clear_message[] = "dit is een test berichtje :) ";
struct pl_ctx * context;
int main(void)
{
context = pl_init();
// sender = (struct pl_keypair *) malloc(sizeof(struct pl_keypair));
// receiver = (struct pl_keypair *) malloc(sizeof(struct pl_keypair));
uart_init();
uart_print("haaalloo");
struct pl_keypair *tx_kp;
struct pl_ctx *tx_ctx;
char clear_message[] = "Blaat blaat, dit is een test berichtje :), en nog meer en meer en meer 123456744555 blablablablablablabal jajajajaj hee blaat ";
char *rx_pubkey;
/* init */
tx_kp = NULL;
tx_ctx = pl_init();
/* load keypair */
memcpy(tx_ctx->kp->secret_key, tx_priv_key, crypto_box_SECRETKEYBYTES);
memcpy(tx_ctx->kp->public_key, tx_comp_p, crypto_box_PUBLICKEYBYTES);
/*load public key of receiver*/
memcpy(tx_ctx->receiver_public_key, rx_comp_p, crypto_box_PUBLICKEYBYTES);
memcpy(tx_ctx->msg->msg, clear_message, MSG_SIZE);
// pl_send_message(tx_ctx);
// uart_print("set keys and proces msg\n");
//******** rx ***********/
return 0;
......
......@@ -44,5 +44,9 @@ int main()
pl_save_public_key(keypair->public_key, filename);
printf("public key saved in file: %s\n", filename);
printf("HEX structs:\n");
hex_dump(keypair);
return 0;
}
......@@ -7,7 +7,11 @@
#endif
#ifdef ARDUINO
#define F_CPU 16000000UL
#define BAUD 9600
#include <avr/io.h>
#include <util/setbaud.h>
#include <avr/pgmspace.h>
const char PROGMEM b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
......@@ -48,6 +52,28 @@ char* to_hex( char hex[], const char bin[], size_t length )
}
#ifdef ARDUINO
void uart_print(char* string)
{
for (int i = 0; i < strlen(string); i++){
while (( UCSR0A & (1<<UDRE0)) == 0){};
UDR0 = string[i];
}
}
void uart_init(void)
{
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= _BV(U2X0);
#else
UCSR0A &= ~(_BV(U2X0));
#endif
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); /* 8-bit data */
UCSR0B = _BV(RXEN0) | _BV(TXEN0); /* Enable RX and TX */
}
void dump_buffer(unsigned int n, const unsigned char* buf)
{
// not implemented
......@@ -97,9 +123,6 @@ void vli_print(char *str, uint8_t *vli, unsigned int size) {
}
printf("\n");
}
#endif
......
......@@ -78,4 +78,13 @@ int base64_enc_len(int inputLen);
int base64_dec_len(char *input, int inputLen);
/* uart_init:
* initializes the uart
*/
void uart_init(void);
/* uart_print:
* send a string to serial
*/
void uart_print(char* string);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment