Root/
| Source at commit 9081d91ca8d1e8d008bfde93944eb528d0da2898 created 10 years 11 months ago. By Werner Almesberger, tornado/cpu/: rearrange things and fix ERC problems | |
|---|---|
| 1 | /* |
| 2 | * fw/param.c - Parameter upload |
| 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 <stdbool.h> |
| 15 | #include <stdint.h> |
| 16 | #include <string.h> |
| 17 | |
| 18 | #include <avr/pgmspace.h> |
| 19 | |
| 20 | #include "hash.h" |
| 21 | #include "sweep.h" |
| 22 | #include "secret.h" |
| 23 | #include "proto.h" |
| 24 | #include "dispatch.h" |
| 25 | |
| 26 | |
| 27 | struct sweep fwd_sweep = { |
| 28 | .pixel_ticks = TP_FWD_PIX_DEFAULT, |
| 29 | .left = PX_FWD_LEFT_DEFAULT, |
| 30 | .right = PX_FWD_RIGHT_DEFAULT, |
| 31 | .forward = 1, |
| 32 | }; |
| 33 | |
| 34 | |
| 35 | struct sweep bwd_sweep = { |
| 36 | .pixel_ticks = TP_BWD_PIX_DEFAULT, |
| 37 | .left = PX_BWD_LEFT_DEFAULT, |
| 38 | .right = PX_BWD_RIGHT_DEFAULT, |
| 39 | .forward = 0, |
| 40 | }; |
| 41 | |
| 42 | uint16_t xa_high = XA_HIGH_DEFAULT; |
| 43 | uint16_t xa_low = XA_LOW_DEFAULT; |
| 44 | uint32_t fwd_start = TP_FWD_START_DEFAULT; |
| 45 | uint32_t bwd_start = TP_BWD_START_DEFAULT; |
| 46 | |
| 47 | static struct params tmp; |
| 48 | static bool failed; |
| 49 | |
| 50 | |
| 51 | static void new_params(void) |
| 52 | { |
| 53 | xa_high = tmp.xa_high; |
| 54 | xa_low = tmp.xa_low; |
| 55 | |
| 56 | fwd_sweep.left = tmp.px_fwd_left; |
| 57 | fwd_sweep.right = tmp.px_fwd_right; |
| 58 | bwd_sweep.left = tmp.px_bwd_left; |
| 59 | bwd_sweep.right = tmp.px_bwd_right; |
| 60 | |
| 61 | fwd_start = tmp.tp_fwd_start; |
| 62 | bwd_start = tmp.tp_bwd_start; |
| 63 | fwd_sweep.pixel_ticks = tmp.tp_fwd_pix; |
| 64 | bwd_sweep.pixel_ticks = tmp.tp_bwd_pix; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | static bool param_more(uint8_t seq, uint8_t limit, const uint8_t *payload) |
| 69 | { |
| 70 | switch (limit-seq) { |
| 71 | default: |
| 72 | hash_merge(payload, PAYLOAD); |
| 73 | break; |
| 74 | case 1: |
| 75 | hash_end(); |
| 76 | failed = !hash_eq(payload, PAYLOAD, 0); |
| 77 | break; |
| 78 | case 0: |
| 79 | if (!hash_eq(payload, PAYLOAD, PAYLOAD)) |
| 80 | failed = 1; |
| 81 | if (failed) |
| 82 | return 0; |
| 83 | new_params(); |
| 84 | break; |
| 85 | } |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | static bool param_first(uint8_t limit, const uint8_t *payload) |
| 91 | { |
| 92 | hash_init(); |
| 93 | hash_merge_progmem(image_secret, sizeof(image_secret)); |
| 94 | hash_merge(payload, PAYLOAD); |
| 95 | memcpy(&tmp, payload, sizeof(tmp)); |
| 96 | failed = 0; |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | struct handler param_handler = { |
| 102 | .type = PARAM, |
| 103 | .first = param_first, |
| 104 | .more = param_more, |
| 105 | }; |
| 106 | |
Branches:
master
tornado-v1
