Mercurial > public > ostc4
annotate Discovery/Src/externLogbookFlash.c @ 421:3f7d80f37bfc ImprovmentNVM_2
Enable sequentionel writing of device data:
DeviceData was always written to the start of the the DD ringbuffer causing everytime a sector erase delay (~200ms). To avoid this the ring buffer functionality has been activated.
To be backward compatible the latest DD set will be written to DD ring buffer start at shutdown time.
In case of a reset the firmware scans for the latest DD block and restores its content giving the same data consistency intervall (10 minutes) as the previous implementation without having the 200ms penality for sector erases
author | ideenmodellierer |
---|---|
date | Mon, 10 Feb 2020 19:25:09 +0100 |
parents | 2174fb133dbe |
children | a560afdaadbf |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @copyright heinrichs weikamp | |
4 * @file externLogbookFlash.c | |
5 * @author heinrichs weikamp gmbh | |
6 * @date 07-Aug-2014 | |
7 * @version V0.0.4 | |
8 * @since 29-Sept-2015 | |
9 * @brief Main File to access the new 1.8 Volt Spansion S25FS256S 256 Mbit (32 Mbyte) | |
10 * @bug | |
11 * @warning | |
12 * | |
13 @verbatim | |
14 ============================================================================== | |
15 ##### Logbook Header (TOC) ##### | |
16 ============================================================================== | |
17 [..] Memory useage: | |
18 NEW: Spansion S25FS-S256S | |
19 | |
20 only 8x 4KB and 1x 32KB, remaining is 64KB or 256KB | |
21 Sector Size (kbyte) Sector Count Sector Range Address Range (Byte Address) Notes | |
22 4 8 SA00 00000000h-00000FFFh | |
23 : : | |
24 SA07 00007000h-00007FFFh | |
25 | |
26 32 1 SA08 00008000h-0000FFFFh | |
27 | |
28 64 511 SA09 00010000h-0001FFFFh | |
29 : : | |
30 SA519 01FF0000h-01FFFFFFh | |
31 OLD: | |
32 1kB each header | |
33 with predive header at beginning | |
34 and postdive header with 0x400 HEADER2OFFSET | |
35 4kB (one erase) has two dives with 4 headers total | |
36 total of 512 kB (with 256 header ids (8 bit)) | |
37 Size is 280 Byte (as of 25.Nov. 2014) | |
38 | |
39 [..] Output to PC / UART is postdive header | |
40 | |
41 [..] Block Protection Lock-Down is to erase logbook only | |
42 | |
43 [..] Timing (see page 137 of LOGBOOK_V3_S25FS-S_00-271247.pdf | |
44 bulk erase is 2 minutes typ., 6 minutes max. | |
45 | |
46 ============================================================================== | |
47 ##### DEMOMODE ##### | |
48 ============================================================================== | |
49 151215: ext_flash_write_settings() is DISABLED! | |
50 | |
51 ============================================================================== | |
52 ##### bug fixes ##### | |
53 ============================================================================== | |
54 150917: end in header and length of sample was one byte too long | |
55 as stated by Jef Driesen email 15.09.2015 | |
56 | |
57 @endverbatim | |
58 ****************************************************************************** | |
59 * @attention | |
60 * | |
61 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
62 * | |
63 ****************************************************************************** | |
64 */ | |
65 | |
66 /* Includes ------------------------------------------------------------------*/ | |
67 #include "stm32f4xx_hal.h" | |
68 #include "externLogbookFlash.h" | |
69 #include "ostc.h" | |
70 #include "settings.h" | |
71 #include "gfx_engine.h" | |
72 | |
73 #ifndef BOOTLOADER_STANDALONE | |
74 #include "logbook.h" | |
75 #endif | |
76 | |
77 /* Private types -------------------------------------------------------------*/ | |
78 #define FLASHSTART 0x000000 | |
79 //#define FLASHSTOP 0x01FFFFFF all 32 MB with 4byte addressing | |
80 #define FLASHSTOP 0x00FFFFFF | |
81 //#define FLASHSTOP 0x3FFFFF | |
82 #define RELEASE 1 | |
83 #define HOLDCS 0 | |
84 | |
85 #define HEADER2OFFSET 0x400 | |
86 | |
87 typedef enum{ | |
88 EF_HEADER, | |
89 EF_SAMPLE, | |
90 EF_DEVICEDATA, | |
91 EF_VPMDATA, | |
92 EF_SETTINGS, | |
93 EF_FIRMWARE, | |
94 EF_FIRMWARE2, | |
95 }which_ring_enum; | |
96 | |
97 | |
98 typedef struct{ | |
99 uint8_t IsBusy:1; | |
100 uint8_t IsWriteEnabled:1; | |
101 uint8_t BlockProtect0:1; | |
102 uint8_t BlockProtect1:1; | |
103 uint8_t BlockProtect2:1; | |
104 uint8_t BlockProtect3:1; | |
105 uint8_t IsAutoAddressIncMode:1; | |
106 uint8_t BlockProtectL:1; | |
107 } extFlashStatusUbit8_t; | |
108 | |
109 typedef union{ | |
110 extFlashStatusUbit8_t ub; | |
111 uint8_t uw; | |
112 } extFlashStatusBit8_Type; | |
113 | |
114 | |
115 /* Exported variables --------------------------------------------------------*/ | |
116 | |
117 /* Private variables ---------------------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
118 static uint32_t actualAddress = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
119 static uint32_t entryPoint = 0; |
38 | 120 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
121 static uint32_t actualPointerHeader = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
122 static uint32_t actualPointerSample = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
123 static uint32_t LengthLeftSampleRead = 0; |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
124 static uint32_t actualPointerDevicedata = DDSTART; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
125 static uint32_t actualPointerDevicedata_Read = DDSTART; |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
126 static uint32_t actualPointerVPM = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
127 static uint32_t actualPointerSettings = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
128 static uint32_t actualPointerFirmware = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
129 static uint32_t actualPointerFirmware2 = 0; |
38 | 130 |
131 /* Private function prototypes -----------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
132 static void chip_unselect(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
133 static void chip_select(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
134 static void error_led_on(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
135 static void error_led_off(void); |
38 | 136 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
137 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
138 static uint8_t read_spi(uint8_t unselect_CS_afterwards); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
139 static void write_address(uint8_t unselect_CS_afterwards); |
38 | 140 static void Error_Handler_extflash(void); |
141 static void wait_chip_not_busy(void); | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
142 static void ext_flash_incf_address(uint8_t type); |
38 | 143 //void ext_flash_incf_address_ring(void); |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
144 static void ext_flash_decf_address_ring(uint8_t type); |
38 | 145 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
146 static void ext_flash_erase4kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
147 static void ext_flash_erase32kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
148 static void ext_flash_erase64kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
149 static uint8_t ext_flash_erase_if_on_page_start(void); |
38 | 150 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
151 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase); |
38 | 152 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
153 static void ext_flash_read_block(uint8_t *getByte, uint8_t type); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
154 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
155 static void ext_flash_read_block_stop(void); |
38 | 156 |
157 static void ef_hw_rough_delay_us(uint32_t delayUs); | |
158 static void ef_erase_64K(uint32_t blocks); | |
159 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
160 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
161 |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
162 static void ext_flash_disable_protection(void); |
38 | 163 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
164 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
165 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
166 static void ext_flash_find_start(void); |
38 | 167 |
168 | |
169 /* Exported functions --------------------------------------------------------*/ | |
170 | |
171 void ext_flash_write_firmware(uint8_t *pSample1, uint32_t length1)//, uint8_t *pSample2, uint32_t length2) | |
172 { | |
173 general32to8_Type lengthTransform; | |
174 | |
175 lengthTransform.u32 = length1; | |
176 | |
177 actualPointerFirmware = FWSTART; | |
178 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE, 1); | |
179 ef_write_block(pSample1,length1, EF_FIRMWARE, 1); | |
180 | |
181 // if(length2) | |
182 // ef_write_block(pSample2,length2, EF_FIRMWARE, 1); | |
183 } | |
184 | |
185 uint8_t ext_flash_read_firmware_version(char *text) | |
186 { | |
187 uint32_t backup = actualAddress; | |
188 uint8_t buffer[4]; | |
189 | |
190 // + 4 for length data, see ext_flash_write_firmware | |
191 actualAddress = FWSTART + 4 + 0x10000; | |
192 ext_flash_read_block_start(); | |
193 ext_flash_read_block(&buffer[0], EF_FIRMWARE); | |
194 ext_flash_read_block(&buffer[1], EF_FIRMWARE); | |
195 ext_flash_read_block(&buffer[2], EF_FIRMWARE); | |
196 ext_flash_read_block(&buffer[3], EF_FIRMWARE); | |
197 | |
198 ext_flash_read_block_stop(); | |
199 actualAddress = backup; | |
200 | |
201 uint8_t ptr = 0; | |
202 text[ptr++] = 'V'; | |
203 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[0] & 0x3F); | |
204 text[ptr++] = '.'; | |
205 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[1] & 0x3F); | |
206 text[ptr++] = '.'; | |
207 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[2] & 0x3F); | |
208 text[ptr++] = ' '; | |
209 if(buffer[3]) | |
210 { | |
211 text[ptr++] = 'b'; | |
212 text[ptr++] = 'e'; | |
213 text[ptr++] = 't'; | |
214 text[ptr++] = 'a'; | |
215 text[ptr++] = ' '; | |
216 } | |
217 return ptr; | |
218 } | |
219 | |
220 | |
221 uint32_t ext_flash_read_firmware(uint8_t *pSample1, uint32_t max_length, uint8_t *magicByte) | |
222 { | |
223 uint32_t backup = actualAddress; | |
224 general32to8_Type lengthTransform; | |
225 | |
226 actualAddress = FWSTART; | |
227 ext_flash_read_block_start(); | |
228 | |
229 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE); | |
230 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE); | |
231 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE); | |
232 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE); | |
233 | |
234 | |
235 if(lengthTransform.u32 == 0xFFFFFFFF) | |
236 { | |
237 lengthTransform.u32 = 0xFFFFFFFF; | |
238 } | |
239 else | |
240 if(lengthTransform.u32 > max_length) | |
241 { | |
242 lengthTransform.u32 = 0xFF000000; | |
243 } | |
244 else | |
245 { | |
246 for(uint32_t i = 0; i<lengthTransform.u32; i++) | |
247 { | |
248 ext_flash_read_block(&pSample1[i], EF_FIRMWARE); | |
249 } | |
250 | |
251 } | |
252 | |
253 ext_flash_read_block_stop(); | |
254 | |
255 if(magicByte) | |
256 { | |
257 *magicByte = pSample1[0x10000 + 0x3E]; // 0x3E == 62 | |
258 } | |
259 | |
260 actualAddress = backup; | |
261 return lengthTransform.u32; | |
262 } | |
263 | |
264 | |
265 void ext_flash_write_firmware2(uint32_t offset, uint8_t *pSample1, uint32_t length1, uint8_t *pSample2, uint32_t length2) | |
266 { | |
267 general32to8_Type lengthTransform, offsetTransform; | |
268 | |
269 lengthTransform.u32 = length1 + length2; | |
270 offsetTransform.u32 = offset; | |
271 | |
272 actualPointerFirmware2 = FWSTART2; | |
273 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE2, 1); | |
274 ef_write_block(offsetTransform.u8,4, EF_FIRMWARE2, 1); | |
275 ef_write_block(pSample1,length1, EF_FIRMWARE2, 1); | |
276 if(length2) | |
277 ef_write_block(pSample2,length2, EF_FIRMWARE2, 1); | |
278 } | |
279 | |
280 | |
281 uint32_t ext_flash_read_firmware2(uint32_t *offset, uint8_t *pSample1, uint32_t max_length1, uint8_t *pSample2, uint32_t max_length2) | |
282 { | |
283 uint32_t backup = actualAddress; | |
284 uint32_t length1, length2; | |
285 general32to8_Type lengthTransform, offsetTransform; | |
286 | |
287 actualAddress = FWSTART2; | |
288 ext_flash_read_block_start(); | |
289 | |
290 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE2); | |
291 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE2); | |
292 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE2); | |
293 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE2); | |
294 | |
295 ext_flash_read_block(&offsetTransform.u8[0], EF_FIRMWARE2); | |
296 ext_flash_read_block(&offsetTransform.u8[1], EF_FIRMWARE2); | |
297 ext_flash_read_block(&offsetTransform.u8[2], EF_FIRMWARE2); | |
298 ext_flash_read_block(&offsetTransform.u8[3], EF_FIRMWARE2); | |
299 | |
300 *offset = offsetTransform.u32; | |
301 | |
302 if(lengthTransform.u32 == 0xFFFFFFFF) | |
303 { | |
304 lengthTransform.u32 = 0xFFFFFFFF; | |
305 } | |
306 else | |
307 if(lengthTransform.u32 > max_length1 + max_length2) | |
308 { | |
309 lengthTransform.u32 = 0xFF000000; | |
310 } | |
311 else | |
312 { | |
313 if(lengthTransform.u32 < max_length1) | |
314 { | |
315 length1 = lengthTransform.u32; | |
316 length2 = 0; | |
317 } | |
318 else | |
319 { | |
320 length1 = max_length1; | |
321 length2 = lengthTransform.u32 - max_length1; | |
322 } | |
323 | |
324 if(pSample1) | |
325 { | |
326 for(uint32_t i = 0; i<length1; i++) | |
327 { | |
328 ext_flash_read_block(&pSample1[i], EF_FIRMWARE2); | |
329 } | |
330 if(pSample2) | |
331 { | |
332 for(uint32_t i = 0; i<length2; i++) | |
333 { | |
334 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2); | |
335 } | |
336 } | |
337 } | |
338 else if(pSample2) | |
339 { | |
340 actualAddress += length1; | |
341 for(uint32_t i = 0; i<length2; i++) | |
342 { | |
343 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2); | |
344 } | |
345 } | |
346 } | |
347 ext_flash_read_block_stop(); | |
348 actualAddress = backup; | |
349 return lengthTransform.u32; | |
350 } | |
351 | |
352 | |
353 void ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(uint8_t *buffer) | |
354 { | |
355 SDeviceLine data[16]; | |
356 uint8_t tempLengthIngnore; | |
357 uint16_t count; | |
358 uint8_t transfer; | |
359 | |
360 RTC_DateTypeDef Sdate; | |
361 RTC_TimeTypeDef Stime; | |
362 | |
363 actualAddress = DDSTART; | |
364 | |
365 ext_flash_read_block_start(); | |
366 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA); | |
367 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA); | |
368 | |
369 ext_flash_read_block_multi((uint8_t *)data,16*3*4, EF_DEVICEDATA); | |
370 ext_flash_read_block_stop(); | |
371 | |
372 count = 0; | |
373 for(int i=0;i<16;i++) | |
374 { | |
375 transfer = (data[i].value_int32 >> 24) & 0xFF; | |
376 buffer[count++] = transfer; | |
377 transfer = (data[i].value_int32 >> 16) & 0xFF; | |
378 buffer[count++] = transfer; | |
379 transfer = (data[i].value_int32 >> 8) & 0xFF; | |
380 buffer[count++] = transfer; | |
381 transfer = (data[i].value_int32) & 0xFF; | |
382 buffer[count++] = transfer; | |
383 | |
384 translateDate(data[i].date_rtc_dr, &Sdate); | |
385 translateTime(data[i].time_rtc_tr, &Stime); | |
386 buffer[count++] = Sdate.Year; | |
387 buffer[count++] = Sdate.Month; | |
388 buffer[count++] = Sdate.Date; | |
389 buffer[count++] = Stime.Hours; | |
390 } | |
391 } | |
392 | |
393 | |
394 #ifndef BOOTLOADER_STANDALONE | |
395 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
396 void ext_flash_write_devicedata(uint8_t resetRing) |
38 | 397 { |
398 uint8_t *pData; | |
399 const uint16_t length = sizeof(SDevice); | |
400 uint8_t length_lo, length_hi; | |
401 uint8_t dataLength[2] = { 0 }; | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
402 uint32_t tmpBlockStart; |
38 | 403 |
404 ext_flash_disable_protection(); | |
405 | |
406 pData = (uint8_t *)stateDeviceGetPointer(); | |
407 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
408 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */ |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
409 if((resetRing) || ((actualPointerDevicedata + length) >= DDSTOP)) |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
410 { |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
411 actualPointerDevicedata = DDSTART; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
412 } |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
413 tmpBlockStart = actualPointerDevicedata; |
38 | 414 |
415 length_lo = (uint8_t)(length & 0xFF); | |
416 length_hi = (uint8_t)(length >> 8); | |
417 dataLength[0] = length_lo; | |
418 dataLength[1] = length_hi; | |
419 | |
420 ef_write_block(dataLength,2, EF_DEVICEDATA, 0); | |
421 ef_write_block(pData,length, EF_DEVICEDATA, 0); | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
422 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
423 actualPointerDevicedata_Read = tmpBlockStart; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
424 |
38 | 425 } |
426 | |
427 | |
428 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length) | |
429 { | |
430 uint16_t length; | |
431 uint8_t length_lo, length_hi; | |
432 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
433 actualAddress = actualPointerDevicedata_Read; |
38 | 434 |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
435 length = 0; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
436 length_lo = 0; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
437 length_hi = 0; |
38 | 438 ext_flash_read_block_start(); |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
439 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
440 |
38 | 441 ext_flash_read_block(&length_lo, EF_DEVICEDATA); |
442 ext_flash_read_block(&length_hi, EF_DEVICEDATA); | |
443 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
444 while ((length_lo != 0xFF) && (length_hi != 0xFF)) |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
445 { |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
446 length = (length_hi * 256) + length_lo; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
447 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
448 if(length > max_length) |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
449 return 0; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
450 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
451 ext_flash_read_block_multi(buffer,length,EF_DEVICEDATA); |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
452 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
453 ext_flash_read_block(&length_lo, EF_DEVICEDATA); /* check if another devicedata set is available */ |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
454 ext_flash_read_block(&length_hi, EF_DEVICEDATA); /* length will be 0xFFFF if a empty memory is read */ |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
455 } |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
456 ext_flash_decf_address_ring(EF_DEVICEDATA); /* set pointer back to empty address */ |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
457 ext_flash_decf_address_ring(EF_DEVICEDATA); |
38 | 458 ext_flash_read_block_stop(); |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
459 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
460 if(actualAddress > actualPointerDevicedata) /* the write pointer has not yet been set up probably */ |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
461 { |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
462 actualPointerDevicedata = actualAddress; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
463 } |
38 | 464 return length; |
465 } | |
466 | |
467 | |
468 void ext_flash_write_vpm(SVpm *vpmInput) | |
469 { | |
470 uint8_t *pData; | |
471 const uint16_t length = sizeof(SVpm); | |
472 | |
473 uint8_t length_lo, length_hi; | |
474 uint8_t dataLength[2] = { 0 }; | |
475 | |
476 pData = (uint8_t *)vpmInput; | |
477 | |
478 actualPointerVPM = VPMSTART; | |
479 | |
480 length_lo = (uint8_t)(length & 0xFF); | |
481 length_hi = (uint8_t)(length >> 8); | |
482 dataLength[0] = length_lo; | |
483 dataLength[1] = length_hi; | |
484 | |
485 ef_write_block(dataLength,2, EF_VPMDATA, 0); | |
486 ef_write_block(pData,length, EF_VPMDATA, 0); | |
487 } | |
488 | |
489 | |
490 int ext_flash_read_vpm(SVpm *vpmOutput) | |
491 { | |
492 uint8_t *pData; | |
493 const uint16_t length = sizeof(SVpm); | |
494 uint8_t length_lo, length_hi; | |
495 int output; | |
496 | |
497 actualAddress = VPMSTART; | |
498 | |
499 ext_flash_read_block_start(); | |
500 ext_flash_read_block(&length_lo, EF_VPMDATA); | |
501 ext_flash_read_block(&length_hi, EF_VPMDATA); | |
502 if((length_lo == (uint8_t)(length & 0xFF)) | |
503 &&(length_hi == (uint8_t)(length >> 8))) | |
504 { | |
505 pData = (uint8_t *)vpmOutput; | |
506 for(uint16_t i = 0; i < length; i++) | |
507 ext_flash_read_block(&pData[i], EF_VPMDATA); | |
508 output = length; | |
509 } | |
510 else | |
511 output = 0; | |
512 | |
513 ext_flash_read_block_stop(); | |
514 return output; | |
515 } | |
516 | |
517 #ifdef DEMOMODE | |
518 void ext_flash_write_settings(void) | |
519 { | |
520 return; | |
521 } | |
522 #else | |
523 void ext_flash_write_settings(void) | |
524 { | |
525 uint8_t *pData; | |
526 const uint16_t length = sizeof(SSettings); | |
527 uint8_t length_lo, length_hi; | |
528 uint8_t dataLength[2] = { 0 }; | |
529 | |
530 ext_flash_disable_protection(); | |
531 | |
532 if(stateRealGetPointer()->lastKnownBatteryPercentage) | |
533 { | |
534 settingsGetPointer()->lastKnownBatteryPercentage = stateRealGetPointer()->lastKnownBatteryPercentage; | |
535 } | |
536 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat; | |
537 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat; | |
538 | |
539 pData = (uint8_t *)settingsGetPointer(); | |
540 | |
541 actualPointerSettings = SETTINGSSTART; | |
542 | |
543 length_lo = (uint8_t)(length & 0xFF); | |
544 length_hi = (uint8_t)(length >> 8); | |
545 dataLength[0] = length_lo; | |
546 dataLength[1] = length_hi; | |
547 | |
548 ef_write_block(dataLength,2, EF_SETTINGS, 0); | |
549 ef_write_block(pData,length, EF_SETTINGS, 0); | |
550 // ext_flash_enable_protection(); | |
551 } | |
552 #endif | |
553 | |
554 | |
555 /* CHANGES 150929 hw | |
556 * this now allows to read old settings too | |
557 * but make sure that everything is fixed in | |
558 * set_new_settings_missing_in_ext_flash | |
559 * new settings should be fine as they are added | |
560 * and loaded before calling this function | |
561 */ | |
562 uint8_t ext_flash_read_settings(void) | |
563 { | |
564 uint8_t returnValue = HAL_BUSY; | |
565 uint8_t *pData; | |
566 const uint16_t lengthStandardNow = sizeof(SSettings); | |
567 uint8_t length_lo, length_hi; | |
568 uint16_t lengthOnEEPROM; | |
569 uint32_t header; | |
570 SSettings *pSettings = settingsGetPointer(); | |
571 | |
572 actualAddress = SETTINGSSTART; | |
573 | |
574 ext_flash_read_block_start(); | |
575 ext_flash_read_block(&length_lo, EF_SETTINGS); | |
576 ext_flash_read_block(&length_hi, EF_SETTINGS); | |
577 | |
578 lengthOnEEPROM = length_hi * 256; | |
579 lengthOnEEPROM += length_lo; | |
580 if(lengthOnEEPROM <= lengthStandardNow) | |
581 { | |
582 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); | |
583 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) | |
584 { | |
585 returnValue = HAL_OK; | |
586 pSettings->header = header; | |
587 pData = (uint8_t *)pSettings + 4; /* header */ | |
588 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++) | |
589 ext_flash_read_block(&pData[i], EF_SETTINGS); | |
590 } | |
591 else | |
592 { | |
593 returnValue = HAL_ERROR; | |
594 } | |
595 } | |
596 ext_flash_read_block_stop(); | |
597 return returnValue; | |
598 } | |
599 | |
600 | |
601 | |
602 | |
603 /* ext_flash_start_new_dive_log_and_set_actualPointerSample | |
604 * prepares the write sample pointer | |
605 * to be used by ext_flash_write_sample() | |
606 * to be set in the * pHeaderPreDive | |
607 * for write with ext_flash_create_new_dive_log() and ext_flash_close_new_dive_log() | |
608 */ | |
609 void ext_flash_start_new_dive_log_and_set_actualPointerSample(uint8_t *pHeaderPreDive) | |
610 { | |
611 convert_Type data; | |
612 SSettings *settings = settingsGetPointer(); | |
613 | |
614 /* new 5. Jan. 2015 */ | |
615 actualPointerSample = settings->logFlashNextSampleStartAddress; | |
616 | |
617 if(!ext_flash_test_remaining_space_of_page_empty(actualPointerSample, 4)) | |
618 ext_flash_set_to_begin_of_next_page(&actualPointerSample, EF_SAMPLE); | |
619 | |
620 if((actualPointerSample < SAMPLESTART) || (actualPointerSample > SAMPLESTOP)) | |
621 actualPointerSample = SAMPLESTART; | |
622 | |
623 data.u32bit = actualPointerSample; | |
624 pHeaderPreDive[2] = data.u8bit.byteLow; | |
625 pHeaderPreDive[3] = data.u8bit.byteMidLow; | |
626 pHeaderPreDive[4] = data.u8bit.byteMidHigh; | |
627 /* to start sample writing and header etc. pp. */ | |
628 ext_flash_disable_protection_for_logbook(); | |
629 } | |
630 | |
631 | |
632 /* ext_flash_create_new_dive_log | |
633 * uses the first header without HEADER2OFFSET | |
634 * for the header it is not important to be complete | |
635 * and can be reconstructed | |
636 * ext_flash_start_new_dive_log_and_set_actualPointerSample() | |
637 * has to be called before to set the actualPointerSample | |
638 * in the header | |
639 * the following func writes to header to the ext_flash | |
640 */ | |
641 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive) | |
642 { | |
643 SSettings *settings; | |
644 uint8_t id, id_next; | |
645 uint8_t header1, header2; | |
646 | |
647 settings = settingsGetPointer(); | |
648 id = settings->lastDiveLogId; | |
649 | |
650 actualAddress = HEADERSTART + (0x800 * id); | |
651 ext_flash_read_block_start(); | |
652 ext_flash_read_block(&header1, EF_SAMPLE); | |
653 ext_flash_read_block(&header2, EF_SAMPLE); | |
654 ext_flash_read_block_stop(); | |
655 | |
656 if((header1 == 0xFA) && (header2 == 0xFA)) | |
657 { | |
658 id += 1; /* 0-255, auto rollover */ | |
659 if(id & 1) | |
660 { | |
661 actualAddress = HEADERSTART + (0x800 * id); | |
662 ext_flash_read_block_start(); | |
663 ext_flash_read_block(&header1, EF_SAMPLE); | |
664 ext_flash_read_block(&header2, EF_SAMPLE); | |
665 ext_flash_read_block_stop(); | |
666 if((header1 == 0xFA) && (header2 == 0xFA)) | |
667 id += 1; | |
668 } | |
669 } | |
670 else | |
671 { | |
672 id = 0; | |
673 } | |
674 | |
675 /* delete next header */ | |
676 id_next = id + 1; | |
677 actualPointerHeader = HEADERSTART + (0x800 * id_next); | |
678 ef_write_block(0,0, EF_HEADER, 0); | |
679 | |
680 settings->lastDiveLogId = id; | |
681 actualPointerHeader = HEADERSTART + (0x800 * id); | |
682 | |
683 if(pHeaderPreDive != 0) | |
684 ef_write_block(pHeaderPreDive,HEADERSIZE, EF_HEADER, 0); | |
685 } | |
686 | |
687 | |
688 void ext_flash_close_new_dive_log(uint8_t *pHeaderPostDive ) | |
689 { | |
690 SSettings * settings = settingsGetPointer(); | |
691 uint8_t id; | |
692 convert_Type startAddress; | |
693 convert_Type data; | |
694 uint32_t backup; | |
695 | |
696 uint8_t sampleData[3]; | |
697 actualAddress = actualPointerSample; | |
698 sampleData[0] = 0xFD; | |
699 sampleData[1] = 0xFD; | |
700 ext_flash_write_sample(sampleData, 2); | |
701 | |
702 /* end of sample data, pointing to the last sample 0xFD | |
703 */ | |
704 actualAddress = actualPointerSample; // change hw 17.09.2015 | |
705 ext_flash_decf_address_ring(EF_SAMPLE); // 17.09.2015: this decf actualAddress only!! | |
706 actualPointerSample = actualAddress; // change hw 17.09.2015 | |
707 data.u32bit = actualPointerSample; | |
708 | |
709 pHeaderPostDive[5] = data.u8bit.byteLow; | |
710 pHeaderPostDive[6] = data.u8bit.byteMidLow; | |
711 pHeaderPostDive[7] = data.u8bit.byteMidHigh; | |
712 | |
713 /* take data written before, calculate length and write | |
714 SLogbookHeader has different order: length (byte# 8,9,10) prior to profile version (byte# 11) | |
715 */ | |
716 startAddress.u8bit.byteLow = pHeaderPostDive[2]; | |
717 startAddress.u8bit.byteMidLow = pHeaderPostDive[3]; | |
718 startAddress.u8bit.byteMidHigh = pHeaderPostDive[4]; | |
719 startAddress.u8bit.byteHigh = 0; | |
720 | |
721 if(startAddress.u32bit < actualPointerSample) | |
722 data.u32bit = 1 + actualPointerSample - startAddress.u32bit; | |
723 else | |
724 data.u32bit = 2 + (actualPointerSample - SAMPLESTART) + (SAMPLESTOP - startAddress.u32bit); | |
725 | |
726 pHeaderPostDive[8] = data.u8bit.byteLow; | |
727 pHeaderPostDive[9] = data.u8bit.byteMidLow; | |
728 pHeaderPostDive[10] = data.u8bit.byteMidHigh; | |
729 | |
730 /* set id and write post-dive-header | |
731 */ | |
732 id = settings->lastDiveLogId; | |
733 actualPointerHeader = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
734 | |
735 ef_write_block(pHeaderPostDive,HEADERSIZE, EF_HEADER, 0); | |
736 | |
737 /* write length at beginning of sample | |
738 and write proper beginning for next dive to actualPointerSample | |
739 */ | |
740 backup = actualPointerSample; | |
741 actualPointerSample = startAddress.u32bit; // is still 0xFF | |
742 sampleData[0] = data.u8bit.byteLow; | |
743 sampleData[1] = data.u8bit.byteMidLow; | |
744 sampleData[2] = data.u8bit.byteMidHigh; | |
745 ext_flash_overwrite_sample_without_erase(sampleData, 3); | |
746 | |
747 actualAddress = backup; | |
748 ext_flash_incf_address(EF_SAMPLE); | |
749 actualPointerSample = actualAddress; | |
750 ext_flash_enable_protection(); | |
751 } | |
752 | |
753 | |
754 void ext_flash_write_sample(uint8_t *pSample, uint16_t length) | |
755 { | |
756 ef_write_block(pSample,length, EF_SAMPLE, 0); | |
757 | |
758 SSettings *settings = settingsGetPointer(); | |
759 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
760 } | |
761 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
762 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length) |
38 | 763 { |
764 ef_write_block(pSample,length, EF_SAMPLE, 1); | |
765 } | |
766 | |
767 | |
768 uint8_t ext_flash_count_dive_headers(void) | |
769 { | |
770 uint8_t id = 0; | |
771 uint8_t counter = 0; | |
772 uint16_t headerStartData = 0x0000; | |
773 | |
774 id = settingsGetPointer()->lastDiveLogId; | |
775 | |
776 do | |
777 { | |
778 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
779 ext_flash_read_block_start(); | |
780 ext_flash_read_block_multi((uint8_t *)&headerStartData, 2, EF_HEADER); | |
781 ext_flash_read_block_stop(); | |
782 counter++; | |
783 id -=1; | |
784 } while((headerStartData == 0xFAFA) && (counter < 255)); | |
785 return (counter - 1); | |
786 } | |
787 | |
788 | |
789 void ext_flash_read_dive_header(uint8_t *pHeaderToFill, uint8_t StepBackwards) | |
790 { | |
791 SSettings *settings; | |
792 uint8_t id; | |
793 uint16_t i; | |
794 | |
795 settings = settingsGetPointer(); | |
796 id = settings->lastDiveLogId; | |
797 id -= StepBackwards; /* 0-255, auto rollover */ | |
798 | |
799 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
800 ext_flash_read_block_start(); | |
801 for(i = 0; i < HEADERSIZE; i++) | |
802 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
803 ext_flash_read_block_stop(); | |
804 | |
805 } | |
806 | |
807 void ext_flash_read_dive_header2(uint8_t *pHeaderToFill, uint8_t id, _Bool bOffset) | |
808 { | |
809 | |
810 uint16_t i; | |
811 actualAddress = HEADERSTART + (0x800 * id) ; | |
812 | |
813 if(bOffset) | |
814 actualAddress += HEADER2OFFSET; | |
815 ext_flash_read_block_start(); | |
816 for(i = 0; i < HEADERSIZE; i++) | |
817 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
818 ext_flash_read_block_stop(); | |
819 } | |
820 | |
821 | |
822 uint32_t ext_flash_read_dive_raw_with_double_header_1K(uint8_t *data, uint32_t max_size, uint8_t StepBackwards) | |
823 { | |
824 if(max_size < 0x800) | |
825 return 0; | |
826 | |
827 uint8_t id; | |
828 convert_Type dataStart, dataEnd; | |
829 uint32_t LengthAll = 0; | |
830 | |
831 id = settingsGetPointer()->lastDiveLogId; | |
832 id -= StepBackwards; /* 0-255, auto rollover */ | |
833 | |
834 // clear data | |
835 for(int i=0;i<0x800;i++) | |
836 data[i] = 0xFF; | |
837 | |
838 // copy primary/pre-dive | |
839 actualAddress = HEADERSTART + (0x800 * id); | |
840 ext_flash_read_block_start(); | |
841 for(int i = 0; i < HEADERSIZE; i++) | |
842 ext_flash_read_block(&data[i], EF_HEADER); | |
843 ext_flash_read_block_stop(); | |
844 | |
845 // copy main/secondary/post-dive | |
846 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
847 ext_flash_read_block_start(); | |
848 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
849 ext_flash_read_block(&data[i], EF_HEADER); | |
850 ext_flash_read_block_stop(); | |
851 | |
852 // data | |
853 | |
854 dataStart.u8bit.byteHigh = 0; | |
855 dataStart.u8bit.byteLow = data[0x402]; | |
856 dataStart.u8bit.byteMidLow = data[0x403]; | |
857 dataStart.u8bit.byteMidHigh = data[0x404]; | |
858 | |
859 dataEnd.u8bit.byteHigh = 0; | |
860 dataEnd.u8bit.byteLow = data[0x405]; | |
861 dataEnd.u8bit.byteMidLow = data[0x406]; | |
862 dataEnd.u8bit.byteMidHigh = data[0x407]; | |
863 | |
864 actualPointerSample = dataStart.u32bit; | |
865 if(dataEnd.u32bit >= dataStart.u32bit) | |
866 LengthAll = 1 + dataEnd.u32bit - dataStart.u32bit; | |
867 else | |
868 LengthAll = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
869 | |
870 LengthAll += 0x800; | |
871 | |
872 if(LengthAll > max_size) | |
873 return 0x800; | |
874 | |
875 actualAddress = actualPointerSample; | |
876 ext_flash_read_block_start(); | |
877 for(uint32_t i = 0x800; i < LengthAll; i++) | |
878 ext_flash_read_block(&data[i], EF_SAMPLE); | |
879 ext_flash_read_block_stop(); | |
880 return LengthAll; | |
881 } | |
882 | |
883 void ext_flash_write_dive_raw_with_double_header_1K(uint8_t *data, uint32_t length) | |
884 { | |
885 convert_Type dataStart, dataEnd; | |
886 SLogbookHeader headerTemp; | |
887 | |
888 // set actualPointerSample and get pointer to sample storage and disable flash write protect | |
889 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t *)&headerTemp); | |
890 | |
891 dataStart.u8bit.byteHigh = 0; | |
892 dataStart.u8bit.byteLow = headerTemp.pBeginProfileData[0]; | |
893 dataStart.u8bit.byteMidLow = headerTemp.pBeginProfileData[1]; | |
894 dataStart.u8bit.byteMidHigh = headerTemp.pBeginProfileData[2]; | |
895 | |
896 dataEnd.u32bit = dataStart.u32bit + length - 0x801; | |
897 if(dataEnd.u32bit > SAMPLESTOP) | |
898 dataEnd.u32bit -= SAMPLESTOP + SAMPLESTART - 1; | |
899 | |
900 data[0x002] = data[0x402] = dataStart.u8bit.byteLow; | |
901 data[0x003] = data[0x403] = dataStart.u8bit.byteMidLow; | |
902 data[0x004] = data[0x404] = dataStart.u8bit.byteMidHigh; | |
903 data[0x005] = data[0x405] = dataEnd.u8bit.byteLow; | |
904 data[0x006] = data[0x406] = dataEnd.u8bit.byteMidLow; | |
905 data[0x007] = data[0x407] = dataEnd.u8bit.byteMidHigh; | |
906 | |
907 // set actualPointerHeader to next free header and update lastDiveLogId | |
908 ext_flash_create_new_dive_log(0); | |
909 | |
910 // copy header data | |
911 ef_write_block(data,0x800,EF_HEADER, 1); | |
912 | |
913 // copy sample data | |
914 ef_write_block(&data[0x800], length-0x800, EF_SAMPLE, 1); | |
915 | |
916 // update logFlashNextSampleStartAddress | |
917 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; | |
918 } | |
919 | |
920 | |
921 // =============================================================================== | |
922 // ext_flash_read_header_memory | |
923 /// @brief This function returns the entire header space 1:1 | |
924 /// @date 04-April-2016 | |
925 /// | |
926 /// @param *data 256KB output | |
927 // =============================================================================== | |
928 void ext_flash_read_header_memory(uint8_t *data) | |
929 { | |
930 actualAddress = HEADERSTART; | |
931 actualPointerHeader = actualAddress; | |
932 ext_flash_read_block_start(); | |
933 for(int i=0;i<8;i++) | |
934 ext_flash_read_block_multi(&data[0x8000 * i], 0x8000, EF_HEADER); | |
935 ext_flash_read_block_stop(); | |
936 } | |
937 | |
938 | |
939 // =============================================================================== | |
940 // ext_flash_read_header_memory | |
941 /// @brief This function erases and overwrites the entire logbook header block | |
942 /// @date 04-April-2016 | |
943 /// | |
944 /// @param *data 256KB input of header memory 1:1 | |
945 // =============================================================================== | |
946 void ext_flash_write_header_memory(uint8_t *data) | |
947 { | |
948 actualAddress = HEADERSTART; | |
949 actualPointerHeader = actualAddress; | |
950 ef_write_block(data, 0x40000, EF_HEADER, 0); | |
951 } | |
952 | |
953 | |
954 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes) | |
955 { | |
956 SSettings *settings = settingsGetPointer(); | |
957 uint8_t id; | |
958 convert_Type dataStart, dataEnd; | |
959 uint8_t header1, header2; | |
960 | |
961 id = settings->lastDiveLogId; | |
962 id -= StepBackwards; /* 0-255, auto rollover */ | |
963 # | |
964 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
965 actualPointerHeader = actualAddress; | |
966 | |
967 ext_flash_read_block_start(); | |
968 /* little endian */ | |
969 ext_flash_read_block(&header1, EF_HEADER); | |
970 ext_flash_read_block(&header2, EF_HEADER); | |
971 dataStart.u8bit.byteHigh = 0; | |
972 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
973 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
974 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
975 dataEnd.u8bit.byteHigh = 0; | |
976 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
977 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
978 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
979 ext_flash_read_block_stop(); | |
980 | |
981 actualPointerSample = dataStart.u32bit; | |
982 if(dataEnd.u32bit >= dataStart.u32bit) | |
983 LengthLeftSampleRead = 1 + dataEnd.u32bit - dataStart.u32bit; | |
984 else | |
985 LengthLeftSampleRead = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
986 *totalNumberOfBytes = LengthLeftSampleRead; | |
987 | |
988 actualAddress = actualPointerSample; | |
989 ext_flash_read_block_start(); | |
990 } | |
991 | |
992 | |
993 void ext_flash_read_next_sample_part(uint8_t *pSample, uint8_t length) | |
994 { | |
995 for(uint16_t i = 0; i < length; i++) | |
996 ext_flash_read_block(&pSample[i], EF_SAMPLE); | |
997 } | |
998 | |
999 | |
1000 void ext_flash_close_read_sample(void) | |
1001 { | |
1002 actualPointerSample = actualAddress; | |
1003 ext_flash_read_block_stop(); | |
1004 } | |
1005 | |
1006 | |
1007 void ext_flash_set_entry_point(void) | |
1008 { | |
1009 entryPoint = actualAddress; | |
1010 } | |
1011 | |
1012 | |
1013 void ext_flash_reopen_read_sample_at_entry_point(void) | |
1014 { | |
1015 error_led_on(); | |
1016 chip_unselect(); | |
1017 wait_chip_not_busy(); | |
1018 | |
1019 actualAddress = entryPoint; | |
1020 ext_flash_read_block_start(); | |
1021 error_led_off(); | |
1022 } | |
1023 | |
1024 /* | |
1025 uint8_t ext_flash_point_to_64k_block_in_headerSpace(uint8_t logId) | |
1026 { | |
1027 uint32_t pointerToData = logId * 0x800; | |
1028 | |
1029 return pointerToData / 0x10000; | |
1030 } | |
1031 */ | |
1032 | |
1033 | |
1034 // =============================================================================== | |
1035 // ext_flash_repair_dive_numbers_starting_count_helper | |
1036 /// @brief | |
1037 /// @date 22-June-2016 | |
1038 | |
1039 // =============================================================================== | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1040 static uint16_t ext_flash_repair_dive_numbers_starting_count_helper(uint8_t *data, uint8_t *change64k, uint16_t startNumber, uint8_t lastLogId) |
38 | 1041 { |
1042 const uint32_t headerStep = 0x800; | |
1043 uint8_t actualLogId = 0; | |
1044 uint16_t oldNumber = 0; | |
1045 uint16_t actualNumber = 0; | |
1046 SLogbookHeader *ptrLogbookHeader = 0; | |
1047 | |
1048 if(startNumber == 0) | |
1049 return 0; | |
1050 | |
1051 actualNumber = startNumber - 1; | |
1052 | |
282 | 1053 // where is the oldest dive (Which is now getting startNumber) |
38 | 1054 // use first header for ease (without HEADER2OFFSET for end of dive header) |
1055 // compare for lastLogId to prevent endless loop | |
1056 | |
1057 if(*(uint16_t*)&data[lastLogId * headerStep] != 0xFAFA) | |
1058 return 0; | |
1059 | |
1060 actualLogId = lastLogId - 1; | |
1061 while((*(uint16_t*)&data[actualLogId * headerStep] == 0xFAFA) && (actualLogId != lastLogId)) | |
1062 { | |
1063 actualLogId--; | |
1064 } | |
1065 | |
1066 // now pointing to one behind the last | |
1067 while(actualLogId != lastLogId) | |
1068 { | |
1069 actualLogId++; | |
1070 actualNumber++; | |
1071 ptrLogbookHeader = (SLogbookHeader *)&data[actualLogId * headerStep]; | |
1072 | |
1073 oldNumber = ptrLogbookHeader->diveNumber; | |
1074 if(oldNumber != actualNumber) | |
1075 { | |
1076 // change64k[ext_flash_point_to_64k_block_in_headerSpace(actualLogId )] = 1; | |
1077 change64k[(actualLogId * 0x800)/0x10000] = 1; | |
1078 ptrLogbookHeader->diveNumber = actualNumber; | |
1079 ptrLogbookHeader = (SLogbookHeader *)(&data[actualLogId * headerStep] + HEADER2OFFSET); | |
1080 ptrLogbookHeader->diveNumber = actualNumber; | |
1081 } | |
1082 } | |
1083 | |
1084 return actualNumber; | |
1085 } | |
1086 | |
1087 // =============================================================================== | |
1088 // ext_flash_repair_SPECIAL_dive_numbers_starting_count_with | |
1089 /// @brief This function | |
1090 /// @date 04-April-2016 | |
282 | 1091 /// problem (160621): 64K blocks (32 dives) in the new flash memory chip |
1092 /// This block needs to be deleted | |
1093 /// these where only 4KB block before | |
38 | 1094 /// @output endCount, last diveNumber |
1095 | |
1096 // =============================================================================== | |
1097 uint16_t ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) | |
1098 { | |
1099 uint32_t logCopyDataPtr = 0; | |
1100 uint8_t *data; | |
1101 uint16_t lastCount; | |
282 | 1102 uint8_t listOfChanged64kBlocks[8]; // 32 dives each 64K |
38 | 1103 |
1104 logCopyDataPtr = getFrame(97); | |
1105 data = (uint8_t *)logCopyDataPtr; | |
1106 | |
1107 for(int i=0;i<8;i++) | |
1108 listOfChanged64kBlocks[i] = 0; | |
1109 | |
1110 actualAddress = HEADERSTART; | |
1111 ext_flash_read_block_start(); | |
1112 ext_flash_read_block_multi(data,0x100000,EF_HEADER); | |
1113 ext_flash_read_block_stop(); | |
1114 | |
1115 lastCount = ext_flash_repair_dive_numbers_starting_count_helper(data, listOfChanged64kBlocks, startCount, settingsGetPointer()->lastDiveLogId); | |
1116 | |
1117 for(int i=0;i<8;i++) | |
1118 { | |
1119 if(listOfChanged64kBlocks[i] != 0) | |
1120 { | |
1121 actualPointerHeader = HEADERSTART + (i * 0x10000); | |
1122 ef_write_block(&data[i * 0x10000], 0x10000, EF_HEADER, 0); | |
1123 } | |
1124 } | |
1125 | |
1126 releaseFrame(97,logCopyDataPtr); | |
1127 if(settingsGetPointer()->totalDiveCounter < lastCount) | |
1128 { | |
1129 settingsGetPointer()->totalDiveCounter = lastCount; | |
1130 } | |
1131 return lastCount; | |
1132 } | |
1133 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1134 /* |
38 | 1135 void OLD_ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) |
1136 { | |
1137 uint16_t counterStorage[256]; | |
1138 uint8_t start = 0xFF; | |
1139 uint32_t logCopyDataPtr = 0; | |
1140 uint8_t *data; | |
1141 uint8_t startAbsolute = 0; | |
1142 int16_t count = 0; | |
1143 _Bool repair = 0; | |
1144 uint8_t startBackup = 0; | |
1145 | |
1146 SLogbookHeader tempLogbookHeader; | |
1147 SLogbookHeader *ptrHeaderInData1a; | |
1148 SLogbookHeader *ptrHeaderInData1b; | |
1149 SLogbookHeader *ptrHeaderInData2a; | |
1150 SLogbookHeader *ptrHeaderInData2b; | |
1151 | |
1152 logCopyDataPtr = getFrame(97); | |
1153 data = (uint8_t *)logCopyDataPtr; | |
1154 ptrHeaderInData1a = (SLogbookHeader *)logCopyDataPtr; | |
1155 ptrHeaderInData1b = (SLogbookHeader *)(logCopyDataPtr + HEADER2OFFSET); | |
1156 ptrHeaderInData2a = (SLogbookHeader *)(logCopyDataPtr + 0x800); | |
1157 ptrHeaderInData2b = (SLogbookHeader *)(logCopyDataPtr + 0x800 + HEADER2OFFSET); | |
1158 | |
1159 // get data | |
1160 for(int StepBackwards = 0; StepBackwards < 255; StepBackwards++) | |
1161 { | |
1162 logbook_getHeader(StepBackwards, &tempLogbookHeader); | |
1163 counterStorage[StepBackwards+1] = tempLogbookHeader.diveNumber; | |
1164 if(tempLogbookHeader.diveHeaderStart == 0xFAFA) | |
1165 start = StepBackwards; | |
1166 else | |
1167 break; | |
1168 } | |
1169 | |
1170 if(start == 0xFF) | |
1171 return; | |
1172 | |
1173 count = start + 1; | |
1174 startAbsolute = settingsGetPointer()->lastDiveLogId; | |
1175 | |
1176 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1177 |
38 | 1178 if(start%2) |
1179 { | |
1180 if(counterStorage[start] != startCount) | |
1181 { | |
1182 // clear data | |
1183 for(int i=0;i<0x800*2;i++) | |
1184 data[i] = 0xFF; | |
1185 | |
1186 uint8_t id = settingsGetPointer()->lastDiveLogId; | |
1187 id -= start; // 0-255, auto rollover | |
1188 | |
1189 // copy primary/pre-dive | |
1190 actualAddress = HEADERSTART + (0x800 * id); | |
1191 ext_flash_read_block_start(); | |
1192 for(int i = 0; i < HEADERSIZE; i++) | |
1193 ext_flash_read_block(&data[i], EF_HEADER); | |
1194 ext_flash_read_block_stop(); | |
1195 | |
1196 // copy main/secondary/post-dive | |
1197 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1198 ext_flash_read_block_start(); | |
1199 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1200 ext_flash_read_block(&data[i], EF_HEADER); | |
1201 ext_flash_read_block_stop(); | |
1202 | |
1203 // repair | |
1204 ptrHeaderInData2a->diveNumber = startCount; | |
1205 ptrHeaderInData2b->diveNumber = startCount; | |
1206 startCount++; | |
1207 | |
1208 // write | |
1209 actualAddress = HEADERSTART + (0x800 * (id-1)); | |
1210 ef_write_block(data,0x800*2,EF_HEADER, 0); | |
1211 } | |
1212 start--; | |
1213 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1214 |
38 | 1215 // for(int count = start; count > -1; count -= 2) |
1216 | |
1217 while(count > 0) | |
1218 { | |
1219 // clear data | |
1220 for(int i=0;i<0x1000;i++) | |
1221 data[i] = 0xFF; | |
1222 | |
1223 repair = 0; | |
1224 | |
1225 startBackup = startAbsolute; | |
1226 | |
1227 if(startAbsolute%2) // 0x800 to 0x1000 | |
1228 { | |
1229 // copy second pre-dive | |
1230 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1231 ext_flash_read_block_start(); | |
1232 for(int i = 0x800; i < HEADERSIZE+0x800; i++) | |
1233 ext_flash_read_block(&data[i], EF_HEADER); | |
1234 ext_flash_read_block_stop(); | |
1235 | |
1236 // copy second post-dive | |
1237 actualAddress = HEADERSTART + HEADER2OFFSET + (0x800 * startAbsolute); | |
1238 ext_flash_read_block_start(); | |
1239 for(int i = 0xC00; i < HEADERSIZE+0xC00; i++) | |
1240 ext_flash_read_block(&data[i], EF_HEADER); | |
1241 ext_flash_read_block_stop(); | |
1242 | |
1243 if(counterStorage[count] != startCount) | |
1244 { | |
1245 ptrHeaderInData2a->diveNumber = startCount; | |
1246 ptrHeaderInData2b->diveNumber = startCount; | |
1247 repair = 1; | |
1248 } | |
1249 startCount += 1; | |
1250 | |
1251 startAbsolute -= 1; | |
1252 count -= 1; | |
1253 | |
1254 if(count > 0) | |
1255 { | |
1256 // copy first pre-dive | |
1257 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1258 ext_flash_read_block_start(); | |
1259 for(int i = 0; i < HEADERSIZE; i++) | |
1260 ext_flash_read_block(&data[i], EF_HEADER); | |
1261 ext_flash_read_block_stop(); | |
1262 | |
1263 // copy first post-dive | |
1264 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1265 ext_flash_read_block_start(); | |
1266 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1267 ext_flash_read_block(&data[i], EF_HEADER); | |
1268 ext_flash_read_block_stop(); | |
1269 | |
1270 if(counterStorage[count] != startCount) | |
1271 { | |
1272 ptrHeaderInData1a->diveNumber = startCount; | |
1273 ptrHeaderInData1b->diveNumber = startCount; | |
1274 repair = 1; | |
1275 } | |
1276 startCount += 1; | |
1277 | |
1278 startAbsolute -= 1; | |
1279 count -= 1; | |
1280 } | |
1281 } | |
1282 else | |
1283 { | |
1284 // copy first pre-dive | |
1285 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1286 ext_flash_read_block_start(); | |
1287 for(int i = 0; i < HEADERSIZE; i++) | |
1288 ext_flash_read_block(&data[i], EF_HEADER); | |
1289 ext_flash_read_block_stop(); | |
1290 | |
1291 // copy first post-dive | |
1292 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1293 ext_flash_read_block_start(); | |
1294 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1295 ext_flash_read_block(&data[i], EF_HEADER); | |
1296 ext_flash_read_block_stop(); | |
1297 | |
1298 if(counterStorage[count] != startCount) | |
1299 { | |
1300 ptrHeaderInData1a->diveNumber = startCount; | |
1301 ptrHeaderInData1b->diveNumber = startCount; | |
1302 repair = 1; | |
1303 } | |
1304 startCount += 1; | |
1305 | |
1306 startAbsolute -= 1; | |
1307 count -= 1; | |
1308 } | |
1309 | |
1310 // write | |
1311 if(repair) | |
1312 { | |
1313 actualPointerHeader = HEADERSTART + (0x1000 * startBackup%2); | |
1314 ef_write_block(data,0x1000,EF_HEADER, 0); | |
1315 } | |
1316 } | |
1317 releaseFrame(97,logCopyDataPtr); | |
1318 settingsGetPointer()->totalDiveCounter = startCount; | |
1319 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1320 */ |
38 | 1321 |
1322 // =============================================================================== | |
1323 // ext_flash_repair_dive_log | |
1324 /// @brief This function | |
1325 /// does set | |
1326 /// logFlashNextSampleStartAddress | |
1327 /// and | |
1328 /// lastDiveLogId | |
1329 /// | |
1330 void ext_flash_repair_dive_log(void) | |
1331 { | |
1332 uint8_t header1, header2; | |
1333 convert_Type dataStart; | |
1334 | |
1335 for(int id = 0; id < 255;id++) | |
1336 { | |
1337 actualAddress = HEADERSTART + (0x800 * id); | |
1338 ext_flash_read_block_start(); | |
1339 ext_flash_read_block(&header1, EF_HEADER); | |
1340 ext_flash_read_block(&header2, EF_HEADER); | |
1341 dataStart.u8bit.byteHigh = 0; | |
1342 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1343 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1344 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1345 ext_flash_read_block_stop(); | |
1346 if((header1 == 0xFA) && (header2 == 0xFA)) | |
1347 { | |
1348 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1349 ext_flash_read_block_start(); | |
1350 ext_flash_read_block(&header1, EF_HEADER); | |
1351 ext_flash_read_block(&header2, EF_HEADER); | |
1352 ext_flash_read_block_stop(); | |
1353 if((header1 != 0xFA) || (header2 != 0xFA)) | |
1354 { | |
1355 actualPointerSample = dataStart.u32bit; | |
1356 actualAddress = actualPointerSample; | |
1357 logbook_recover_brokenlog(id); | |
1358 SSettings *settings = settingsGetPointer(); | |
1359 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1360 } | |
1361 } | |
1362 } | |
1363 ext_flash_find_start(); | |
1364 } | |
1365 | |
1366 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1367 static void ext_flash_find_start(void) |
38 | 1368 { |
1369 uint8_t id; | |
1370 uint8_t header1, header2; | |
1371 convert_Type dataStart, dataEnd; | |
1372 | |
1373 for(id = 0; id < 255;id++) | |
1374 { | |
1375 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1376 ext_flash_read_block_start(); | |
1377 ext_flash_read_block(&header1, EF_HEADER); | |
1378 ext_flash_read_block(&header2, EF_HEADER); | |
1379 dataStart.u8bit.byteHigh = 0; | |
1380 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1381 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1382 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1383 ext_flash_read_block_stop(); | |
1384 if((header1 == 0xFF) && (header2 == 0xFF)) | |
1385 { | |
1386 break; | |
1387 } | |
1388 } | |
1389 id--; | |
1390 SSettings *settings = settingsGetPointer(); | |
1391 settings->lastDiveLogId = id; | |
1392 | |
1393 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1394 actualPointerHeader = actualAddress; | |
1395 | |
1396 ext_flash_read_block_start(); | |
1397 | |
1398 ext_flash_read_block(&header1, EF_HEADER); | |
1399 ext_flash_read_block(&header2, EF_HEADER); | |
1400 dataStart.u8bit.byteHigh = 0; | |
1401 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1402 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1403 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1404 dataEnd.u8bit.byteHigh = 0; | |
1405 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
1406 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
1407 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
1408 ext_flash_read_block_stop(); | |
1409 | |
1410 //Find free space | |
1411 if((header1 == 0xFA) && (header2 == 0xFA)) | |
1412 { | |
1413 uint8_t uiRead = 0; | |
1414 int countFF = 0; | |
1415 //End of last complete dive | |
1416 actualPointerSample = dataEnd.u32bit ; | |
1417 actualAddress = actualPointerSample; | |
1418 //Check if there are samples of dives with less than half a minute | |
1419 while(true) | |
1420 { | |
1421 ext_flash_read_block_start(); | |
1422 ext_flash_read_block(&uiRead, EF_SAMPLE); | |
1423 if(uiRead == 0xFF) | |
1424 countFF++; | |
1425 else | |
1426 countFF = 0; | |
1427 | |
1428 | |
1429 | |
1430 if(countFF == 10) | |
1431 { | |
1432 actualAddress -= 10; | |
1433 break; | |
1434 } | |
1435 | |
1436 //New page: clear | |
1437 if(ext_flash_erase_if_on_page_start()) | |
1438 break; | |
1439 } | |
1440 // Set new start address | |
1441 actualPointerSample = actualAddress; | |
1442 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1443 } | |
1444 else | |
1445 { | |
1446 settings->logFlashNextSampleStartAddress = SAMPLESTART; | |
1447 } | |
1448 } | |
1449 | |
1450 | |
1451 #endif | |
1452 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1453 static void ext_flash_disable_protection(void) |
38 | 1454 { |
1455 /* | |
1456 extFlashStatusBit8_Type status; | |
1457 | |
1458 status.uw = 0; | |
1459 | |
1460 wait_chip_not_busy(); | |
1461 write_spi(0x50,RELEASE); // EWSR | |
1462 write_spi(0x01,HOLDCS); // WRSR | |
1463 write_spi(status.uw,RELEASE); // new status | |
1464 */ | |
1465 } | |
1466 | |
1467 | |
1468 void ext_flash_disable_protection_for_logbook(void) | |
1469 { | |
1470 /* | |
1471 extFlashStatusBit8_Type status; | |
1472 | |
1473 status.uw = 0; | |
1474 status.ub.BlockProtect0 = 1; | |
1475 status.ub.BlockProtect1 = 0; | |
1476 status.ub.BlockProtect2 = 1; | |
1477 status.ub.BlockProtect3 = 0; // not set in OSTC3. Why? | |
1478 | |
1479 wait_chip_not_busy(); | |
1480 write_spi(0x50,RELEASE); // EWSR | |
1481 write_spi(0x01,HOLDCS); // WRSR | |
1482 write_spi(status.uw,RELEASE); // new status | |
1483 */ | |
1484 } | |
1485 | |
1486 | |
1487 void ext_flash_enable_protection(void) | |
1488 { | |
1489 /* | |
1490 extFlashStatusBit8_Type status; | |
1491 | |
1492 status.uw = 0; | |
1493 status.ub.BlockProtect0 = 1; | |
1494 status.ub.BlockProtect1 = 1; | |
1495 status.ub.BlockProtect2 = 1; | |
1496 status.ub.BlockProtect3 = 1; // not set in OSTC3. Why? | |
1497 | |
1498 wait_chip_not_busy(); | |
1499 write_spi(0x50,RELEASE); // EWSR | |
1500 write_spi(0x01,HOLDCS); // WRSR | |
1501 write_spi(status.uw,RELEASE); // new status | |
1502 */ | |
1503 } | |
1504 | |
1505 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1506 /*void ext_flash_erase_chip(void) |
38 | 1507 { |
1508 wait_chip_not_busy(); | |
1509 write_spi(0x06,RELEASE); | |
1510 write_spi(0x60,RELEASE); | |
1511 wait_chip_not_busy(); | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1512 }*/ |
38 | 1513 |
1514 void ext_flash_erase_firmware(void) | |
1515 { | |
1516 uint32_t size, blocks_64k; | |
1517 | |
1518 actualAddress = FWSTART; | |
1519 size = 1 + FWSTOP - FWSTART; | |
1520 blocks_64k = size / 0x10000; | |
1521 ef_erase_64K(blocks_64k); | |
1522 } | |
1523 | |
1524 void ext_flash_erase_firmware2(void) | |
1525 { | |
1526 uint32_t size, blocks_64k; | |
1527 | |
1528 actualAddress = FWSTART2; | |
1529 size = 1 + FWSTOP2 - FWSTART2; | |
1530 blocks_64k = size / 0x10000; | |
1531 ef_erase_64K(blocks_64k); | |
1532 } | |
1533 | |
1534 | |
1535 | |
1536 void ext_flash_erase_logbook(void) | |
1537 { | |
1538 uint32_t size, blocks_64k; | |
1539 | |
1540 ext_flash_disable_protection_for_logbook(); | |
1541 | |
1542 actualAddress = SAMPLESTART; | |
1543 size = 1 + SAMPLESTOP - SAMPLESTART; | |
1544 blocks_64k = size / 0x10000; | |
1545 ef_erase_64K(blocks_64k); | |
1546 | |
1547 actualAddress = HEADERSTART; | |
1548 size = 1 + HEADERSTOP - HEADERSTART; | |
1549 blocks_64k = size / 0x10000; | |
1550 ef_erase_64K(blocks_64k); | |
1551 | |
1552 ext_flash_enable_protection(); | |
1553 } | |
1554 | |
1555 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1556 static void ext_flash_erase4kB(void) |
38 | 1557 { |
1558 wait_chip_not_busy(); | |
1559 write_spi(0x06,RELEASE);/* WREN */ | |
1560 write_spi(0x20,HOLDCS);/* sector erase cmd */ | |
1561 write_address(RELEASE); | |
1562 } | |
1563 | |
282 | 1564 /* be careful - might not work with entire family and other products |
38 | 1565 * see page 14 of LOGBOOK_V3_S25FS-S_00-271247.pdf |
1566 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1567 static void ext_flash_erase32kB(void) |
38 | 1568 { |
1569 uint32_t actualAddress_backup; | |
1570 | |
1571 actualAddress_backup = actualAddress; | |
1572 actualAddress = 0; | |
1573 wait_chip_not_busy(); | |
1574 write_spi(0x06,RELEASE);/* WREN */ | |
1575 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1576 write_address(RELEASE); | |
1577 actualAddress = actualAddress_backup; | |
1578 } | |
1579 | |
1580 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1581 static void ext_flash_erase64kB(void) |
38 | 1582 { |
1583 wait_chip_not_busy(); | |
1584 write_spi(0x06,RELEASE);/* WREN */ | |
1585 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1586 write_address(RELEASE); | |
1587 } | |
1588 | |
1589 | |
1590 void ext_flash_read_block_start(void) | |
1591 { | |
1592 wait_chip_not_busy(); | |
1593 write_spi(0x03,HOLDCS); /* WREN */ | |
1594 write_address(HOLDCS); | |
1595 } | |
1596 | |
1597 /* 4KB, 32KB, 64 KB, not the upper 16 MB with 4 Byte address at the moment */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1598 static uint8_t ext_flash_erase_if_on_page_start(void) |
38 | 1599 { |
1600 if(actualAddress < 0x00008000) | |
1601 { | |
1602 /* 4K Byte is 0x1000 */ | |
1603 if((actualAddress & 0xFFF) == 0) | |
1604 { | |
1605 ext_flash_erase4kB(); | |
1606 return 1; | |
1607 } | |
1608 } | |
1609 else | |
1610 if(actualAddress < 0x00010000) | |
1611 { | |
1612 /* 32K Byte is only one page */ | |
1613 if(actualAddress == 0x00010000) | |
1614 { | |
1615 ext_flash_erase32kB(); | |
1616 return 1; | |
1617 } | |
1618 } | |
1619 else | |
1620 { | |
1621 /* 64K Byte is 0x10000 */ | |
1622 if((actualAddress & 0xFFFF) == 0) | |
1623 { | |
1624 ext_flash_erase64kB(); | |
1625 return 1; | |
1626 } | |
1627 } | |
1628 return 0; | |
1629 } | |
1630 | |
1631 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1632 static void ext_flash_read_block(uint8_t *getByte, uint8_t type) |
38 | 1633 { |
1634 *getByte = read_spi(HOLDCS);/* read data */ | |
1635 ext_flash_incf_address(type); | |
1636 } | |
1637 | |
1638 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1639 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type) |
38 | 1640 { |
1641 uint8_t *data; | |
1642 data = getByte; | |
1643 | |
1644 for(uint32_t i=0;i<size;i++) | |
1645 { | |
1646 data[i] = read_spi(HOLDCS);/* read data */ | |
1647 ext_flash_incf_address(type); | |
1648 } | |
1649 } | |
1650 | |
1651 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1652 static void ext_flash_read_block_stop(void) |
38 | 1653 { |
1654 chip_unselect(); | |
1655 } | |
1656 | |
1657 | |
1658 /* Private functions ---------------------------------------------------------*/ | |
1659 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1660 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) |
38 | 1661 { |
1662 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; | |
420 | 1663 uint32_t i=0; |
1664 | |
38 | 1665 if(!length) |
1666 return; | |
1667 | |
1668 uint32_t ringStart, ringStop; | |
1669 | |
1670 switch(type) | |
1671 { | |
1672 case EF_HEADER: | |
1673 actualAddress = actualPointerHeader; | |
1674 ringStart = HEADERSTART; | |
1675 ringStop = HEADERSTOP; | |
1676 break; | |
1677 case EF_SAMPLE: | |
1678 actualAddress = actualPointerSample; | |
1679 ringStart = SAMPLESTART; | |
1680 ringStop = SAMPLESTOP; | |
1681 break; | |
1682 case EF_DEVICEDATA: | |
1683 actualAddress = actualPointerDevicedata; | |
1684 ringStart = DDSTART; | |
1685 ringStop = DDSTOP; | |
1686 break; | |
1687 case EF_VPMDATA: | |
1688 actualAddress = actualPointerVPM; | |
1689 ringStart = VPMSTART; | |
1690 ringStop = VPMSTOP; | |
1691 break; | |
1692 case EF_SETTINGS: | |
1693 actualAddress = actualPointerSettings; | |
1694 ringStart = SETTINGSSTART; | |
1695 ringStop = SETTINGSSTOP; | |
1696 break; | |
1697 case EF_FIRMWARE: | |
1698 actualAddress = actualPointerFirmware; | |
1699 ringStart = FWSTART; | |
1700 ringStop = FWSTOP; | |
1701 break; | |
1702 case EF_FIRMWARE2: | |
1703 actualAddress = actualPointerFirmware2; | |
1704 ringStart = FWSTART2; | |
1705 ringStop = FWSTOP2; | |
1706 break; | |
1707 default: | |
1708 ringStart = FLASHSTART; | |
1709 ringStop = FLASHSTOP; | |
1710 break; | |
1711 } | |
1712 /* safety */ | |
1713 if(actualAddress < ringStart) | |
1714 actualAddress = ringStart; | |
1715 | |
1716 if(do_not_erase == 0) | |
1717 ext_flash_erase_if_on_page_start(); | |
1718 | |
420 | 1719 while( i<length) |
38 | 1720 { |
1721 ef_hw_rough_delay_us(5); | |
1722 wait_chip_not_busy(); | |
1723 write_spi(0x06,RELEASE); /* WREN */ | |
1724 write_spi(0x02,HOLDCS); /* write cmd */ | |
1725 write_address(HOLDCS); | |
1726 | |
1727 remaining_length = length - i; | |
420 | 1728 remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1; |
38 | 1729 remaining_space_to_ring_end = ringStop - actualAddress; |
1730 | |
420 | 1731 if(remaining_length >= 256) |
1732 { | |
1733 remaining_length = 255; /* up to 256 bytes may be written in one burst. Last byte is written with release */ | |
1734 } | |
1735 else | |
38 | 1736 { |
420 | 1737 remaining_length--; /* last byte needed for release */ |
1738 } | |
1739 if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */ | |
1740 { | |
1741 remaining_length = remaining_page_size - 1; | |
1742 } | |
1743 if( (remaining_space_to_ring_end >= 256)) | |
1744 { | |
1745 for(int j=0; j<remaining_length; j++) | |
38 | 1746 { |
1747 write_spi(sendByte[i],HOLDCS);/* write data */ | |
1748 actualAddress++; | |
1749 i++; | |
1750 } | |
1751 } | |
1752 /* byte with RELEASE */ | |
1753 write_spi(sendByte[i],RELEASE);/* write data */ | |
1754 actualAddress++; | |
420 | 1755 i++; |
1756 | |
38 | 1757 if(actualAddress > ringStop) |
1758 actualAddress = ringStart; | |
420 | 1759 |
38 | 1760 if(do_not_erase == 0) |
1761 ext_flash_erase_if_on_page_start(); | |
1762 } | |
1763 switch(type) | |
1764 { | |
1765 case EF_HEADER: | |
1766 actualPointerHeader = actualAddress; | |
1767 break; | |
1768 case EF_SAMPLE: | |
1769 actualPointerSample = actualAddress; | |
1770 break; | |
1771 case EF_DEVICEDATA: | |
1772 actualPointerDevicedata = actualAddress; | |
1773 break; | |
1774 case EF_VPMDATA: | |
1775 actualPointerVPM = actualAddress; | |
1776 break; | |
1777 case EF_SETTINGS: | |
1778 actualPointerSettings = actualAddress; | |
1779 break; | |
1780 case EF_FIRMWARE: | |
1781 actualPointerFirmware = actualAddress; | |
1782 break; | |
1783 case EF_FIRMWARE2: | |
1784 actualPointerFirmware2 = actualAddress; | |
1785 break; | |
1786 default: | |
1787 break; | |
1788 } | |
1789 } | |
1790 | |
1791 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1792 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length) |
38 | 1793 { |
1794 if((pointer & 0xFFF) == 0) | |
1795 return 1; | |
1796 | |
1797 uint32_t backup = actualAddress; | |
1798 uint8_t data; | |
1799 uint32_t size_to_page_end; | |
1800 | |
1801 size_to_page_end = 0x1000 - (pointer & 0xFFF); | |
1802 if(length > size_to_page_end) | |
1803 length = size_to_page_end; | |
1804 | |
1805 actualAddress = pointer; | |
1806 ext_flash_read_block_start(); | |
1807 | |
1808 for(uint16_t i = 0; i<length; i++) | |
1809 { | |
1810 ext_flash_read_block(&data, 255); // 255 = ENTIRE FLASH | |
1811 if(data != 0xFF) | |
1812 { | |
1813 ext_flash_read_block_stop(); | |
1814 actualAddress = backup; | |
1815 return 0; | |
1816 } | |
1817 } | |
1818 ext_flash_read_block_stop(); | |
1819 actualAddress = backup; | |
1820 return 1; | |
1821 } | |
1822 | |
1823 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1824 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type) |
38 | 1825 { |
1826 uint32_t ringStart, ringStop; | |
1827 | |
1828 switch(type) | |
1829 { | |
1830 case EF_HEADER: | |
1831 ringStart = HEADERSTART; | |
1832 ringStop = HEADERSTOP; | |
1833 break; | |
1834 case EF_SAMPLE: | |
1835 ringStart = SAMPLESTART; | |
1836 ringStop = SAMPLESTOP; | |
1837 break; | |
1838 case EF_DEVICEDATA: | |
1839 ringStart = DDSTART; | |
1840 ringStop = DDSTOP; | |
1841 break; | |
1842 case EF_VPMDATA: | |
1843 ringStart = VPMSTART; | |
1844 ringStop = VPMSTOP; | |
1845 break; | |
1846 case EF_SETTINGS: | |
1847 ringStart = SETTINGSSTART; | |
1848 ringStop = SETTINGSSTOP; | |
1849 break; | |
1850 default: | |
1851 ringStart = FLASHSTART; | |
1852 ringStop = FLASHSTOP; | |
1853 break; | |
1854 } | |
1855 | |
1856 *pointer = (*pointer & 0xFFF) + 0x1000; | |
1857 | |
1858 if((*pointer < ringStart) || (*pointer >= ringStop)) | |
1859 *pointer = ringStart; | |
1860 } | |
1861 | |
1862 | |
1863 static void ef_erase_64K(uint32_t blocks) | |
1864 { | |
1865 for(uint32_t i = 0; i < blocks; i++) | |
1866 { | |
1867 wait_chip_not_busy(); | |
1868 write_spi(0x06,RELEASE);/* WREN */ | |
1869 write_spi(0xD8,HOLDCS);/* 64k erase cmd */ | |
1870 write_address(RELEASE); | |
1871 actualAddress += 0x10000; | |
1872 HAL_Delay(25); | |
1873 } | |
1874 } | |
1875 | |
1876 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1877 static void chip_unselect(void) |
38 | 1878 { |
1879 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_SET); // chip select | |
1880 } | |
1881 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1882 static void chip_select(void) |
38 | 1883 { |
1884 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select | |
1885 } | |
1886 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1887 static void error_led_on(void) |
38 | 1888 { |
1889 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); | |
1890 } | |
1891 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1892 static void error_led_off(void) |
38 | 1893 { |
1894 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); | |
1895 } | |
1896 | |
1897 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1898 static uint8_t read_spi(uint8_t unselect_CS_afterwards) |
38 | 1899 { |
1900 uint8_t byte; | |
1901 | |
1902 chip_select(); | |
1903 | |
1904 if(HAL_SPI_Receive(&hspiDisplay, &byte, 1, 10000) != HAL_OK) | |
1905 Error_Handler_extflash(); | |
1906 | |
1907 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
1908 { | |
1909 } | |
1910 if(unselect_CS_afterwards) | |
1911 chip_unselect(); | |
1912 | |
1913 return byte; | |
1914 } | |
1915 | |
1916 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1917 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards) |
38 | 1918 { |
1919 chip_select(); | |
1920 | |
1921 if(HAL_SPI_Transmit(&hspiDisplay, &data, 1, 10000) != HAL_OK) | |
1922 Error_Handler_extflash(); | |
1923 | |
1924 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
1925 { | |
1926 } | |
1927 if(unselect_CS_afterwards) | |
1928 chip_unselect(); | |
1929 } | |
1930 | |
1931 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1932 static void write_address(uint8_t unselect_CS_afterwards) |
38 | 1933 { |
1934 uint8_t hi, med ,lo; | |
1935 | |
1936 hi = (actualAddress >> 16) & 0xFF; | |
1937 med = (actualAddress >> 8) & 0xFF; | |
1938 lo = actualAddress & 0xFF; | |
1939 | |
1940 write_spi(hi, HOLDCS); | |
1941 write_spi(med, HOLDCS); | |
1942 write_spi(lo, unselect_CS_afterwards); | |
1943 } | |
1944 | |
1945 | |
1946 static void wait_chip_not_busy(void) | |
1947 { | |
1948 uint8_t status; | |
1949 | |
1950 chip_unselect(); | |
1951 | |
1952 write_spi(0x05,HOLDCS); /* RDSR */ | |
1953 status = read_spi(HOLDCS);/* read status */ | |
1954 while(status & 0x01) | |
1955 { | |
1956 HAL_Delay(1); | |
1957 status = read_spi(HOLDCS);/* read status */ | |
1958 } | |
1959 chip_unselect(); | |
1960 } | |
1961 | |
1962 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1963 static void ext_flash_incf_address(uint8_t type) |
38 | 1964 { |
1965 uint32_t ringStart, ringStop; | |
1966 | |
1967 actualAddress += 1; | |
1968 | |
1969 switch(type) | |
1970 { | |
1971 case EF_HEADER: | |
1972 ringStart = HEADERSTART; | |
1973 ringStop = HEADERSTOP; | |
1974 break; | |
1975 case EF_SAMPLE: | |
1976 ringStart = SAMPLESTART; | |
1977 ringStop = SAMPLESTOP; | |
1978 break; | |
1979 case EF_DEVICEDATA: | |
1980 ringStart = DDSTART; | |
1981 ringStop = DDSTOP; | |
1982 break; | |
1983 case EF_VPMDATA: | |
1984 ringStart = VPMSTART; | |
1985 ringStop = VPMSTOP; | |
1986 break; | |
1987 case EF_SETTINGS: | |
1988 ringStart = SETTINGSSTART; | |
1989 ringStop = SETTINGSSTOP; | |
1990 break; | |
1991 case EF_FIRMWARE: | |
1992 ringStart = FWSTART; | |
1993 ringStop = FWSTOP; | |
1994 break; | |
1995 case EF_FIRMWARE2: | |
1996 ringStart = FWSTART2; | |
1997 ringStop = FWSTOP2; | |
1998 break; | |
1999 default: | |
2000 ringStart = FLASHSTART; | |
2001 ringStop = FLASHSTOP; | |
2002 break; | |
2003 } | |
2004 | |
2005 if((actualAddress < ringStart) || (actualAddress > ringStop)) | |
2006 actualAddress = ringStart; | |
2007 } | |
2008 | |
2009 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2010 static void ext_flash_decf_address_ring(uint8_t type) |
38 | 2011 { |
2012 uint32_t ringStart, ringStop; | |
2013 | |
2014 switch(type) | |
2015 { | |
2016 case EF_HEADER: | |
2017 ringStart = HEADERSTART; | |
2018 ringStop = HEADERSTOP; | |
2019 break; | |
2020 case EF_SAMPLE: | |
2021 ringStart = SAMPLESTART; | |
2022 ringStop = SAMPLESTOP; | |
2023 break; | |
2024 case EF_DEVICEDATA: | |
2025 ringStart = DDSTART; | |
2026 ringStop = DDSTOP; | |
2027 break; | |
2028 case EF_VPMDATA: | |
2029 ringStart = VPMSTART; | |
2030 ringStop = VPMSTOP; | |
2031 break; | |
2032 case EF_SETTINGS: | |
2033 ringStart = SETTINGSSTART; | |
2034 ringStop = SETTINGSSTOP; | |
2035 break; | |
2036 case EF_FIRMWARE: | |
2037 ringStart = FWSTART; | |
2038 ringStop = FWSTOP; | |
2039 break; | |
2040 case EF_FIRMWARE2: | |
2041 ringStart = FWSTART2; | |
2042 ringStop = FWSTOP2; | |
2043 break; | |
2044 default: | |
2045 ringStart = FLASHSTART; | |
2046 ringStop = FLASHSTOP; | |
2047 break; | |
2048 } | |
2049 | |
2050 if((actualAddress <= ringStart) || (actualAddress > ringStop)) | |
2051 actualAddress = ringStop; | |
2052 else | |
2053 actualAddress -= 1; | |
2054 } | |
2055 | |
2056 | |
2057 static void ef_hw_rough_delay_us(uint32_t delayUs) | |
2058 { | |
2059 if(!delayUs) | |
2060 return; | |
2061 delayUs*= 12; | |
2062 while(delayUs--); | |
2063 return; | |
2064 } | |
2065 | |
2066 static void Error_Handler_extflash(void) | |
2067 { | |
2068 while(1) | |
2069 { | |
2070 } | |
2071 } | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2072 /* |
38 | 2073 uint8_t ext_flash_erase_firmware_if_not_empty(void) |
2074 { | |
2075 const uint8_t TESTSIZE_FW = 4; | |
2076 | |
2077 uint8_t data[TESTSIZE_FW]; | |
2078 uint8_t notEmpty = 0; | |
2079 | |
2080 actualAddress = FWSTART; | |
2081 ext_flash_read_block_start(); | |
2082 for(int i = 0; i < TESTSIZE_FW; i++) | |
2083 { | |
2084 ext_flash_read_block(&data[i], EF_FIRMWARE); | |
2085 if(data[i] != 0xFF) | |
2086 notEmpty = 1; | |
2087 } | |
2088 ext_flash_read_block_stop(); | |
2089 | |
2090 if(notEmpty) | |
2091 { | |
2092 ext_flash_erase_firmware(); | |
2093 return 1; | |
2094 } | |
2095 else | |
2096 return 0; | |
2097 } | |
2098 | |
2099 uint8_t ext_flash_erase_firmware2_if_not_empty(void) | |
2100 { | |
2101 const uint8_t TESTSIZE_FW = 4; | |
2102 | |
2103 uint8_t data[TESTSIZE_FW]; | |
2104 uint8_t notEmpty = 0; | |
2105 | |
2106 actualAddress = FWSTART2; | |
2107 ext_flash_read_block_start(); | |
2108 for(int i = 0; i < TESTSIZE_FW; i++) | |
2109 { | |
2110 ext_flash_read_block(&data[i], EF_FIRMWARE2); | |
2111 if(data[i] != 0xFF) | |
2112 notEmpty = 1; | |
2113 } | |
2114 ext_flash_read_block_stop(); | |
2115 | |
2116 if(notEmpty) | |
2117 { | |
2118 ext_flash_erase_firmware2(); | |
2119 return 1; | |
2120 } | |
2121 else | |
2122 return 0; | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2123 }*/ |