Date:2012-06-20 15:30:40 (8 years 1 month ago)
Author:Werner Almesberger
Commit:87cc67d5f7bdc1e5c67de41fb05a9efc643734aa
Message:fw/: add image data upload (completely untested)

Files: PROTOCOL (1 diff)
fw/Makefile (1 diff)
fw/antorcha.c (1 diff)
fw/dispatch.h (1 diff)
fw/image.c (1 diff)
fw/image.h (1 diff)
fw/io.h (1 diff)
fw/sweep.c (1 diff)

Change Details

PROTOCOL
3838Even numbered packet types correspond to packets sent from the remote
3939controller to the device. Odd numbered packet types correspond to
4040responses. The device never initiates communication.
41
42
43Image format
44============
45
46Two bytes per line. LSB of first byte is LED A1, MSB of last byte is B8.
47Unused lines must be set to zero.
fw/Makefile
134134
135135fw.o: unlock-secret.inc
136136reset.o: unlock-secret.inc
137image.o: image-secret.inc
137138
138139# ----- Dependencies ----------------------------------------------------------
139140
fw/antorcha.c
2020
2121
2222static const struct handler *protos[] = {
23    &image_handler,
2324    &reset_handler,
2425    NULL
2526};
fw/dispatch.h
2626};
2727
2828
29extern struct handler image_handler;
2930extern struct handler reset_handler;
3031
32
3133bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos);
3234
3335#endif /* !PROTO_H */
fw/image.c
1111 */
1212
1313
14#include <stdbool.h>
15#include <stdint.h>
16#include <string.h>
17
18#include "io.h"
19#include "hash.h"
20#include "proto.h"
21#include "dispatch.h"
1422#include "image.h"
1523
1624
17extern struct line image[MAX_LINES];
25static struct line images[2][MAX_LINES];
26static const struct line *next_image;
27static struct line *p, *end;
28static bool failed;
29
30const struct line *image = images[0];
31
32
33static const uint8_t image_secret[2*PAYLOAD] = {
34    #include "image-secret.inc"
35};
36
37
38#define MAP(port, value, group) ( \
39    ((value) & 1 ? MASK(port, LED_##group##1) : 0) | \
40    ((value) & 2 ? MASK(port, LED_##group##2) : 0) | \
41    ((value) & 4 ? MASK(port, LED_##group##3) : 0) | \
42    ((value) & 8 ? MASK(port, LED_##group##4) : 0) | \
43    ((value) & 16 ? MASK(port, LED_##group##5) : 0) | \
44    ((value) & 32 ? MASK(port, LED_##group##6) : 0) | \
45    ((value) & 64 ? MASK(port, LED_##group##7) : 0) | \
46    ((value) & 128 ? MASK(port, LED_##group##8) : 0))
47
48
49static void add_payload(const uint8_t *payload)
50{
51    uint8_t i, b, c, d;
52
53    for (i = 0; i != PAYLOAD && p != end; i += 2) {
54        b = MAP(B, payload[i], A) | MAP(B, payload[i+1], B);
55        c = MAP(C, payload[i], A) | MAP(C, payload[i+1], B);
56        d = MAP(D, payload[i], A) | MAP(D, payload[i+1], B);
57        p->d = d;
58        p->cb = c | b;
59        p++;
60    }
61}
62
63
64static bool image_first(const uint8_t *payload)
65{
66    hash_init();
67    next_image = p = image == images[0] ? images[1] : images[0];
68    end = p+MAX_LINES;
69    memset(p, 0, (char *) end-(char *) p);
70    add_payload(payload);
71    hash_merge(payload, PAYLOAD);
72    failed = 0;
73    return 1;
74}
75
76
77static bool image_more(uint8_t seq, uint8_t limit, const uint8_t *payload)
78{
79    switch (limit-seq) {
80    default:
81        add_payload(payload);
82        /* fall through */
83    case 3:
84    case 2:
85        hash_merge(payload, PAYLOAD);
86        break;
87    case 1:
88        failed = !hash_eq(payload, PAYLOAD, 0);
89        break;
90    case 0:
91        if (!hash_eq(payload, PAYLOAD, PAYLOAD))
92            failed = 1;
93        if (failed)
94            return 0;
95        image = next_image;
96        break;
97    }
98    return 1;
99}
100
101
102struct handler image_handler = {
103        .type = IMAGE,
104        .first = image_first,
105        .more = image_more,
106};
fw/image.h
2727};
2828
2929
30extern struct line image[MAX_LINES];
30extern const struct line *image;
3131
3232#endif /* !IMAGE_H */
fw/io.h
5757#define __SEL_CC(v) (v)
5858#define __SEL_DD(v) (v)
5959
60#if 0
6160#define __SEL_BC(v) (0)
6261#define __SEL_BD(v) (0)
6362#define __SEL_CB(v) (0)
6463#define __SEL_CD(v) (0)
6564#define __SEL_DB(v) (0)
6665#define __SEL_DC(v) (0)
67#endif
6866
6967#define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit))
7068#define MASK(...) __MASK(__VA_ARGS__)
fw/sweep.c
2121#include "sweep.h"
2222
2323
24struct line image[MAX_LINES];
25
2624static uint32_t t_sw; /* cumulative number of timer ticks in sweep */
2725
2826static uint16_t wait_periods; /* number of periods to wait before image */

Archive Download the corresponding diff file

Branches:
master
tornado-v1



interactive