Date:2012-12-09 21:28:19 (7 years 4 hours ago)
Author:Werner Almesberger
Commit:45f14d214ab31fe28644ef8f61552a3e25330ccf
Message:tornado/fw/tornado.c: experimental code to log ADC samples to memory card

For a yet unknown reason, writing to the card fails if also processing
the samples. Maybe it's some side-effect of switching the LEDs.
Files: tornado/fw/tornado.c (5 diffs)

Change Details

tornado/fw/tornado.c
88
99#include "io.h"
1010#include "led.h"
11#include "mmc.h"
1112#include "accel.h"
1213
1314
...... 
106107};
107108
108109
110static uint8_t one[LED_BYTES] =
111    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
112
113static volatile uint16_t sample_t = 0, sample_v;
114
115
109116static void zxing(uint16_t x, uint16_t y)
110117{
111    static uint8_t one[LED_BYTES] =
112        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
113118    static uint16_t e = 512 << E_SHIFT;
114119    static uint32_t m = 512 << M_SHIFT;
115120    int16_t d;
...... 
118123    static const prog_uint8_t *p;
119124    static uint16_t cols = 0;
120125
126    sample_t++;
127    sample_v = x;
128return;
129
121130    e = y+(e-(e >> E_SHIFT));
122131    m = y+(m-(m >> M_SHIFT));
123132    d = (e >> E_SHIFT)-(m >> M_SHIFT);
...... 
142151}
143152
144153
154static void panic(void)
155{
156    cli();
157    while (1) {
158        led_show(one);
159        _delay_ms(100);
160        led_off();
161        _delay_ms(100);
162    }
163}
164
165
145166int main(void)
146167{
147168    PORTB = HIGH(B);
...... 
164185#endif
165186
166187    led_init();
188
189#if 0
190    led_show(one);
191
192    if (!mmc_init())
193        panic();
194    if (!mmc_begin_write(0))
195        panic();
196
197    uint16_t n = 0;
198
199    for (n = 0; n != 512; n += 2) {
200        mmc_write(n);
201        mmc_write(n >> 8);
202    }
203
204    if (!mmc_end_write())
205        panic();
206
207    if (!mmc_begin_write(n))
208        panic();
209
210    for (; n != 1024; n += 2) {
211        mmc_write(n);
212        mmc_write(n >> 8);
213    }
214
215    if (!mmc_end_write())
216        panic();
217
218    _delay_ms(1000);
219
220    led_off();
221
222    while (1);
223#endif
224
167225#if 1
226    uint16_t last_t = 0;
227    uint32_t n = 0;
228
168229    sample = zxing;
230    if (!mmc_init())
231        panic();
169232    accel_start();
170233    sei();
171    while (1);
234    while (1) {
235        uint16_t t, v;
236
237        if (!(n & 511)) {
238            if (n && !mmc_end_write())
239                panic();
240            if (!mmc_begin_write(n))
241                panic();
242        }
243
244#if 0
245    t = n;
246    v = 0;
172247#else
248        do {
249            cli();
250            t = sample_t;
251            v = sample_v;
252            sei();
253        }
254        while (t == last_t);
255#endif
256
257        last_t = t;
258        mmc_write(t);
259        mmc_write(t >> 8);
260        mmc_write(v);
261        mmc_write(v >> 8);
262        n += 4;
263    }
264#endif
265
266#if 0
173267    static uint8_t p[LED_BYTES];
174268    uint8_t mode = 0;
175269    uint16_t n = 0, v;

Archive Download the corresponding diff file

Branches:
master
tornado-v1



interactive