1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-22 01:51:55 +02:00

fw/: add parameter upload (untested), move parameters from antorcha.c to param.c

This commit is contained in:
Werner Almesberger 2012-06-27 02:36:08 -03:00
parent 276ffd7f44
commit 0a0792688b
5 changed files with 140 additions and 22 deletions

View File

@ -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

View File

@ -15,6 +15,7 @@
#include <stdint.h>
#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,
&param_handler,
NULL
};

View File

@ -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);

105
fw/param.c Normal file
View File

@ -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 <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <avr/pgmspace.h>
#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,
};

30
fw/param.h Normal file
View File

@ -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 <stdint.h>
#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 */