| Date: | 2012-12-09 21:28:19 (11 years 16 days 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 | ||
|---|---|---|
| 8 | 8 | |
| 9 | 9 | #include "io.h" |
| 10 | 10 | #include "led.h" |
| 11 | #include "mmc.h" | |
| 11 | 12 | #include "accel.h" |
| 12 | 13 | |
| 13 | 14 | |
| ... | ... | |
| 106 | 107 | }; |
| 107 | 108 | |
| 108 | 109 | |
| 110 | static uint8_t one[LED_BYTES] = | |
| 111 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
| 112 | ||
| 113 | static volatile uint16_t sample_t = 0, sample_v; | |
| 114 | ||
| 115 | ||
| 109 | 116 | static void zxing(uint16_t x, uint16_t y) |
| 110 | 117 | { |
| 111 | static uint8_t one[LED_BYTES] = | |
| 112 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
| 113 | 118 | static uint16_t e = 512 << E_SHIFT; |
| 114 | 119 | static uint32_t m = 512 << M_SHIFT; |
| 115 | 120 | int16_t d; |
| ... | ... | |
| 118 | 123 | static const prog_uint8_t *p; |
| 119 | 124 | static uint16_t cols = 0; |
| 120 | 125 | |
| 126 | sample_t++; | |
| 127 | sample_v = x; | |
| 128 | return; | |
| 129 | ||
| 121 | 130 | e = y+(e-(e >> E_SHIFT)); |
| 122 | 131 | m = y+(m-(m >> M_SHIFT)); |
| 123 | 132 | d = (e >> E_SHIFT)-(m >> M_SHIFT); |
| ... | ... | |
| 142 | 151 | } |
| 143 | 152 | |
| 144 | 153 | |
| 154 | static 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 | ||
| 145 | 166 | int main(void) |
| 146 | 167 | { |
| 147 | 168 | PORTB = HIGH(B); |
| ... | ... | |
| 164 | 185 | #endif |
| 165 | 186 | |
| 166 | 187 | 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 | ||
| 167 | 225 | #if 1 |
| 226 | uint16_t last_t = 0; | |
| 227 | uint32_t n = 0; | |
| 228 | ||
| 168 | 229 | sample = zxing; |
| 230 | if (!mmc_init()) | |
| 231 | panic(); | |
| 169 | 232 | accel_start(); |
| 170 | 233 | 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; | |
| 172 | 247 | #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 | |
| 173 | 267 | static uint8_t p[LED_BYTES]; |
| 174 | 268 | uint8_t mode = 0; |
| 175 | 269 | uint16_t n = 0, v; |
Branches:
master
tornado-v1
