1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-22 08:34:04 +02:00

fw/: add image data upload (completely untested)

This commit is contained in:
Werner Almesberger 2012-06-20 10:30:40 -03:00
parent 6223a58552
commit 87cc67d5f7
8 changed files with 102 additions and 6 deletions

View File

@ -38,3 +38,10 @@ may have a variable-size payload.
Even numbered packet types correspond to packets sent from the remote
controller to the device. Odd numbered packet types correspond to
responses. The device never initiates communication.
Image format
============
Two bytes per line. LSB of first byte is LED A1, MSB of last byte is B8.
Unused lines must be set to zero.

View File

@ -134,6 +134,7 @@ image-secret.inc:
fw.o: unlock-secret.inc
reset.o: unlock-secret.inc
image.o: image-secret.inc
# ----- Dependencies ----------------------------------------------------------

View File

@ -20,6 +20,7 @@
static const struct handler *protos[] = {
&image_handler,
&reset_handler,
NULL
};

View File

@ -26,8 +26,10 @@ struct handler {
};
extern struct handler image_handler;
extern struct handler reset_handler;
bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos);
#endif /* !PROTO_H */

View File

@ -11,7 +11,96 @@
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "io.h"
#include "hash.h"
#include "proto.h"
#include "dispatch.h"
#include "image.h"
extern struct line image[MAX_LINES];
static struct line images[2][MAX_LINES];
static const struct line *next_image;
static struct line *p, *end;
static bool failed;
const struct line *image = images[0];
static const uint8_t image_secret[2*PAYLOAD] = {
#include "image-secret.inc"
};
#define MAP(port, value, group) ( \
((value) & 1 ? MASK(port, LED_##group##1) : 0) | \
((value) & 2 ? MASK(port, LED_##group##2) : 0) | \
((value) & 4 ? MASK(port, LED_##group##3) : 0) | \
((value) & 8 ? MASK(port, LED_##group##4) : 0) | \
((value) & 16 ? MASK(port, LED_##group##5) : 0) | \
((value) & 32 ? MASK(port, LED_##group##6) : 0) | \
((value) & 64 ? MASK(port, LED_##group##7) : 0) | \
((value) & 128 ? MASK(port, LED_##group##8) : 0))
static void add_payload(const uint8_t *payload)
{
uint8_t i, b, c, d;
for (i = 0; i != PAYLOAD && p != end; i += 2) {
b = MAP(B, payload[i], A) | MAP(B, payload[i+1], B);
c = MAP(C, payload[i], A) | MAP(C, payload[i+1], B);
d = MAP(D, payload[i], A) | MAP(D, payload[i+1], B);
p->d = d;
p->cb = c | b;
p++;
}
}
static bool image_first(const uint8_t *payload)
{
hash_init();
next_image = p = image == images[0] ? images[1] : images[0];
end = p+MAX_LINES;
memset(p, 0, (char *) end-(char *) p);
add_payload(payload);
hash_merge(payload, PAYLOAD);
failed = 0;
return 1;
}
static bool image_more(uint8_t seq, uint8_t limit, const uint8_t *payload)
{
switch (limit-seq) {
default:
add_payload(payload);
/* fall through */
case 3:
case 2:
hash_merge(payload, PAYLOAD);
break;
case 1:
failed = !hash_eq(payload, PAYLOAD, 0);
break;
case 0:
if (!hash_eq(payload, PAYLOAD, PAYLOAD))
failed = 1;
if (failed)
return 0;
image = next_image;
break;
}
return 1;
}
struct handler image_handler = {
.type = IMAGE,
.first = image_first,
.more = image_more,
};

View File

@ -27,6 +27,6 @@ struct line {
};
extern struct line image[MAX_LINES];
extern const struct line *image;
#endif /* !IMAGE_H */

View File

@ -57,14 +57,12 @@
#define __SEL_CC(v) (v)
#define __SEL_DD(v) (v)
#if 0
#define __SEL_BC(v) (0)
#define __SEL_BD(v) (0)
#define __SEL_CB(v) (0)
#define __SEL_CD(v) (0)
#define __SEL_DB(v) (0)
#define __SEL_DC(v) (0)
#endif
#define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit))
#define MASK(...) __MASK(__VA_ARGS__)

View File

@ -21,8 +21,6 @@
#include "sweep.h"
struct line image[MAX_LINES];
static uint32_t t_sw; /* cumulative number of timer ticks in sweep */
static uint16_t wait_periods; /* number of periods to wait before image */