From 0a0792688bb9731659324e33f9c1a51cc41d7667 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 27 Jun 2012 02:36:08 -0300 Subject: [PATCH] fw/: add parameter upload (untested), move parameters from antorcha.c to param.c --- fw/Makefile | 3 +- fw/antorcha.c | 23 +---------- fw/dispatch.h | 1 + fw/param.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ fw/param.h | 30 +++++++++++++++ 5 files changed, 140 insertions(+), 22 deletions(-) create mode 100644 fw/param.c create mode 100644 fw/param.h diff --git a/fw/Makefile b/fw/Makefile index 9ef0e6f..39fa3cf 100644 --- a/fw/Makefile +++ b/fw/Makefile @@ -30,7 +30,8 @@ OBJCOPY = $(AVR_PREFIX)objcopy #OBJDUMP = $(AVR_PREFIX)objdump SIZE = $(AVR_PREFIX)size -OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sample.o sweep.o \ +OBJS = $(NAME).o accel.o dispatch.o hash.o image.o param.o \ + reset.o sample.o sweep.o \ $(COMMON_OBJS) BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS) COMMON_OBJS = rf.o spi.o diff --git a/fw/antorcha.c b/fw/antorcha.c index 9e6c554..02b98da 100644 --- a/fw/antorcha.c +++ b/fw/antorcha.c @@ -15,6 +15,7 @@ #include #include "proto.h" +#include "param.h" #include "rf.h" #include "dispatch.h" #include "sweep.h" @@ -25,22 +26,6 @@ #include "io.h" -static struct sweep fwd_sweep = { - .pixel_ticks = TP_FWD_PIX_DEFAULT, - .left = PX_FWD_LEFT_DEFAULT, - .right = PX_FWD_RIGHT_DEFAULT, - .forward = 1, -}; - - -static struct sweep bwd_sweep = { - .pixel_ticks = TP_BWD_PIX_DEFAULT, - .left = PX_BWD_LEFT_DEFAULT, - .right = PX_BWD_RIGHT_DEFAULT, - .forward = 0, -}; - - static volatile enum sync_state { IDLE, /* undecided */ BWD, /* backward sweep */ @@ -53,11 +38,6 @@ static volatile uint32_t tR0, tR1, tL0, tL1; static volatile uint32_t tL, tR; static volatile bool wake = 0; -static uint16_t xa_high = XA_HIGH_DEFAULT; -static uint16_t xa_low = XA_LOW_DEFAULT; -static uint32_t fwd_start = TP_FWD_START_DEFAULT; -static uint32_t bwd_start = TP_BWD_START_DEFAULT; - static void sync_sweep(bool x, uint16_t v) { @@ -132,6 +112,7 @@ static const struct handler *protos[] = { &image_handler, &reset_handler, &sample_handler, + ¶m_handler, NULL }; diff --git a/fw/dispatch.h b/fw/dispatch.h index 1085220..b8612f7 100644 --- a/fw/dispatch.h +++ b/fw/dispatch.h @@ -29,6 +29,7 @@ struct handler { extern struct handler image_handler; extern struct handler reset_handler; extern struct handler sample_handler; +extern struct handler param_handler; bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos); diff --git a/fw/param.c b/fw/param.c new file mode 100644 index 0000000..c02c24c --- /dev/null +++ b/fw/param.c @@ -0,0 +1,105 @@ +/* + * fw/param.c - Parameter upload + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include +#include +#include + +#include + +#include "hash.h" +#include "sweep.h" +#include "image.h" +#include "proto.h" +#include "dispatch.h" + + +struct sweep fwd_sweep = { + .pixel_ticks = TP_FWD_PIX_DEFAULT, + .left = PX_FWD_LEFT_DEFAULT, + .right = PX_FWD_RIGHT_DEFAULT, + .forward = 1, +}; + + +struct sweep bwd_sweep = { + .pixel_ticks = TP_BWD_PIX_DEFAULT, + .left = PX_BWD_LEFT_DEFAULT, + .right = PX_BWD_RIGHT_DEFAULT, + .forward = 0, +}; + +uint16_t xa_high = XA_HIGH_DEFAULT; +uint16_t xa_low = XA_LOW_DEFAULT; +uint32_t fwd_start = TP_FWD_START_DEFAULT; +uint32_t bwd_start = TP_BWD_START_DEFAULT; + +static struct params tmp; +static bool failed; + + +static void new_params(void) +{ + xa_high = tmp.xa_high; + xa_low = tmp.xa_low; + + fwd_sweep.left = tmp.px_fwd_left; + fwd_sweep.right = tmp.px_fwd_right; + bwd_sweep.left = tmp.px_bwd_left; + bwd_sweep.right = tmp.px_bwd_right; + + fwd_start = tmp.tp_fwd_start; + bwd_start = tmp.tp_bwd_start; + fwd_sweep.pixel_ticks = tmp.tp_fwd_pix; + bwd_sweep.pixel_ticks = tmp.tp_bwd_pix; +} + + +static bool param_more(uint8_t seq, uint8_t limit, const uint8_t *payload) +{ + switch (limit-seq) { + default: + hash_merge(payload, PAYLOAD); + break; + case 1: + hash_end(); + failed = !hash_eq(payload, PAYLOAD, 0); + break; + case 0: + if (!hash_eq(payload, PAYLOAD, PAYLOAD)) + failed = 1; + if (failed) + return 0; + new_params(); + break; + } + return 1; +} + + +static bool param_first(uint8_t limit, const uint8_t *payload) +{ + hash_init(); + hash_merge_progmem(image_secret, sizeof(image_secret)); + hash_merge(payload, PAYLOAD); + memcpy(&tmp, payload, sizeof(tmp)); + failed = 0; + return 1; +} + + +struct handler param_handler = { + .type = PARAM, + .first = param_first, + .more = param_more, +}; diff --git a/fw/param.h b/fw/param.h new file mode 100644 index 0000000..8f53130 --- /dev/null +++ b/fw/param.h @@ -0,0 +1,30 @@ +/* + * fw/param.h - Parameter upload + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef PARAM_H +#define PARAM_H + +#include + +#include "sweep.h" + + +extern struct sweep fwd_sweep; +extern struct sweep bwd_sweep; + +extern uint16_t xa_high; +extern uint16_t xa_low; +extern uint32_t fwd_start; +extern uint32_t bwd_start; + +#endif /* !PARAM_H */