Date:2012-06-21 17:12:10 (8 years 1 month ago)
Author:Werner Almesberger
Commit:f0e79b8dcc7b59b33affa2056173a5de2b86ed37
Message:fw/: add acceleration sensor sample protocol (untested)

Files: doc/PROTOCOL (2 diffs)
fw/Makefile (1 diff)
fw/antorcha.c (1 diff)
fw/dispatch.h (1 diff)
fw/proto.h (1 diff)
fw/sample.c (1 diff)

Change Details

doc/PROTOCOL
3131
3232   9 n 0 Parameter ACK
3333
34   10 0 0 Sample (64 bytes payload)
35
36   11 0 0 Sample ACK
37
38   13 n 0 Samples
39
3440Unlock, firmware, image, and parameter packets all have a fixed-size
354164 bytes payload. Pings and acknowledgements have no payload. Pongs
3642may have a variable-size payload.
...... 
4551
4652Two bytes per line. LSB of first byte is LED A1, MSB of last byte is B8.
4753Unused lines must be set to zero.
54
55
56Sample format
57=============
58
59Each sample packet has the following structure:
60
61  Offset Size
62       0 2 Absolute time of X sample, high 16 bits
63       2 8*N N samples
64
65Where each sample is
66
67  Offset Size
68       0 2 Absolute time of X sample, lower 16 bits
69       2 2 X sample (0-1023)
70       4 2 Absolute time of Y sample, lower 16 bits
71       6 2 Y sample (0-1023)
72
73Byte order TBD. (Defined by avr-gcc)
fw/Makefile
3030#OBJDUMP = $(AVR_PREFIX)objdump
3131SIZE = $(AVR_PREFIX)size
3232
33OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sweep.o \
33OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sample.o sweep.o \
3434       $(COMMON_OBJS)
3535BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS)
3636COMMON_OBJS = rf.o spi.o
fw/antorcha.c
3333static const struct handler *protos[] = {
3434    &image_handler,
3535    &reset_handler,
36    &sample_handler,
3637    NULL
3738};
3839
fw/dispatch.h
2828
2929extern struct handler image_handler;
3030extern struct handler reset_handler;
31extern struct handler sample_handler;
3132
3233
3334bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos);
fw/proto.h
2828    IMAGE_ACK = 7, /* image upload acknowledgement */
2929    PARAM = 8, /* parameter upload */
3030    PARAM_ACK = 9, /* parameter upload acknowledgement */
31    SAMPLE = 10, /* start/stop sampling */
32    SAMPLE_ACK = 11, /* start/stop sampling acknowledgement */
33    SAMPLES = 13, /* samples */
3134};
3235
3336
fw/sample.c
1/*
2 * fw/sample.c - Acceleration sensor sample protocol
3 *
4 * Written 2012 by Werner Almesberger
5 * Copyright 2012 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stddef.h>
15#include <stdbool.h>
16#include <stdint.h>
17
18#include <avr/interrupt.h>
19
20#include "rf.h"
21#include "sweep.h"
22#include "accel.h"
23#include "proto.h"
24#include "dispatch.h"
25
26
27#define MAX_PACKET 120 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */
28
29static uint8_t buf[MAX_PACKET+3] = { SAMPLES, 0, 0 };
30static uint16_t *p;
31
32
33static void handler(bool x, uint16_t v)
34{
35    bool first;
36    uint32_t t;
37
38    first = p == (uint16_t *) (buf+3);
39    if (first && !x)
40        return;
41    t = uptime();
42    if (first)
43        *p++ = t >> 16;
44    *p++ = t;
45    *p++ = v;
46    if (x)
47        return;
48    if ((uint8_t *) (p+4) <= buf+MAX_PACKET)
49        return;
50    rf_send(buf, (uint8_t *) p-buf);
51    p = (uint16_t *) (buf+3);
52}
53
54
55static bool sample_first(uint8_t limit, const uint8_t *payload)
56{
57    if (payload[0]) {
58        buf[1] = 0;
59        cli();
60        sample = handler;
61        p = (uint16_t *) (buf+3);
62        sei();
63    } else {
64        cli();
65        sample = NULL;
66        sei();
67    }
68    return 1;
69}
70
71
72static bool sample_more(uint8_t seq, uint8_t limit, const uint8_t *payload)
73{
74    return 0;
75}
76
77
78struct handler sample_handler = {
79        .type = SAMPLE,
80        .first = sample_first,
81        .more = sample_more,
82};

Archive Download the corresponding diff file

Branches:
master
tornado-v1



interactive