comparison flash.c @ 31:03592ca4d37e

Port tempctrl.c from AVR. I removed the beep code as I don't have a beeper on the STM32 board. Reworked the heat/cool stuff so it can use separate ports.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 27 Nov 2012 13:20:52 +1030
parents 5c9d2e3d6591
children dcac5f08f87a
comparison
equal deleted inserted replaced
30:435c6330896c 31:03592ca4d37e
23 }; 23 };
24 24
25 #define RW_IDLE 0 25 #define RW_IDLE 0
26 #define RW_RUNNING 1 26 #define RW_RUNNING 1
27 27
28 /* Holds all the settings needed */
29 typedef struct {
30 uint8_t fermenter_ROM[8];
31 uint8_t fridge_ROM[8];
32 uint8_t ambient_ROM[8];
33 int16_t target_temp;
34 uint16_t hysteresis;
35 /* How much to under/overshoot on heating/cooling */
36 int16_t minheatovershoot;
37 int16_t mincoolovershoot;
38
39 /* Minimum time the cooler can be on/off */
40 int16_t mincoolontime;
41 int16_t mincoolofftime;
42
43 /* Minimum time the heater can be on/off */
44 int16_t minheatontime;
45 int16_t minheatofftime;
46
47 #define TC_MODE_AUTO 'a' /* Automatic control */
48 #define TC_MODE_HEAT 'h' /* Force heating */
49 #define TC_MODE_COOL 'c' /* Force cooling */
50 #define TC_MODE_IDLE 'i' /* Force idle */
51 #define TC_MODE_NOTHING 'n' /* Do nothing (like idle but log nothing) */
52 char mode;
53
54 /* Bit patterns for various modes */
55 uint8_t coolbits;
56 uint8_t heatbits;
57 uint8_t idlebits;
58
59 /* Check/stale times */
60 int16_t check_interval;
61 int16_t stale_factor;
62
63 /* Beep if stale */
64 int8_t dobeep;
65
66 /* Pad to 4 bytes */
67 uint8_t pad[1];
68
69 } __attribute__((packed, aligned(4))) settings_t;
70
71 const settings_t default_settings = {
72 .fermenter_ROM = { 0x10, 0x4c, 0x7d, 0x53, 0x01, 0x08, 0x00, 0xff },
73 .fridge_ROM = { 0x10, 0x6f, 0x40, 0x53, 0x01, 0x08, 0x00, 0x16 },
74 .ambient_ROM = { 0x10, 0x76, 0x05, 0x53, 0x01, 0x08, 0x00, 0x8c },
75 .target_temp = 1000,
76 .hysteresis = 100,
77 .minheatovershoot = 50,
78 .mincoolovershoot = -50,
79 .mincoolontime = 300,
80 .mincoolofftime = 600,
81 .minheatontime = 60,
82 .minheatofftime = 60,
83 .mode = TC_MODE_AUTO,
84 .coolbits = 1 << 6,
85 .heatbits = 1<< 7,
86 .idlebits = 0x00,
87 .check_interval = 10,
88 .stale_factor = 3,
89 .dobeep = 0
90 };
91
92 /* RAM copy of setting */
93 static settings_t ram_settings;
94
95 static int writestate = RW_IDLE; 28 static int writestate = RW_IDLE;
96 static int readstate = RW_IDLE; 29 static int readstate = RW_IDLE;
97 30
98 void 31 void
99 flashcmd(char **argv, int argc) { 32 flashcmd(int argc, char **argv) {
100 uint8_t status, tmp, len; 33 uint8_t status, tmp, len;
101 uint32_t addr; 34 uint32_t addr;
102 35
103 if (argc == 0) { 36 if (argc == 0) {
104 fputs("No command specified\r\n", stdout); 37 fputs("No command specified\r\n", stdout);
173 flashstartwrite(addr, data); 106 flashstartwrite(addr, data);
174 else 107 else
175 flashwriteword(data); 108 flashwriteword(data);
176 } 109 }
177 flashstopwrite(); 110 flashstopwrite();
178 } else if (!strcmp(argv[0], "tw")) {
179 /* Copy default to RAM */
180 bcopy(&default_settings, &ram_settings, sizeof(default_settings));
181
182 /* Write RAM copy into flash */
183 flashwriteblock(0, sizeof(ram_settings), &ram_settings);
184 } else if (!strcmp(argv[0], "tr")) {
185 int crcok;
186
187 /* Read flash copy to RAM */
188 crcok = flashreadblock(0, sizeof(ram_settings), &ram_settings);
189
190 printf("CRC is %s\r\n", crcok ? "OK" : "bad");
191 } else if (!strcmp(argv[0], "id")) { 111 } else if (!strcmp(argv[0], "id")) {
192 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", flashreadid()); 112 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", flashreadid());
193 } else { 113 } else {
194 fputs("Unknown sub command\r\n", stdout); 114 fputs("Unknown sub command\r\n", stdout);
195 return; 115 return;