Mercurial > public > ostc4
annotate Discovery/Src/externLogbookFlash.c @ 751:70e9c83ecf22
resolv merge
author | Ideenmodellierer |
---|---|
date | Mon, 13 Mar 2023 22:23:00 +0100 |
parents | 2702bfa7b177 |
children | bc6c90e20d9e |
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; |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
119 static uint32_t preparedPageAddress = 0; |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
120 static uint32_t closeSectorAddress = 0; |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
121 static uint32_t entryPoint = 0; |
38 | 122 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
123 static uint32_t actualPointerHeader = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
124 static uint32_t actualPointerSample = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
125 static uint32_t LengthLeftSampleRead = 0; |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
126 static uint32_t actualPointerDevicedata = DDSTART; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
127 static uint32_t actualPointerDevicedata_Read = DDSTART; |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
128 static uint32_t actualPointerVPM = 0; |
427 | 129 static uint32_t actualPointerSettings = SETTINGSSTART; |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
130 static uint32_t actualPointerFirmware = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
131 static uint32_t actualPointerFirmware2 = 0; |
38 | 132 |
133 /* Private function prototypes -----------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
134 static void chip_unselect(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
135 static void chip_select(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
136 static void error_led_on(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
137 static void error_led_off(void); |
38 | 138 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
139 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
|
140 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
|
141 static void write_address(uint8_t unselect_CS_afterwards); |
38 | 142 static void Error_Handler_extflash(void); |
143 static void wait_chip_not_busy(void); | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
144 static void ext_flash_incf_address(uint8_t type); |
38 | 145 //void ext_flash_incf_address_ring(void); |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
146 static void ext_flash_decf_address_ring(uint8_t type); |
38 | 147 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
148 static void ext_flash_erase4kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
149 static void ext_flash_erase32kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
150 static void ext_flash_erase64kB(void); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
151 static uint8_t ext_flash_erase_if_on_page_start(void); |
38 | 152 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
153 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase); |
38 | 154 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
155 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
|
156 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
|
157 static void ext_flash_read_block_stop(void); |
38 | 158 |
159 static void ef_hw_rough_delay_us(uint32_t delayUs); | |
160 static void ef_erase_64K(uint32_t blocks); | |
161 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
162 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
|
163 |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
164 static void ext_flash_disable_protection(void); |
38 | 165 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
166 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
|
167 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
|
168 static void ext_flash_find_start(void); |
38 | 169 |
170 | |
171 /* Exported functions --------------------------------------------------------*/ | |
172 | |
173 void ext_flash_write_firmware(uint8_t *pSample1, uint32_t length1)//, uint8_t *pSample2, uint32_t length2) | |
174 { | |
175 general32to8_Type lengthTransform; | |
176 | |
177 lengthTransform.u32 = length1; | |
178 | |
179 actualPointerFirmware = FWSTART; | |
180 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE, 1); | |
181 ef_write_block(pSample1,length1, EF_FIRMWARE, 1); | |
182 | |
183 // if(length2) | |
184 // ef_write_block(pSample2,length2, EF_FIRMWARE, 1); | |
185 } | |
186 | |
187 uint8_t ext_flash_read_firmware_version(char *text) | |
188 { | |
189 uint32_t backup = actualAddress; | |
190 uint8_t buffer[4]; | |
191 | |
192 // + 4 for length data, see ext_flash_write_firmware | |
193 actualAddress = FWSTART + 4 + 0x10000; | |
194 ext_flash_read_block_start(); | |
195 ext_flash_read_block(&buffer[0], EF_FIRMWARE); | |
196 ext_flash_read_block(&buffer[1], EF_FIRMWARE); | |
197 ext_flash_read_block(&buffer[2], EF_FIRMWARE); | |
198 ext_flash_read_block(&buffer[3], EF_FIRMWARE); | |
199 | |
200 ext_flash_read_block_stop(); | |
201 actualAddress = backup; | |
202 | |
203 uint8_t ptr = 0; | |
204 text[ptr++] = 'V'; | |
205 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[0] & 0x3F); | |
206 text[ptr++] = '.'; | |
207 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[1] & 0x3F); | |
208 text[ptr++] = '.'; | |
209 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[2] & 0x3F); | |
210 text[ptr++] = ' '; | |
211 if(buffer[3]) | |
212 { | |
213 text[ptr++] = 'b'; | |
214 text[ptr++] = 'e'; | |
215 text[ptr++] = 't'; | |
216 text[ptr++] = 'a'; | |
217 text[ptr++] = ' '; | |
218 } | |
219 return ptr; | |
220 } | |
221 | |
222 | |
223 uint32_t ext_flash_read_firmware(uint8_t *pSample1, uint32_t max_length, uint8_t *magicByte) | |
224 { | |
225 uint32_t backup = actualAddress; | |
226 general32to8_Type lengthTransform; | |
227 | |
228 actualAddress = FWSTART; | |
229 ext_flash_read_block_start(); | |
230 | |
231 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE); | |
232 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE); | |
233 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE); | |
234 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE); | |
235 | |
236 | |
237 if(lengthTransform.u32 == 0xFFFFFFFF) | |
238 { | |
239 lengthTransform.u32 = 0xFFFFFFFF; | |
240 } | |
241 else | |
242 if(lengthTransform.u32 > max_length) | |
243 { | |
244 lengthTransform.u32 = 0xFF000000; | |
245 } | |
246 else | |
247 { | |
248 for(uint32_t i = 0; i<lengthTransform.u32; i++) | |
249 { | |
250 ext_flash_read_block(&pSample1[i], EF_FIRMWARE); | |
251 } | |
252 | |
253 } | |
254 | |
255 ext_flash_read_block_stop(); | |
256 | |
257 if(magicByte) | |
258 { | |
259 *magicByte = pSample1[0x10000 + 0x3E]; // 0x3E == 62 | |
260 } | |
261 | |
262 actualAddress = backup; | |
263 return lengthTransform.u32; | |
264 } | |
265 | |
266 | |
267 void ext_flash_write_firmware2(uint32_t offset, uint8_t *pSample1, uint32_t length1, uint8_t *pSample2, uint32_t length2) | |
268 { | |
269 general32to8_Type lengthTransform, offsetTransform; | |
270 | |
271 lengthTransform.u32 = length1 + length2; | |
272 offsetTransform.u32 = offset; | |
273 | |
274 actualPointerFirmware2 = FWSTART2; | |
275 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE2, 1); | |
276 ef_write_block(offsetTransform.u8,4, EF_FIRMWARE2, 1); | |
277 ef_write_block(pSample1,length1, EF_FIRMWARE2, 1); | |
278 if(length2) | |
279 ef_write_block(pSample2,length2, EF_FIRMWARE2, 1); | |
280 } | |
281 | |
282 | |
283 uint32_t ext_flash_read_firmware2(uint32_t *offset, uint8_t *pSample1, uint32_t max_length1, uint8_t *pSample2, uint32_t max_length2) | |
284 { | |
285 uint32_t backup = actualAddress; | |
286 uint32_t length1, length2; | |
287 general32to8_Type lengthTransform, offsetTransform; | |
288 | |
289 actualAddress = FWSTART2; | |
290 ext_flash_read_block_start(); | |
291 | |
292 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE2); | |
293 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE2); | |
294 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE2); | |
295 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE2); | |
296 | |
297 ext_flash_read_block(&offsetTransform.u8[0], EF_FIRMWARE2); | |
298 ext_flash_read_block(&offsetTransform.u8[1], EF_FIRMWARE2); | |
299 ext_flash_read_block(&offsetTransform.u8[2], EF_FIRMWARE2); | |
300 ext_flash_read_block(&offsetTransform.u8[3], EF_FIRMWARE2); | |
301 | |
302 *offset = offsetTransform.u32; | |
303 | |
304 if(lengthTransform.u32 == 0xFFFFFFFF) | |
305 { | |
306 lengthTransform.u32 = 0xFFFFFFFF; | |
307 } | |
308 else | |
309 if(lengthTransform.u32 > max_length1 + max_length2) | |
310 { | |
311 lengthTransform.u32 = 0xFF000000; | |
312 } | |
313 else | |
314 { | |
315 if(lengthTransform.u32 < max_length1) | |
316 { | |
317 length1 = lengthTransform.u32; | |
318 length2 = 0; | |
319 } | |
320 else | |
321 { | |
322 length1 = max_length1; | |
323 length2 = lengthTransform.u32 - max_length1; | |
324 } | |
325 | |
326 if(pSample1) | |
327 { | |
328 for(uint32_t i = 0; i<length1; i++) | |
329 { | |
330 ext_flash_read_block(&pSample1[i], EF_FIRMWARE2); | |
331 } | |
332 if(pSample2) | |
333 { | |
334 for(uint32_t i = 0; i<length2; i++) | |
335 { | |
336 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2); | |
337 } | |
338 } | |
339 } | |
340 else if(pSample2) | |
341 { | |
342 actualAddress += length1; | |
343 for(uint32_t i = 0; i<length2; i++) | |
344 { | |
345 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2); | |
346 } | |
347 } | |
348 } | |
349 ext_flash_read_block_stop(); | |
350 actualAddress = backup; | |
351 return lengthTransform.u32; | |
352 } | |
353 | |
354 | |
355 void ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(uint8_t *buffer) | |
356 { | |
357 SDeviceLine data[16]; | |
358 uint8_t tempLengthIngnore; | |
359 uint16_t count; | |
360 uint8_t transfer; | |
361 | |
362 RTC_DateTypeDef Sdate; | |
363 RTC_TimeTypeDef Stime; | |
364 | |
365 actualAddress = DDSTART; | |
366 | |
367 ext_flash_read_block_start(); | |
368 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA); | |
369 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA); | |
370 | |
371 ext_flash_read_block_multi((uint8_t *)data,16*3*4, EF_DEVICEDATA); | |
372 ext_flash_read_block_stop(); | |
373 | |
374 count = 0; | |
375 for(int i=0;i<16;i++) | |
376 { | |
377 transfer = (data[i].value_int32 >> 24) & 0xFF; | |
378 buffer[count++] = transfer; | |
379 transfer = (data[i].value_int32 >> 16) & 0xFF; | |
380 buffer[count++] = transfer; | |
381 transfer = (data[i].value_int32 >> 8) & 0xFF; | |
382 buffer[count++] = transfer; | |
383 transfer = (data[i].value_int32) & 0xFF; | |
384 buffer[count++] = transfer; | |
385 | |
386 translateDate(data[i].date_rtc_dr, &Sdate); | |
387 translateTime(data[i].time_rtc_tr, &Stime); | |
388 buffer[count++] = Sdate.Year; | |
389 buffer[count++] = Sdate.Month; | |
390 buffer[count++] = Sdate.Date; | |
391 buffer[count++] = Stime.Hours; | |
392 } | |
393 } | |
394 | |
395 | |
396 #ifndef BOOTLOADER_STANDALONE | |
397 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
398 void ext_flash_write_devicedata(uint8_t resetRing) |
38 | 399 { |
400 uint8_t *pData; | |
401 const uint16_t length = sizeof(SDevice); | |
402 uint8_t length_lo, length_hi; | |
403 uint8_t dataLength[2] = { 0 }; | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
404 uint32_t tmpBlockStart; |
38 | 405 |
406 ext_flash_disable_protection(); | |
407 | |
408 pData = (uint8_t *)stateDeviceGetPointer(); | |
409 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
410 /* 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
|
411 if((resetRing) || ((actualPointerDevicedata + length) >= DDSTOP)) |
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 actualPointerDevicedata = DDSTART; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
414 } |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
415 tmpBlockStart = actualPointerDevicedata; |
38 | 416 |
417 length_lo = (uint8_t)(length & 0xFF); | |
418 length_hi = (uint8_t)(length >> 8); | |
419 dataLength[0] = length_lo; | |
420 dataLength[1] = length_hi; | |
421 | |
422 ef_write_block(dataLength,2, EF_DEVICEDATA, 0); | |
423 ef_write_block(pData,length, EF_DEVICEDATA, 0); | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
424 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
425 actualPointerDevicedata_Read = tmpBlockStart; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
426 |
38 | 427 } |
428 | |
429 | |
430 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length) | |
431 { | |
432 uint16_t length; | |
433 uint8_t length_lo, length_hi; | |
434 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
435 actualAddress = actualPointerDevicedata_Read; |
38 | 436 |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
437 length = 0; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
438 length_lo = 0; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
439 length_hi = 0; |
38 | 440 ext_flash_read_block_start(); |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
441 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
442 |
38 | 443 ext_flash_read_block(&length_lo, EF_DEVICEDATA); |
444 ext_flash_read_block(&length_hi, EF_DEVICEDATA); | |
445 | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
446 while ((length_lo != 0xFF) && (length_hi != 0xFF)) |
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 length = (length_hi * 256) + length_lo; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
449 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
450 if(length > max_length) |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
451 return 0; |
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_multi(buffer,length,EF_DEVICEDATA); |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
454 |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
455 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
|
456 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
|
457 } |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
458 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
|
459 ext_flash_decf_address_ring(EF_DEVICEDATA); |
38 | 460 ext_flash_read_block_stop(); |
421
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 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
|
463 { |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
464 actualPointerDevicedata = actualAddress; |
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
420
diff
changeset
|
465 } |
38 | 466 return length; |
467 } | |
468 | |
469 | |
470 void ext_flash_write_vpm(SVpm *vpmInput) | |
471 { | |
472 uint8_t *pData; | |
473 const uint16_t length = sizeof(SVpm); | |
474 | |
475 uint8_t length_lo, length_hi; | |
476 uint8_t dataLength[2] = { 0 }; | |
477 | |
478 pData = (uint8_t *)vpmInput; | |
479 | |
480 actualPointerVPM = VPMSTART; | |
481 | |
482 length_lo = (uint8_t)(length & 0xFF); | |
483 length_hi = (uint8_t)(length >> 8); | |
484 dataLength[0] = length_lo; | |
485 dataLength[1] = length_hi; | |
486 | |
487 ef_write_block(dataLength,2, EF_VPMDATA, 0); | |
488 ef_write_block(pData,length, EF_VPMDATA, 0); | |
489 } | |
490 | |
491 | |
492 int ext_flash_read_vpm(SVpm *vpmOutput) | |
493 { | |
494 uint8_t *pData; | |
495 const uint16_t length = sizeof(SVpm); | |
496 uint8_t length_lo, length_hi; | |
497 int output; | |
498 | |
499 actualAddress = VPMSTART; | |
500 | |
501 ext_flash_read_block_start(); | |
502 ext_flash_read_block(&length_lo, EF_VPMDATA); | |
503 ext_flash_read_block(&length_hi, EF_VPMDATA); | |
504 if((length_lo == (uint8_t)(length & 0xFF)) | |
505 &&(length_hi == (uint8_t)(length >> 8))) | |
506 { | |
507 pData = (uint8_t *)vpmOutput; | |
508 for(uint16_t i = 0; i < length; i++) | |
509 ext_flash_read_block(&pData[i], EF_VPMDATA); | |
510 output = length; | |
511 } | |
512 else | |
513 output = 0; | |
514 | |
515 ext_flash_read_block_stop(); | |
516 return output; | |
517 } | |
518 | |
519 #ifdef DEMOMODE | |
520 void ext_flash_write_settings(void) | |
521 { | |
522 return; | |
523 } | |
524 #else | |
427 | 525 void ext_flash_write_settings(uint8_t resetRing) |
38 | 526 { |
527 uint8_t *pData; | |
528 const uint16_t length = sizeof(SSettings); | |
529 uint8_t length_lo, length_hi; | |
530 uint8_t dataLength[2] = { 0 }; | |
531 | |
532 ext_flash_disable_protection(); | |
533 | |
534 if(stateRealGetPointer()->lastKnownBatteryPercentage) | |
535 { | |
536 settingsGetPointer()->lastKnownBatteryPercentage = stateRealGetPointer()->lastKnownBatteryPercentage; | |
537 } | |
538 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat; | |
539 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat; | |
540 | |
541 pData = (uint8_t *)settingsGetPointer(); | |
542 | |
427 | 543 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */ |
544 if((resetRing) || ((actualPointerSettings + length) >= SETTINGSSTOP)) | |
545 { | |
546 actualPointerSettings = SETTINGSSTART; | |
547 } | |
38 | 548 |
549 length_lo = (uint8_t)(length & 0xFF); | |
550 length_hi = (uint8_t)(length >> 8); | |
551 dataLength[0] = length_lo; | |
552 dataLength[1] = length_hi; | |
553 | |
554 ef_write_block(dataLength,2, EF_SETTINGS, 0); | |
555 ef_write_block(pData,length, EF_SETTINGS, 0); | |
556 // ext_flash_enable_protection(); | |
557 } | |
558 #endif | |
559 | |
560 | |
561 /* CHANGES 150929 hw | |
562 * this now allows to read old settings too | |
563 * but make sure that everything is fixed in | |
564 * set_new_settings_missing_in_ext_flash | |
565 * new settings should be fine as they are added | |
566 * and loaded before calling this function | |
567 */ | |
568 uint8_t ext_flash_read_settings(void) | |
569 { | |
570 uint8_t returnValue = HAL_BUSY; | |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
571 uint8_t exit = 0; |
38 | 572 uint8_t *pData; |
573 const uint16_t lengthStandardNow = sizeof(SSettings); | |
574 uint8_t length_lo, length_hi; | |
575 uint16_t lengthOnEEPROM; | |
576 uint32_t header; | |
577 SSettings *pSettings = settingsGetPointer(); | |
578 | |
579 actualAddress = SETTINGSSTART; | |
580 | |
581 ext_flash_read_block_start(); | |
582 ext_flash_read_block(&length_lo, EF_SETTINGS); | |
583 ext_flash_read_block(&length_hi, EF_SETTINGS); | |
584 | |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
585 while ((length_lo != 0xFF) && (length_hi != 0xFF) && (exit == 0)) /* get the latest stored setting block */ |
38 | 586 { |
427 | 587 lengthOnEEPROM = length_hi * 256; |
588 lengthOnEEPROM += length_lo; | |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
589 if(lengthOnEEPROM <= lengthStandardNow) /* EEPROM Header size equal or smaller => settings constant or upgraded */ |
38 | 590 { |
427 | 591 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
592 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) /* check to allow update of header */ |
427 | 593 { |
594 returnValue = HAL_OK; | |
595 pSettings->header = header; | |
596 pData = (uint8_t *)pSettings + 4; /* header */ | |
597 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++) | |
598 ext_flash_read_block(&pData[i], EF_SETTINGS); | |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
599 if(header != pSettings->header) /* setting layout changed => no additional setting sets expected */ |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
600 { |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
601 exit = 1; |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
602 } |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
603 } |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
604 else |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
605 { |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
606 returnValue = HAL_ERROR; |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
607 exit = 1; |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
608 } |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
609 } |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
610 else /* size of settings decreased => possible downgrade of firmware */ |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
611 { |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
612 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
613 |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
614 if(header > 0xFFFF0014) /* verify that new (old) header should be compatible (only less bytes, no change in layout) */ |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
615 { |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
616 returnValue = HAL_OK; |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
617 pSettings->header = header; |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
618 pData = (uint8_t *)pSettings + 4; /* header */ |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
619 for(uint16_t i = 0; i < (lengthStandardNow-4); i++) /* only read the data fitting into the structure */ |
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
620 ext_flash_read_block(&pData[i], EF_SETTINGS); |
427 | 621 } |
622 else | |
623 { | |
624 returnValue = HAL_ERROR; | |
625 } | |
538
b1eee27cd02b
BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents:
466
diff
changeset
|
626 exit = 1; |
38 | 627 } |
427 | 628 ext_flash_read_block(&length_lo, EF_SETTINGS); |
629 ext_flash_read_block(&length_hi, EF_SETTINGS); | |
630 } | |
631 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */ | |
632 ext_flash_decf_address_ring(EF_SETTINGS); | |
633 ext_flash_read_block_stop(); | |
634 | |
635 if(actualAddress > actualPointerSettings) /* the write pointer has not yet been set up probably */ | |
636 { | |
637 actualPointerSettings = actualAddress; | |
38 | 638 } |
639 ext_flash_read_block_stop(); | |
640 return returnValue; | |
641 } | |
642 | |
643 | |
644 | |
645 | |
646 /* ext_flash_start_new_dive_log_and_set_actualPointerSample | |
647 * prepares the write sample pointer | |
648 * to be used by ext_flash_write_sample() | |
649 * to be set in the * pHeaderPreDive | |
650 * for write with ext_flash_create_new_dive_log() and ext_flash_close_new_dive_log() | |
651 */ | |
652 void ext_flash_start_new_dive_log_and_set_actualPointerSample(uint8_t *pHeaderPreDive) | |
653 { | |
654 convert_Type data; | |
655 SSettings *settings = settingsGetPointer(); | |
656 | |
657 /* new 5. Jan. 2015 */ | |
658 actualPointerSample = settings->logFlashNextSampleStartAddress; | |
659 | |
660 if(!ext_flash_test_remaining_space_of_page_empty(actualPointerSample, 4)) | |
661 ext_flash_set_to_begin_of_next_page(&actualPointerSample, EF_SAMPLE); | |
662 | |
663 if((actualPointerSample < SAMPLESTART) || (actualPointerSample > SAMPLESTOP)) | |
664 actualPointerSample = SAMPLESTART; | |
665 | |
666 data.u32bit = actualPointerSample; | |
667 pHeaderPreDive[2] = data.u8bit.byteLow; | |
668 pHeaderPreDive[3] = data.u8bit.byteMidLow; | |
669 pHeaderPreDive[4] = data.u8bit.byteMidHigh; | |
670 /* to start sample writing and header etc. pp. */ | |
671 ext_flash_disable_protection_for_logbook(); | |
672 } | |
673 | |
674 | |
675 /* ext_flash_create_new_dive_log | |
676 * uses the first header without HEADER2OFFSET | |
677 * for the header it is not important to be complete | |
678 * and can be reconstructed | |
679 * ext_flash_start_new_dive_log_and_set_actualPointerSample() | |
680 * has to be called before to set the actualPointerSample | |
681 * in the header | |
682 * the following func writes to header to the ext_flash | |
683 */ | |
684 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive) | |
685 { | |
686 SSettings *settings; | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
687 uint8_t id; |
38 | 688 uint8_t header1, header2; |
689 | |
690 settings = settingsGetPointer(); | |
691 id = settings->lastDiveLogId; | |
692 | |
693 actualAddress = HEADERSTART + (0x800 * id); | |
694 ext_flash_read_block_start(); | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
695 ext_flash_read_block(&header1, EF_SAMPLE); /* the sample ring is increased instead of header... not sure if that is planned intention */ |
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
696 ext_flash_read_block(&header2, EF_SAMPLE); /* does not matter because actual address is reset in write_block call */ |
38 | 697 ext_flash_read_block_stop(); |
698 | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
699 /* TODO Cleanup_Ref_2: The code below should not be necessary in case of a proper shutdown and startup */ |
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
700 /* the implementation fixes an issue which might happen at Cleanup_Ref_1 (in case of more then 254 dives) */ |
38 | 701 if((header1 == 0xFA) && (header2 == 0xFA)) |
702 { | |
703 id += 1; /* 0-255, auto rollover */ | |
704 if(id & 1) | |
705 { | |
706 actualAddress = HEADERSTART + (0x800 * id); | |
707 ext_flash_read_block_start(); | |
708 ext_flash_read_block(&header1, EF_SAMPLE); | |
709 ext_flash_read_block(&header2, EF_SAMPLE); | |
710 ext_flash_read_block_stop(); | |
711 if((header1 == 0xFA) && (header2 == 0xFA)) | |
712 id += 1; | |
713 } | |
714 } | |
715 else | |
716 { | |
717 id = 0; | |
718 } | |
719 | |
720 settings->lastDiveLogId = id; | |
721 actualPointerHeader = HEADERSTART + (0x800 * id); | |
722 | |
723 if(pHeaderPreDive != 0) | |
724 ef_write_block(pHeaderPreDive,HEADERSIZE, EF_HEADER, 0); | |
725 } | |
726 | |
727 | |
728 void ext_flash_close_new_dive_log(uint8_t *pHeaderPostDive ) | |
729 { | |
730 SSettings * settings = settingsGetPointer(); | |
731 uint8_t id; | |
732 convert_Type startAddress; | |
733 convert_Type data; | |
734 uint32_t backup; | |
735 | |
736 uint8_t sampleData[3]; | |
737 actualAddress = actualPointerSample; | |
738 sampleData[0] = 0xFD; | |
739 sampleData[1] = 0xFD; | |
740 ext_flash_write_sample(sampleData, 2); | |
741 | |
742 /* end of sample data, pointing to the last sample 0xFD | |
743 */ | |
744 actualAddress = actualPointerSample; // change hw 17.09.2015 | |
745 ext_flash_decf_address_ring(EF_SAMPLE); // 17.09.2015: this decf actualAddress only!! | |
746 actualPointerSample = actualAddress; // change hw 17.09.2015 | |
747 data.u32bit = actualPointerSample; | |
748 | |
749 pHeaderPostDive[5] = data.u8bit.byteLow; | |
750 pHeaderPostDive[6] = data.u8bit.byteMidLow; | |
751 pHeaderPostDive[7] = data.u8bit.byteMidHigh; | |
752 | |
753 /* take data written before, calculate length and write | |
754 SLogbookHeader has different order: length (byte# 8,9,10) prior to profile version (byte# 11) | |
755 */ | |
756 startAddress.u8bit.byteLow = pHeaderPostDive[2]; | |
757 startAddress.u8bit.byteMidLow = pHeaderPostDive[3]; | |
758 startAddress.u8bit.byteMidHigh = pHeaderPostDive[4]; | |
759 startAddress.u8bit.byteHigh = 0; | |
760 | |
761 if(startAddress.u32bit < actualPointerSample) | |
762 data.u32bit = 1 + actualPointerSample - startAddress.u32bit; | |
763 else | |
764 data.u32bit = 2 + (actualPointerSample - SAMPLESTART) + (SAMPLESTOP - startAddress.u32bit); | |
765 | |
766 pHeaderPostDive[8] = data.u8bit.byteLow; | |
767 pHeaderPostDive[9] = data.u8bit.byteMidLow; | |
768 pHeaderPostDive[10] = data.u8bit.byteMidHigh; | |
769 | |
770 /* set id and write post-dive-header | |
771 */ | |
772 id = settings->lastDiveLogId; | |
773 actualPointerHeader = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
774 | |
775 ef_write_block(pHeaderPostDive,HEADERSIZE, EF_HEADER, 0); | |
776 | |
777 /* write length at beginning of sample | |
778 and write proper beginning for next dive to actualPointerSample | |
779 */ | |
780 backup = actualPointerSample; | |
781 actualPointerSample = startAddress.u32bit; // is still 0xFF | |
782 sampleData[0] = data.u8bit.byteLow; | |
783 sampleData[1] = data.u8bit.byteMidLow; | |
784 sampleData[2] = data.u8bit.byteMidHigh; | |
785 ext_flash_overwrite_sample_without_erase(sampleData, 3); | |
786 | |
787 actualAddress = backup; | |
788 ext_flash_incf_address(EF_SAMPLE); | |
789 actualPointerSample = actualAddress; | |
790 ext_flash_enable_protection(); | |
791 } | |
792 | |
793 | |
794 void ext_flash_write_sample(uint8_t *pSample, uint16_t length) | |
795 { | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
796 uint32_t actualAdressBackup = 0; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
797 |
38 | 798 ef_write_block(pSample,length, EF_SAMPLE, 0); |
799 | |
800 SSettings *settings = settingsGetPointer(); | |
801 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
802 |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
803 if(0xFFFF - (actualAddress & 0x0000FFFF) < 255) /* are we close to a sector border? */ |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
804 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
805 if (((actualAddress & 0x0000FFFF) != 0) && (preparedPageAddress == 0)) /* only prepare if not already at start of sector */ |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
806 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
807 actualAdressBackup = actualAddress; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
808 actualAddress = (actualAddress & 0xFFFF0000) + 0x00010000; /* Set to start of next 64k sector */ |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
809 if(actualAddress >= SAMPLESTOP) |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
810 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
811 actualAddress = SAMPLESTART; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
812 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
813 preparedPageAddress = actualAddress; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
814 ext_flash_erase64kB(); |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
815 actualAddress = actualAdressBackup; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
816 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
817 } |
38 | 818 } |
819 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
820 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length) |
38 | 821 { |
822 ef_write_block(pSample,length, EF_SAMPLE, 1); | |
823 } | |
824 | |
825 | |
826 uint8_t ext_flash_count_dive_headers(void) | |
827 { | |
828 uint8_t id = 0; | |
829 uint8_t counter = 0; | |
830 uint16_t headerStartData = 0x0000; | |
831 | |
832 id = settingsGetPointer()->lastDiveLogId; | |
833 | |
834 do | |
835 { | |
836 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
837 ext_flash_read_block_start(); | |
838 ext_flash_read_block_multi((uint8_t *)&headerStartData, 2, EF_HEADER); | |
839 ext_flash_read_block_stop(); | |
840 counter++; | |
841 id -=1; | |
842 } while((headerStartData == 0xFAFA) && (counter < 255)); | |
843 return (counter - 1); | |
844 } | |
845 | |
846 | |
847 void ext_flash_read_dive_header(uint8_t *pHeaderToFill, uint8_t StepBackwards) | |
848 { | |
849 SSettings *settings; | |
850 uint8_t id; | |
851 uint16_t i; | |
852 | |
853 settings = settingsGetPointer(); | |
854 id = settings->lastDiveLogId; | |
855 id -= StepBackwards; /* 0-255, auto rollover */ | |
856 | |
857 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
858 ext_flash_read_block_start(); | |
859 for(i = 0; i < HEADERSIZE; i++) | |
860 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
861 ext_flash_read_block_stop(); | |
862 | |
863 } | |
864 | |
865 void ext_flash_read_dive_header2(uint8_t *pHeaderToFill, uint8_t id, _Bool bOffset) | |
866 { | |
867 | |
868 uint16_t i; | |
869 actualAddress = HEADERSTART + (0x800 * id) ; | |
870 | |
871 if(bOffset) | |
872 actualAddress += HEADER2OFFSET; | |
873 ext_flash_read_block_start(); | |
874 for(i = 0; i < HEADERSIZE; i++) | |
875 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
876 ext_flash_read_block_stop(); | |
877 } | |
878 | |
879 | |
880 uint32_t ext_flash_read_dive_raw_with_double_header_1K(uint8_t *data, uint32_t max_size, uint8_t StepBackwards) | |
881 { | |
882 if(max_size < 0x800) | |
883 return 0; | |
884 | |
885 uint8_t id; | |
886 convert_Type dataStart, dataEnd; | |
887 uint32_t LengthAll = 0; | |
888 | |
889 id = settingsGetPointer()->lastDiveLogId; | |
890 id -= StepBackwards; /* 0-255, auto rollover */ | |
891 | |
892 // clear data | |
893 for(int i=0;i<0x800;i++) | |
894 data[i] = 0xFF; | |
895 | |
896 // copy primary/pre-dive | |
897 actualAddress = HEADERSTART + (0x800 * id); | |
898 ext_flash_read_block_start(); | |
899 for(int i = 0; i < HEADERSIZE; i++) | |
900 ext_flash_read_block(&data[i], EF_HEADER); | |
901 ext_flash_read_block_stop(); | |
902 | |
903 // copy main/secondary/post-dive | |
904 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
905 ext_flash_read_block_start(); | |
906 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
907 ext_flash_read_block(&data[i], EF_HEADER); | |
908 ext_flash_read_block_stop(); | |
909 | |
910 // data | |
911 | |
912 dataStart.u8bit.byteHigh = 0; | |
913 dataStart.u8bit.byteLow = data[0x402]; | |
914 dataStart.u8bit.byteMidLow = data[0x403]; | |
915 dataStart.u8bit.byteMidHigh = data[0x404]; | |
916 | |
917 dataEnd.u8bit.byteHigh = 0; | |
918 dataEnd.u8bit.byteLow = data[0x405]; | |
919 dataEnd.u8bit.byteMidLow = data[0x406]; | |
920 dataEnd.u8bit.byteMidHigh = data[0x407]; | |
921 | |
922 actualPointerSample = dataStart.u32bit; | |
923 if(dataEnd.u32bit >= dataStart.u32bit) | |
924 LengthAll = 1 + dataEnd.u32bit - dataStart.u32bit; | |
925 else | |
926 LengthAll = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
927 | |
928 LengthAll += 0x800; | |
929 | |
930 if(LengthAll > max_size) | |
931 return 0x800; | |
932 | |
933 actualAddress = actualPointerSample; | |
934 ext_flash_read_block_start(); | |
935 for(uint32_t i = 0x800; i < LengthAll; i++) | |
936 ext_flash_read_block(&data[i], EF_SAMPLE); | |
937 ext_flash_read_block_stop(); | |
938 return LengthAll; | |
939 } | |
940 | |
941 void ext_flash_write_dive_raw_with_double_header_1K(uint8_t *data, uint32_t length) | |
942 { | |
943 convert_Type dataStart, dataEnd; | |
944 SLogbookHeader headerTemp; | |
945 | |
946 // set actualPointerSample and get pointer to sample storage and disable flash write protect | |
947 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t *)&headerTemp); | |
948 | |
949 dataStart.u8bit.byteHigh = 0; | |
950 dataStart.u8bit.byteLow = headerTemp.pBeginProfileData[0]; | |
951 dataStart.u8bit.byteMidLow = headerTemp.pBeginProfileData[1]; | |
952 dataStart.u8bit.byteMidHigh = headerTemp.pBeginProfileData[2]; | |
953 | |
954 dataEnd.u32bit = dataStart.u32bit + length - 0x801; | |
955 if(dataEnd.u32bit > SAMPLESTOP) | |
956 dataEnd.u32bit -= SAMPLESTOP + SAMPLESTART - 1; | |
957 | |
958 data[0x002] = data[0x402] = dataStart.u8bit.byteLow; | |
959 data[0x003] = data[0x403] = dataStart.u8bit.byteMidLow; | |
960 data[0x004] = data[0x404] = dataStart.u8bit.byteMidHigh; | |
961 data[0x005] = data[0x405] = dataEnd.u8bit.byteLow; | |
962 data[0x006] = data[0x406] = dataEnd.u8bit.byteMidLow; | |
963 data[0x007] = data[0x407] = dataEnd.u8bit.byteMidHigh; | |
964 | |
965 // set actualPointerHeader to next free header and update lastDiveLogId | |
966 ext_flash_create_new_dive_log(0); | |
967 | |
968 // copy header data | |
969 ef_write_block(data,0x800,EF_HEADER, 1); | |
970 | |
971 // copy sample data | |
972 ef_write_block(&data[0x800], length-0x800, EF_SAMPLE, 1); | |
973 | |
974 // update logFlashNextSampleStartAddress | |
975 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; | |
976 } | |
977 | |
978 | |
979 // =============================================================================== | |
980 // ext_flash_read_header_memory | |
981 /// @brief This function returns the entire header space 1:1 | |
982 /// @date 04-April-2016 | |
983 /// | |
984 /// @param *data 256KB output | |
985 // =============================================================================== | |
986 void ext_flash_read_header_memory(uint8_t *data) | |
987 { | |
988 actualAddress = HEADERSTART; | |
989 actualPointerHeader = actualAddress; | |
990 ext_flash_read_block_start(); | |
991 for(int i=0;i<8;i++) | |
992 ext_flash_read_block_multi(&data[0x8000 * i], 0x8000, EF_HEADER); | |
993 ext_flash_read_block_stop(); | |
994 } | |
995 | |
996 | |
997 // =============================================================================== | |
463 | 998 // ext_flash_write_header_memory |
38 | 999 /// @brief This function erases and overwrites the entire logbook header block |
1000 /// @date 04-April-2016 | |
1001 /// | |
1002 /// @param *data 256KB input of header memory 1:1 | |
1003 // =============================================================================== | |
1004 void ext_flash_write_header_memory(uint8_t *data) | |
1005 { | |
1006 actualAddress = HEADERSTART; | |
1007 actualPointerHeader = actualAddress; | |
1008 ef_write_block(data, 0x40000, EF_HEADER, 0); | |
1009 } | |
1010 | |
463 | 1011 void ext_flash_read_sample_memory(uint8_t *data,uint16_t blockId) |
1012 { | |
1013 actualAddress = SAMPLESTART; | |
1014 actualAddress += blockId * 0x8000; /* add 32k Block offset */ | |
1015 actualPointerSample = actualAddress; | |
1016 ext_flash_read_block_start(); | |
1017 ext_flash_read_block_multi(data, 0x8000, EF_SAMPLE); | |
1018 ext_flash_read_block_stop(); | |
1019 } | |
1020 | |
1021 void ext_flash_write_sample_memory(uint8_t *data,uint16_t blockId) | |
1022 { | |
1023 actualAddress = SAMPLESTART; | |
1024 actualAddress += blockId * 0x8000; /* add 32k Block offset */ | |
1025 actualPointerSample = actualAddress; | |
1026 ef_write_block(data, 0x8000, EF_SAMPLE,0); | |
1027 } | |
1028 | |
38 | 1029 |
1030 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes) | |
1031 { | |
1032 SSettings *settings = settingsGetPointer(); | |
1033 uint8_t id; | |
1034 convert_Type dataStart, dataEnd; | |
1035 uint8_t header1, header2; | |
1036 | |
1037 id = settings->lastDiveLogId; | |
1038 id -= StepBackwards; /* 0-255, auto rollover */ | |
1039 # | |
1040 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1041 actualPointerHeader = actualAddress; | |
1042 | |
1043 ext_flash_read_block_start(); | |
1044 /* little endian */ | |
1045 ext_flash_read_block(&header1, EF_HEADER); | |
1046 ext_flash_read_block(&header2, EF_HEADER); | |
1047 dataStart.u8bit.byteHigh = 0; | |
1048 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1049 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1050 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1051 dataEnd.u8bit.byteHigh = 0; | |
1052 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
1053 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
1054 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
1055 ext_flash_read_block_stop(); | |
1056 | |
1057 actualPointerSample = dataStart.u32bit; | |
1058 if(dataEnd.u32bit >= dataStart.u32bit) | |
1059 LengthLeftSampleRead = 1 + dataEnd.u32bit - dataStart.u32bit; | |
1060 else | |
1061 LengthLeftSampleRead = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
1062 *totalNumberOfBytes = LengthLeftSampleRead; | |
1063 | |
1064 actualAddress = actualPointerSample; | |
1065 ext_flash_read_block_start(); | |
1066 } | |
1067 | |
1068 | |
1069 void ext_flash_read_next_sample_part(uint8_t *pSample, uint8_t length) | |
1070 { | |
1071 for(uint16_t i = 0; i < length; i++) | |
1072 ext_flash_read_block(&pSample[i], EF_SAMPLE); | |
1073 } | |
1074 | |
1075 | |
1076 void ext_flash_close_read_sample(void) | |
1077 { | |
1078 actualPointerSample = actualAddress; | |
1079 ext_flash_read_block_stop(); | |
1080 } | |
1081 | |
1082 | |
1083 void ext_flash_set_entry_point(void) | |
1084 { | |
1085 entryPoint = actualAddress; | |
1086 } | |
1087 | |
1088 | |
1089 void ext_flash_reopen_read_sample_at_entry_point(void) | |
1090 { | |
1091 error_led_on(); | |
1092 chip_unselect(); | |
1093 wait_chip_not_busy(); | |
1094 | |
1095 actualAddress = entryPoint; | |
1096 ext_flash_read_block_start(); | |
1097 error_led_off(); | |
1098 } | |
1099 | |
1100 /* | |
1101 uint8_t ext_flash_point_to_64k_block_in_headerSpace(uint8_t logId) | |
1102 { | |
1103 uint32_t pointerToData = logId * 0x800; | |
1104 | |
1105 return pointerToData / 0x10000; | |
1106 } | |
1107 */ | |
1108 | |
1109 | |
1110 // =============================================================================== | |
1111 // ext_flash_repair_dive_numbers_starting_count_helper | |
1112 /// @brief | |
1113 /// @date 22-June-2016 | |
1114 | |
1115 // =============================================================================== | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1116 static uint16_t ext_flash_repair_dive_numbers_starting_count_helper(uint8_t *data, uint8_t *change64k, uint16_t startNumber, uint8_t lastLogId) |
38 | 1117 { |
1118 const uint32_t headerStep = 0x800; | |
1119 uint8_t actualLogId = 0; | |
1120 uint16_t oldNumber = 0; | |
1121 uint16_t actualNumber = 0; | |
1122 SLogbookHeader *ptrLogbookHeader = 0; | |
1123 | |
1124 if(startNumber == 0) | |
1125 return 0; | |
1126 | |
1127 actualNumber = startNumber - 1; | |
1128 | |
282 | 1129 // where is the oldest dive (Which is now getting startNumber) |
38 | 1130 // use first header for ease (without HEADER2OFFSET for end of dive header) |
1131 // compare for lastLogId to prevent endless loop | |
1132 | |
1133 if(*(uint16_t*)&data[lastLogId * headerStep] != 0xFAFA) | |
1134 return 0; | |
1135 | |
1136 actualLogId = lastLogId - 1; | |
1137 while((*(uint16_t*)&data[actualLogId * headerStep] == 0xFAFA) && (actualLogId != lastLogId)) | |
1138 { | |
1139 actualLogId--; | |
1140 } | |
1141 | |
1142 // now pointing to one behind the last | |
1143 while(actualLogId != lastLogId) | |
1144 { | |
1145 actualLogId++; | |
1146 actualNumber++; | |
1147 ptrLogbookHeader = (SLogbookHeader *)&data[actualLogId * headerStep]; | |
1148 | |
1149 oldNumber = ptrLogbookHeader->diveNumber; | |
1150 if(oldNumber != actualNumber) | |
1151 { | |
1152 // change64k[ext_flash_point_to_64k_block_in_headerSpace(actualLogId )] = 1; | |
1153 change64k[(actualLogId * 0x800)/0x10000] = 1; | |
1154 ptrLogbookHeader->diveNumber = actualNumber; | |
1155 ptrLogbookHeader = (SLogbookHeader *)(&data[actualLogId * headerStep] + HEADER2OFFSET); | |
1156 ptrLogbookHeader->diveNumber = actualNumber; | |
1157 } | |
1158 } | |
1159 | |
1160 return actualNumber; | |
1161 } | |
1162 | |
1163 // =============================================================================== | |
1164 // ext_flash_repair_SPECIAL_dive_numbers_starting_count_with | |
1165 /// @brief This function | |
1166 /// @date 04-April-2016 | |
282 | 1167 /// problem (160621): 64K blocks (32 dives) in the new flash memory chip |
1168 /// This block needs to be deleted | |
1169 /// these where only 4KB block before | |
38 | 1170 /// @output endCount, last diveNumber |
1171 | |
1172 // =============================================================================== | |
1173 uint16_t ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) | |
1174 { | |
1175 uint32_t logCopyDataPtr = 0; | |
1176 uint8_t *data; | |
1177 uint16_t lastCount; | |
282 | 1178 uint8_t listOfChanged64kBlocks[8]; // 32 dives each 64K |
38 | 1179 |
1180 logCopyDataPtr = getFrame(97); | |
1181 data = (uint8_t *)logCopyDataPtr; | |
1182 | |
1183 for(int i=0;i<8;i++) | |
1184 listOfChanged64kBlocks[i] = 0; | |
1185 | |
1186 actualAddress = HEADERSTART; | |
1187 ext_flash_read_block_start(); | |
1188 ext_flash_read_block_multi(data,0x100000,EF_HEADER); | |
1189 ext_flash_read_block_stop(); | |
1190 | |
1191 lastCount = ext_flash_repair_dive_numbers_starting_count_helper(data, listOfChanged64kBlocks, startCount, settingsGetPointer()->lastDiveLogId); | |
1192 | |
1193 for(int i=0;i<8;i++) | |
1194 { | |
1195 if(listOfChanged64kBlocks[i] != 0) | |
1196 { | |
1197 actualPointerHeader = HEADERSTART + (i * 0x10000); | |
1198 ef_write_block(&data[i * 0x10000], 0x10000, EF_HEADER, 0); | |
1199 } | |
1200 } | |
1201 | |
1202 releaseFrame(97,logCopyDataPtr); | |
1203 if(settingsGetPointer()->totalDiveCounter < lastCount) | |
1204 { | |
1205 settingsGetPointer()->totalDiveCounter = lastCount; | |
1206 } | |
1207 return lastCount; | |
1208 } | |
1209 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1210 /* |
38 | 1211 void OLD_ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) |
1212 { | |
1213 uint16_t counterStorage[256]; | |
1214 uint8_t start = 0xFF; | |
1215 uint32_t logCopyDataPtr = 0; | |
1216 uint8_t *data; | |
1217 uint8_t startAbsolute = 0; | |
1218 int16_t count = 0; | |
1219 _Bool repair = 0; | |
1220 uint8_t startBackup = 0; | |
1221 | |
1222 SLogbookHeader tempLogbookHeader; | |
1223 SLogbookHeader *ptrHeaderInData1a; | |
1224 SLogbookHeader *ptrHeaderInData1b; | |
1225 SLogbookHeader *ptrHeaderInData2a; | |
1226 SLogbookHeader *ptrHeaderInData2b; | |
1227 | |
1228 logCopyDataPtr = getFrame(97); | |
1229 data = (uint8_t *)logCopyDataPtr; | |
1230 ptrHeaderInData1a = (SLogbookHeader *)logCopyDataPtr; | |
1231 ptrHeaderInData1b = (SLogbookHeader *)(logCopyDataPtr + HEADER2OFFSET); | |
1232 ptrHeaderInData2a = (SLogbookHeader *)(logCopyDataPtr + 0x800); | |
1233 ptrHeaderInData2b = (SLogbookHeader *)(logCopyDataPtr + 0x800 + HEADER2OFFSET); | |
1234 | |
1235 // get data | |
1236 for(int StepBackwards = 0; StepBackwards < 255; StepBackwards++) | |
1237 { | |
1238 logbook_getHeader(StepBackwards, &tempLogbookHeader); | |
1239 counterStorage[StepBackwards+1] = tempLogbookHeader.diveNumber; | |
1240 if(tempLogbookHeader.diveHeaderStart == 0xFAFA) | |
1241 start = StepBackwards; | |
1242 else | |
1243 break; | |
1244 } | |
1245 | |
1246 if(start == 0xFF) | |
1247 return; | |
1248 | |
1249 count = start + 1; | |
1250 startAbsolute = settingsGetPointer()->lastDiveLogId; | |
1251 | |
1252 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1253 |
38 | 1254 if(start%2) |
1255 { | |
1256 if(counterStorage[start] != startCount) | |
1257 { | |
1258 // clear data | |
1259 for(int i=0;i<0x800*2;i++) | |
1260 data[i] = 0xFF; | |
1261 | |
1262 uint8_t id = settingsGetPointer()->lastDiveLogId; | |
1263 id -= start; // 0-255, auto rollover | |
1264 | |
1265 // copy primary/pre-dive | |
1266 actualAddress = HEADERSTART + (0x800 * id); | |
1267 ext_flash_read_block_start(); | |
1268 for(int i = 0; i < HEADERSIZE; i++) | |
1269 ext_flash_read_block(&data[i], EF_HEADER); | |
1270 ext_flash_read_block_stop(); | |
1271 | |
1272 // copy main/secondary/post-dive | |
1273 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1274 ext_flash_read_block_start(); | |
1275 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1276 ext_flash_read_block(&data[i], EF_HEADER); | |
1277 ext_flash_read_block_stop(); | |
1278 | |
1279 // repair | |
1280 ptrHeaderInData2a->diveNumber = startCount; | |
1281 ptrHeaderInData2b->diveNumber = startCount; | |
1282 startCount++; | |
1283 | |
1284 // write | |
1285 actualAddress = HEADERSTART + (0x800 * (id-1)); | |
1286 ef_write_block(data,0x800*2,EF_HEADER, 0); | |
1287 } | |
1288 start--; | |
1289 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1290 |
38 | 1291 // for(int count = start; count > -1; count -= 2) |
1292 | |
1293 while(count > 0) | |
1294 { | |
1295 // clear data | |
1296 for(int i=0;i<0x1000;i++) | |
1297 data[i] = 0xFF; | |
1298 | |
1299 repair = 0; | |
1300 | |
1301 startBackup = startAbsolute; | |
1302 | |
1303 if(startAbsolute%2) // 0x800 to 0x1000 | |
1304 { | |
1305 // copy second pre-dive | |
1306 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1307 ext_flash_read_block_start(); | |
1308 for(int i = 0x800; i < HEADERSIZE+0x800; i++) | |
1309 ext_flash_read_block(&data[i], EF_HEADER); | |
1310 ext_flash_read_block_stop(); | |
1311 | |
1312 // copy second post-dive | |
1313 actualAddress = HEADERSTART + HEADER2OFFSET + (0x800 * startAbsolute); | |
1314 ext_flash_read_block_start(); | |
1315 for(int i = 0xC00; i < HEADERSIZE+0xC00; i++) | |
1316 ext_flash_read_block(&data[i], EF_HEADER); | |
1317 ext_flash_read_block_stop(); | |
1318 | |
1319 if(counterStorage[count] != startCount) | |
1320 { | |
1321 ptrHeaderInData2a->diveNumber = startCount; | |
1322 ptrHeaderInData2b->diveNumber = startCount; | |
1323 repair = 1; | |
1324 } | |
1325 startCount += 1; | |
1326 | |
1327 startAbsolute -= 1; | |
1328 count -= 1; | |
1329 | |
1330 if(count > 0) | |
1331 { | |
1332 // copy first pre-dive | |
1333 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1334 ext_flash_read_block_start(); | |
1335 for(int i = 0; i < HEADERSIZE; i++) | |
1336 ext_flash_read_block(&data[i], EF_HEADER); | |
1337 ext_flash_read_block_stop(); | |
1338 | |
1339 // copy first post-dive | |
1340 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1341 ext_flash_read_block_start(); | |
1342 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1343 ext_flash_read_block(&data[i], EF_HEADER); | |
1344 ext_flash_read_block_stop(); | |
1345 | |
1346 if(counterStorage[count] != startCount) | |
1347 { | |
1348 ptrHeaderInData1a->diveNumber = startCount; | |
1349 ptrHeaderInData1b->diveNumber = startCount; | |
1350 repair = 1; | |
1351 } | |
1352 startCount += 1; | |
1353 | |
1354 startAbsolute -= 1; | |
1355 count -= 1; | |
1356 } | |
1357 } | |
1358 else | |
1359 { | |
1360 // copy first pre-dive | |
1361 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1362 ext_flash_read_block_start(); | |
1363 for(int i = 0; i < HEADERSIZE; i++) | |
1364 ext_flash_read_block(&data[i], EF_HEADER); | |
1365 ext_flash_read_block_stop(); | |
1366 | |
1367 // copy first post-dive | |
1368 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1369 ext_flash_read_block_start(); | |
1370 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1371 ext_flash_read_block(&data[i], EF_HEADER); | |
1372 ext_flash_read_block_stop(); | |
1373 | |
1374 if(counterStorage[count] != startCount) | |
1375 { | |
1376 ptrHeaderInData1a->diveNumber = startCount; | |
1377 ptrHeaderInData1b->diveNumber = startCount; | |
1378 repair = 1; | |
1379 } | |
1380 startCount += 1; | |
1381 | |
1382 startAbsolute -= 1; | |
1383 count -= 1; | |
1384 } | |
1385 | |
1386 // write | |
1387 if(repair) | |
1388 { | |
1389 actualPointerHeader = HEADERSTART + (0x1000 * startBackup%2); | |
1390 ef_write_block(data,0x1000,EF_HEADER, 0); | |
1391 } | |
1392 } | |
1393 releaseFrame(97,logCopyDataPtr); | |
1394 settingsGetPointer()->totalDiveCounter = startCount; | |
1395 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1396 */ |
38 | 1397 |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1398 uint8_t ext_dive_log_consistent(void) |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1399 { |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1400 uint8_t ret = 0; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1401 uint8_t header1, header2; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1402 uint8_t id; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1403 convert_Type dataStart; |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1404 convert_Type dataEnd; |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1405 |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1406 SSettings *settings = settingsGetPointer(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1407 id = settings->lastDiveLogId; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1408 |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1409 if(settings->lastDiveLogId != 0) /* not trust LogID 0 which might be reset by a settings problem */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1410 { /* ==> Find function will be called restoring the Id belonging to the latest sample */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1411 actualAddress = HEADERSTART + (0x800 * id); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1412 ext_flash_read_block_start(); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1413 ext_flash_read_block(&header1, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1414 ext_flash_read_block(&header2, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1415 ext_flash_read_block_stop(); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1416 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1417 { |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1418 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1419 ext_flash_read_block_start(); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1420 ext_flash_read_block(&header1, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1421 ext_flash_read_block(&header2, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1422 dataStart.u8bit.byteHigh = 0; |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1423 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1424 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1425 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1426 dataEnd.u8bit.byteHigh = 0; |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1427 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1428 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1429 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1430 ext_flash_read_block_stop(); |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1431 |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1432 if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1433 { |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1434 if(dataStart.u32bit < dataEnd.u32bit) |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1435 { |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1436 ret = 1; /* => lastDiveLogID points to a valid dive entry */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1437 } |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1438 else /* check if address wrap is valid */ |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1439 { |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1440 if(ext_flash_SampleOverrunValid()) |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1441 { |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1442 ret = 1; |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1443 } |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1444 } |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1445 } |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1446 } |
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
1447 } |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1448 return ret; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1449 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1450 |
38 | 1451 // =============================================================================== |
1452 // ext_flash_repair_dive_log | |
1453 /// @brief This function | |
1454 /// does set | |
1455 /// logFlashNextSampleStartAddress | |
1456 /// and | |
1457 /// lastDiveLogId | |
1458 /// | |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1459 |
38 | 1460 void ext_flash_repair_dive_log(void) |
1461 { | |
1462 uint8_t header1, header2; | |
1463 convert_Type dataStart; | |
1464 | |
1465 for(int id = 0; id < 255;id++) | |
1466 { | |
1467 actualAddress = HEADERSTART + (0x800 * id); | |
1468 ext_flash_read_block_start(); | |
1469 ext_flash_read_block(&header1, EF_HEADER); | |
1470 ext_flash_read_block(&header2, EF_HEADER); | |
1471 dataStart.u8bit.byteHigh = 0; | |
1472 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1473 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1474 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1475 ext_flash_read_block_stop(); | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1476 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */ |
38 | 1477 { |
1478 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1479 ext_flash_read_block_start(); | |
1480 ext_flash_read_block(&header1, EF_HEADER); | |
1481 ext_flash_read_block(&header2, EF_HEADER); | |
1482 ext_flash_read_block_stop(); | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1483 if((header1 != 0xFA) || (header2 != 0xFA)) /* Secondary header was not written at the end of a dive */ |
38 | 1484 { |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1485 actualPointerSample = dataStart.u32bit; /* Set datapointer to position stored in header written at beginning of dive */ |
38 | 1486 actualAddress = actualPointerSample; |
1487 logbook_recover_brokenlog(id); | |
1488 SSettings *settings = settingsGetPointer(); | |
1489 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1490 } | |
1491 } | |
1492 } | |
1493 ext_flash_find_start(); | |
1494 } | |
1495 | |
1496 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1497 static void ext_flash_find_start(void) |
38 | 1498 { |
1499 uint8_t id; | |
1500 uint8_t header1, header2; | |
1501 convert_Type dataStart, dataEnd; | |
1502 | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
1503 /* TODO Cleanup_Ref_1: cleanup logFlashNextSampleStartAddress and lastDiveLogId */ |
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
1504 /* The implementation below would cause problems in case more then 254 dives would be done. */ |
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
1505 /* This is avoided by Cleanup_Ref2 */ |
441
9a9e4908ce2e
fix potential issue with >255 dives in the logbook
heinrichsweikamp
parents:
429
diff
changeset
|
1506 for(id = 0; id <= 255;id++) |
38 | 1507 { |
1508 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1509 ext_flash_read_block_start(); | |
1510 ext_flash_read_block(&header1, EF_HEADER); | |
1511 ext_flash_read_block(&header2, EF_HEADER); | |
1512 dataStart.u8bit.byteHigh = 0; | |
1513 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1514 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1515 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1516 ext_flash_read_block_stop(); | |
1517 if((header1 == 0xFF) && (header2 == 0xFF)) | |
1518 { | |
1519 break; | |
1520 } | |
1521 } | |
1522 id--; | |
1523 SSettings *settings = settingsGetPointer(); | |
1524 settings->lastDiveLogId = id; | |
1525 | |
1526 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1527 actualPointerHeader = actualAddress; | |
1528 | |
1529 ext_flash_read_block_start(); | |
1530 | |
1531 ext_flash_read_block(&header1, EF_HEADER); | |
1532 ext_flash_read_block(&header2, EF_HEADER); | |
1533 dataStart.u8bit.byteHigh = 0; | |
1534 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1535 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1536 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1537 dataEnd.u8bit.byteHigh = 0; | |
1538 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
1539 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
1540 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
1541 ext_flash_read_block_stop(); | |
1542 | |
1543 //Find free space | |
1544 if((header1 == 0xFA) && (header2 == 0xFA)) | |
1545 { | |
1546 uint8_t uiRead = 0; | |
1547 int countFF = 0; | |
1548 //End of last complete dive | |
1549 actualPointerSample = dataEnd.u32bit ; | |
1550 actualAddress = actualPointerSample; | |
1551 //Check if there are samples of dives with less than half a minute | |
1552 while(true) | |
1553 { | |
1554 ext_flash_read_block_start(); | |
1555 ext_flash_read_block(&uiRead, EF_SAMPLE); | |
1556 if(uiRead == 0xFF) | |
1557 countFF++; | |
1558 else | |
1559 countFF = 0; | |
1560 | |
1561 | |
1562 | |
1563 if(countFF == 10) | |
1564 { | |
1565 actualAddress -= 10; | |
1566 break; | |
1567 } | |
1568 | |
1569 //New page: clear | |
1570 if(ext_flash_erase_if_on_page_start()) | |
1571 break; | |
1572 } | |
1573 // Set new start address | |
1574 actualPointerSample = actualAddress; | |
1575 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1576 } | |
1577 else | |
1578 { | |
1579 settings->logFlashNextSampleStartAddress = SAMPLESTART; | |
1580 } | |
1581 } | |
1582 | |
1583 | |
1584 #endif | |
1585 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1586 static void ext_flash_disable_protection(void) |
38 | 1587 { |
1588 /* | |
1589 extFlashStatusBit8_Type status; | |
1590 | |
1591 status.uw = 0; | |
1592 | |
1593 wait_chip_not_busy(); | |
1594 write_spi(0x50,RELEASE); // EWSR | |
1595 write_spi(0x01,HOLDCS); // WRSR | |
1596 write_spi(status.uw,RELEASE); // new status | |
1597 */ | |
1598 } | |
1599 | |
1600 | |
1601 void ext_flash_disable_protection_for_logbook(void) | |
1602 { | |
1603 /* | |
1604 extFlashStatusBit8_Type status; | |
1605 | |
1606 status.uw = 0; | |
1607 status.ub.BlockProtect0 = 1; | |
1608 status.ub.BlockProtect1 = 0; | |
1609 status.ub.BlockProtect2 = 1; | |
1610 status.ub.BlockProtect3 = 0; // not set in OSTC3. Why? | |
1611 | |
1612 wait_chip_not_busy(); | |
1613 write_spi(0x50,RELEASE); // EWSR | |
1614 write_spi(0x01,HOLDCS); // WRSR | |
1615 write_spi(status.uw,RELEASE); // new status | |
1616 */ | |
1617 } | |
1618 | |
1619 | |
1620 void ext_flash_enable_protection(void) | |
1621 { | |
1622 /* | |
1623 extFlashStatusBit8_Type status; | |
1624 | |
1625 status.uw = 0; | |
1626 status.ub.BlockProtect0 = 1; | |
1627 status.ub.BlockProtect1 = 1; | |
1628 status.ub.BlockProtect2 = 1; | |
1629 status.ub.BlockProtect3 = 1; // not set in OSTC3. Why? | |
1630 | |
1631 wait_chip_not_busy(); | |
1632 write_spi(0x50,RELEASE); // EWSR | |
1633 write_spi(0x01,HOLDCS); // WRSR | |
1634 write_spi(status.uw,RELEASE); // new status | |
1635 */ | |
1636 } | |
1637 | |
1638 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1639 /*void ext_flash_erase_chip(void) |
38 | 1640 { |
1641 wait_chip_not_busy(); | |
1642 write_spi(0x06,RELEASE); | |
1643 write_spi(0x60,RELEASE); | |
1644 wait_chip_not_busy(); | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1645 }*/ |
38 | 1646 |
1647 void ext_flash_erase_firmware(void) | |
1648 { | |
1649 uint32_t size, blocks_64k; | |
1650 | |
1651 actualAddress = FWSTART; | |
1652 size = 1 + FWSTOP - FWSTART; | |
1653 blocks_64k = size / 0x10000; | |
1654 ef_erase_64K(blocks_64k); | |
1655 } | |
1656 | |
1657 void ext_flash_erase_firmware2(void) | |
1658 { | |
1659 uint32_t size, blocks_64k; | |
1660 | |
1661 actualAddress = FWSTART2; | |
1662 size = 1 + FWSTOP2 - FWSTART2; | |
1663 blocks_64k = size / 0x10000; | |
1664 ef_erase_64K(blocks_64k); | |
1665 } | |
1666 | |
1667 | |
1668 | |
1669 void ext_flash_erase_logbook(void) | |
1670 { | |
1671 uint32_t size, blocks_64k; | |
1672 | |
1673 ext_flash_disable_protection_for_logbook(); | |
1674 | |
1675 actualAddress = SAMPLESTART; | |
1676 size = 1 + SAMPLESTOP - SAMPLESTART; | |
1677 blocks_64k = size / 0x10000; | |
1678 ef_erase_64K(blocks_64k); | |
1679 | |
1680 actualAddress = HEADERSTART; | |
1681 size = 1 + HEADERSTOP - HEADERSTART; | |
1682 blocks_64k = size / 0x10000; | |
1683 ef_erase_64K(blocks_64k); | |
1684 | |
1685 ext_flash_enable_protection(); | |
1686 } | |
1687 | |
1688 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1689 static void ext_flash_erase4kB(void) |
38 | 1690 { |
1691 wait_chip_not_busy(); | |
1692 write_spi(0x06,RELEASE);/* WREN */ | |
1693 write_spi(0x20,HOLDCS);/* sector erase cmd */ | |
1694 write_address(RELEASE); | |
1695 } | |
1696 | |
282 | 1697 /* be careful - might not work with entire family and other products |
38 | 1698 * see page 14 of LOGBOOK_V3_S25FS-S_00-271247.pdf |
1699 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1700 static void ext_flash_erase32kB(void) |
38 | 1701 { |
1702 uint32_t actualAddress_backup; | |
1703 | |
1704 actualAddress_backup = actualAddress; | |
1705 actualAddress = 0; | |
1706 wait_chip_not_busy(); | |
1707 write_spi(0x06,RELEASE);/* WREN */ | |
1708 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1709 write_address(RELEASE); | |
1710 actualAddress = actualAddress_backup; | |
1711 } | |
1712 | |
1713 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1714 static void ext_flash_erase64kB(void) |
38 | 1715 { |
1716 wait_chip_not_busy(); | |
1717 write_spi(0x06,RELEASE);/* WREN */ | |
1718 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1719 write_address(RELEASE); | |
1720 } | |
1721 | |
1722 | |
1723 void ext_flash_read_block_start(void) | |
1724 { | |
1725 wait_chip_not_busy(); | |
1726 write_spi(0x03,HOLDCS); /* WREN */ | |
1727 write_address(HOLDCS); | |
1728 } | |
1729 | |
1730 /* 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
|
1731 static uint8_t ext_flash_erase_if_on_page_start(void) |
38 | 1732 { |
1733 if(actualAddress < 0x00008000) | |
1734 { | |
1735 /* 4K Byte is 0x1000 */ | |
1736 if((actualAddress & 0xFFF) == 0) | |
1737 { | |
1738 ext_flash_erase4kB(); | |
1739 return 1; | |
1740 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1741 } |
38 | 1742 else |
1743 if(actualAddress < 0x00010000) | |
1744 { | |
1745 /* 32K Byte is only one page */ | |
1746 if(actualAddress == 0x00010000) | |
1747 { | |
1748 ext_flash_erase32kB(); | |
1749 return 1; | |
1750 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1751 } |
38 | 1752 else |
1753 { | |
1754 /* 64K Byte is 0x10000 */ | |
1755 if((actualAddress & 0xFFFF) == 0) | |
1756 { | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1757 if(preparedPageAddress == actualAddress) /* has page already been prepared before? (at the moment for samples only) */ |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1758 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1759 preparedPageAddress = 0; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1760 |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1761 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1762 else |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1763 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1764 ext_flash_erase64kB(); |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1765 } |
38 | 1766 return 1; |
1767 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1768 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1769 |
38 | 1770 return 0; |
1771 } | |
1772 | |
1773 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1774 static void ext_flash_read_block(uint8_t *getByte, uint8_t type) |
38 | 1775 { |
1776 *getByte = read_spi(HOLDCS);/* read data */ | |
1777 ext_flash_incf_address(type); | |
1778 } | |
1779 | |
1780 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1781 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type) |
38 | 1782 { |
1783 uint8_t *data; | |
1784 data = getByte; | |
1785 | |
1786 for(uint32_t i=0;i<size;i++) | |
1787 { | |
1788 data[i] = read_spi(HOLDCS);/* read data */ | |
1789 ext_flash_incf_address(type); | |
1790 } | |
1791 } | |
1792 | |
1793 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1794 static void ext_flash_read_block_stop(void) |
38 | 1795 { |
1796 chip_unselect(); | |
1797 } | |
1798 | |
1799 | |
1800 /* Private functions ---------------------------------------------------------*/ | |
1801 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1802 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) |
38 | 1803 { |
1804 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; | |
420 | 1805 uint32_t i=0; |
1806 | |
38 | 1807 if(!length) |
1808 return; | |
1809 | |
1810 uint32_t ringStart, ringStop; | |
1811 | |
1812 switch(type) | |
1813 { | |
1814 case EF_HEADER: | |
1815 actualAddress = actualPointerHeader; | |
1816 ringStart = HEADERSTART; | |
1817 ringStop = HEADERSTOP; | |
1818 break; | |
1819 case EF_SAMPLE: | |
1820 actualAddress = actualPointerSample; | |
1821 ringStart = SAMPLESTART; | |
1822 ringStop = SAMPLESTOP; | |
1823 break; | |
1824 case EF_DEVICEDATA: | |
1825 actualAddress = actualPointerDevicedata; | |
1826 ringStart = DDSTART; | |
1827 ringStop = DDSTOP; | |
1828 break; | |
1829 case EF_VPMDATA: | |
1830 actualAddress = actualPointerVPM; | |
1831 ringStart = VPMSTART; | |
1832 ringStop = VPMSTOP; | |
1833 break; | |
1834 case EF_SETTINGS: | |
1835 actualAddress = actualPointerSettings; | |
1836 ringStart = SETTINGSSTART; | |
1837 ringStop = SETTINGSSTOP; | |
1838 break; | |
1839 case EF_FIRMWARE: | |
1840 actualAddress = actualPointerFirmware; | |
1841 ringStart = FWSTART; | |
1842 ringStop = FWSTOP; | |
1843 break; | |
1844 case EF_FIRMWARE2: | |
1845 actualAddress = actualPointerFirmware2; | |
1846 ringStart = FWSTART2; | |
1847 ringStop = FWSTOP2; | |
1848 break; | |
1849 default: | |
1850 ringStart = FLASHSTART; | |
1851 ringStop = FLASHSTOP; | |
1852 break; | |
1853 } | |
1854 /* safety */ | |
1855 if(actualAddress < ringStart) | |
1856 actualAddress = ringStart; | |
1857 | |
1858 if(do_not_erase == 0) | |
459
7ac0e76dbd6a
Activated reset of sample information within header data at time of sector erasing:
ideenmodellierer
parents:
452
diff
changeset
|
1859 { |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
1860 ext_flash_erase_if_on_page_start(); |
459
7ac0e76dbd6a
Activated reset of sample information within header data at time of sector erasing:
ideenmodellierer
parents:
452
diff
changeset
|
1861 } |
38 | 1862 |
420 | 1863 while( i<length) |
38 | 1864 { |
1865 ef_hw_rough_delay_us(5); | |
1866 wait_chip_not_busy(); | |
1867 write_spi(0x06,RELEASE); /* WREN */ | |
1868 write_spi(0x02,HOLDCS); /* write cmd */ | |
1869 write_address(HOLDCS); | |
1870 | |
1871 remaining_length = length - i; | |
420 | 1872 remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1; |
38 | 1873 remaining_space_to_ring_end = ringStop - actualAddress; |
1874 | |
420 | 1875 if(remaining_length >= 256) |
1876 { | |
1877 remaining_length = 255; /* up to 256 bytes may be written in one burst. Last byte is written with release */ | |
1878 } | |
1879 else | |
38 | 1880 { |
420 | 1881 remaining_length--; /* last byte needed for release */ |
1882 } | |
1883 if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */ | |
1884 { | |
1885 remaining_length = remaining_page_size - 1; | |
1886 } | |
1887 if( (remaining_space_to_ring_end >= 256)) | |
1888 { | |
1889 for(int j=0; j<remaining_length; j++) | |
38 | 1890 { |
1891 write_spi(sendByte[i],HOLDCS);/* write data */ | |
1892 actualAddress++; | |
1893 i++; | |
1894 } | |
1895 } | |
1896 /* byte with RELEASE */ | |
1897 write_spi(sendByte[i],RELEASE);/* write data */ | |
1898 actualAddress++; | |
420 | 1899 i++; |
1900 | |
38 | 1901 if(actualAddress > ringStop) |
1902 actualAddress = ringStart; | |
420 | 1903 |
38 | 1904 if(do_not_erase == 0) |
1905 ext_flash_erase_if_on_page_start(); | |
1906 } | |
1907 switch(type) | |
1908 { | |
1909 case EF_HEADER: | |
1910 actualPointerHeader = actualAddress; | |
1911 break; | |
1912 case EF_SAMPLE: | |
1913 actualPointerSample = actualAddress; | |
1914 break; | |
1915 case EF_DEVICEDATA: | |
1916 actualPointerDevicedata = actualAddress; | |
1917 break; | |
1918 case EF_VPMDATA: | |
1919 actualPointerVPM = actualAddress; | |
1920 break; | |
1921 case EF_SETTINGS: | |
1922 actualPointerSettings = actualAddress; | |
1923 break; | |
1924 case EF_FIRMWARE: | |
1925 actualPointerFirmware = actualAddress; | |
1926 break; | |
1927 case EF_FIRMWARE2: | |
1928 actualPointerFirmware2 = actualAddress; | |
1929 break; | |
1930 default: | |
1931 break; | |
1932 } | |
1933 } | |
1934 | |
1935 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1936 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length) |
38 | 1937 { |
1938 if((pointer & 0xFFF) == 0) | |
1939 return 1; | |
1940 | |
1941 uint32_t backup = actualAddress; | |
1942 uint8_t data; | |
1943 uint32_t size_to_page_end; | |
1944 | |
1945 size_to_page_end = 0x1000 - (pointer & 0xFFF); | |
1946 if(length > size_to_page_end) | |
1947 length = size_to_page_end; | |
1948 | |
1949 actualAddress = pointer; | |
1950 ext_flash_read_block_start(); | |
1951 | |
1952 for(uint16_t i = 0; i<length; i++) | |
1953 { | |
1954 ext_flash_read_block(&data, 255); // 255 = ENTIRE FLASH | |
1955 if(data != 0xFF) | |
1956 { | |
1957 ext_flash_read_block_stop(); | |
1958 actualAddress = backup; | |
1959 return 0; | |
1960 } | |
1961 } | |
1962 ext_flash_read_block_stop(); | |
1963 actualAddress = backup; | |
1964 return 1; | |
1965 } | |
1966 | |
1967 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1968 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type) |
38 | 1969 { |
1970 uint32_t ringStart, ringStop; | |
1971 | |
1972 switch(type) | |
1973 { | |
1974 case EF_HEADER: | |
1975 ringStart = HEADERSTART; | |
1976 ringStop = HEADERSTOP; | |
1977 break; | |
1978 case EF_SAMPLE: | |
1979 ringStart = SAMPLESTART; | |
1980 ringStop = SAMPLESTOP; | |
1981 break; | |
1982 case EF_DEVICEDATA: | |
1983 ringStart = DDSTART; | |
1984 ringStop = DDSTOP; | |
1985 break; | |
1986 case EF_VPMDATA: | |
1987 ringStart = VPMSTART; | |
1988 ringStop = VPMSTOP; | |
1989 break; | |
1990 case EF_SETTINGS: | |
1991 ringStart = SETTINGSSTART; | |
1992 ringStop = SETTINGSSTOP; | |
1993 break; | |
1994 default: | |
1995 ringStart = FLASHSTART; | |
1996 ringStop = FLASHSTOP; | |
1997 break; | |
1998 } | |
1999 | |
2000 *pointer = (*pointer & 0xFFF) + 0x1000; | |
2001 | |
2002 if((*pointer < ringStart) || (*pointer >= ringStop)) | |
2003 *pointer = ringStart; | |
2004 } | |
2005 | |
2006 | |
2007 static void ef_erase_64K(uint32_t blocks) | |
2008 { | |
2009 for(uint32_t i = 0; i < blocks; i++) | |
2010 { | |
2011 wait_chip_not_busy(); | |
2012 write_spi(0x06,RELEASE);/* WREN */ | |
2013 write_spi(0xD8,HOLDCS);/* 64k erase cmd */ | |
2014 write_address(RELEASE); | |
2015 actualAddress += 0x10000; | |
2016 HAL_Delay(25); | |
2017 } | |
2018 } | |
2019 | |
2020 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2021 static void chip_unselect(void) |
38 | 2022 { |
2023 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_SET); // chip select | |
2024 } | |
2025 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2026 static void chip_select(void) |
38 | 2027 { |
2028 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select | |
2029 } | |
2030 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2031 static void error_led_on(void) |
38 | 2032 { |
2033 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); | |
2034 } | |
2035 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2036 static void error_led_off(void) |
38 | 2037 { |
2038 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); | |
2039 } | |
2040 | |
2041 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2042 static uint8_t read_spi(uint8_t unselect_CS_afterwards) |
38 | 2043 { |
2044 uint8_t byte; | |
2045 | |
2046 chip_select(); | |
2047 | |
2048 if(HAL_SPI_Receive(&hspiDisplay, &byte, 1, 10000) != HAL_OK) | |
2049 Error_Handler_extflash(); | |
2050 | |
2051 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
2052 { | |
2053 } | |
2054 if(unselect_CS_afterwards) | |
2055 chip_unselect(); | |
2056 | |
2057 return byte; | |
2058 } | |
2059 | |
2060 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2061 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards) |
38 | 2062 { |
2063 chip_select(); | |
2064 | |
2065 if(HAL_SPI_Transmit(&hspiDisplay, &data, 1, 10000) != HAL_OK) | |
2066 Error_Handler_extflash(); | |
2067 | |
2068 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
2069 { | |
2070 } | |
2071 if(unselect_CS_afterwards) | |
2072 chip_unselect(); | |
2073 } | |
2074 | |
2075 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2076 static void write_address(uint8_t unselect_CS_afterwards) |
38 | 2077 { |
2078 uint8_t hi, med ,lo; | |
2079 | |
2080 hi = (actualAddress >> 16) & 0xFF; | |
2081 med = (actualAddress >> 8) & 0xFF; | |
2082 lo = actualAddress & 0xFF; | |
2083 | |
2084 write_spi(hi, HOLDCS); | |
2085 write_spi(med, HOLDCS); | |
2086 write_spi(lo, unselect_CS_afterwards); | |
2087 } | |
2088 | |
2089 | |
2090 static void wait_chip_not_busy(void) | |
2091 { | |
2092 uint8_t status; | |
2093 | |
2094 chip_unselect(); | |
2095 | |
2096 write_spi(0x05,HOLDCS); /* RDSR */ | |
2097 status = read_spi(HOLDCS);/* read status */ | |
2098 while(status & 0x01) | |
2099 { | |
2100 HAL_Delay(1); | |
2101 status = read_spi(HOLDCS);/* read status */ | |
2102 } | |
2103 chip_unselect(); | |
2104 } | |
2105 | |
2106 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2107 static void ext_flash_incf_address(uint8_t type) |
38 | 2108 { |
2109 uint32_t ringStart, ringStop; | |
2110 | |
2111 actualAddress += 1; | |
2112 | |
2113 switch(type) | |
2114 { | |
2115 case EF_HEADER: | |
2116 ringStart = HEADERSTART; | |
2117 ringStop = HEADERSTOP; | |
2118 break; | |
2119 case EF_SAMPLE: | |
2120 ringStart = SAMPLESTART; | |
2121 ringStop = SAMPLESTOP; | |
2122 break; | |
2123 case EF_DEVICEDATA: | |
2124 ringStart = DDSTART; | |
2125 ringStop = DDSTOP; | |
2126 break; | |
2127 case EF_VPMDATA: | |
2128 ringStart = VPMSTART; | |
2129 ringStop = VPMSTOP; | |
2130 break; | |
2131 case EF_SETTINGS: | |
2132 ringStart = SETTINGSSTART; | |
2133 ringStop = SETTINGSSTOP; | |
2134 break; | |
2135 case EF_FIRMWARE: | |
2136 ringStart = FWSTART; | |
2137 ringStop = FWSTOP; | |
2138 break; | |
2139 case EF_FIRMWARE2: | |
2140 ringStart = FWSTART2; | |
2141 ringStop = FWSTOP2; | |
2142 break; | |
2143 default: | |
2144 ringStart = FLASHSTART; | |
2145 ringStop = FLASHSTOP; | |
2146 break; | |
2147 } | |
2148 | |
2149 if((actualAddress < ringStart) || (actualAddress > ringStop)) | |
2150 actualAddress = ringStart; | |
2151 } | |
2152 | |
2153 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2154 static void ext_flash_decf_address_ring(uint8_t type) |
38 | 2155 { |
2156 uint32_t ringStart, ringStop; | |
2157 | |
2158 switch(type) | |
2159 { | |
2160 case EF_HEADER: | |
2161 ringStart = HEADERSTART; | |
2162 ringStop = HEADERSTOP; | |
2163 break; | |
2164 case EF_SAMPLE: | |
2165 ringStart = SAMPLESTART; | |
2166 ringStop = SAMPLESTOP; | |
2167 break; | |
2168 case EF_DEVICEDATA: | |
2169 ringStart = DDSTART; | |
2170 ringStop = DDSTOP; | |
2171 break; | |
2172 case EF_VPMDATA: | |
2173 ringStart = VPMSTART; | |
2174 ringStop = VPMSTOP; | |
2175 break; | |
2176 case EF_SETTINGS: | |
2177 ringStart = SETTINGSSTART; | |
2178 ringStop = SETTINGSSTOP; | |
2179 break; | |
2180 case EF_FIRMWARE: | |
2181 ringStart = FWSTART; | |
2182 ringStop = FWSTOP; | |
2183 break; | |
2184 case EF_FIRMWARE2: | |
2185 ringStart = FWSTART2; | |
2186 ringStop = FWSTOP2; | |
2187 break; | |
2188 default: | |
2189 ringStart = FLASHSTART; | |
2190 ringStop = FLASHSTOP; | |
2191 break; | |
2192 } | |
2193 | |
2194 if((actualAddress <= ringStart) || (actualAddress > ringStop)) | |
2195 actualAddress = ringStop; | |
2196 else | |
2197 actualAddress -= 1; | |
2198 } | |
2199 | |
2200 | |
2201 static void ef_hw_rough_delay_us(uint32_t delayUs) | |
2202 { | |
2203 if(!delayUs) | |
2204 return; | |
2205 delayUs*= 12; | |
2206 while(delayUs--); | |
2207 return; | |
2208 } | |
2209 | |
2210 static void Error_Handler_extflash(void) | |
2211 { | |
2212 while(1) | |
2213 { | |
2214 } | |
2215 } | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2216 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2217 void ext_flash_CloseSector(void) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2218 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2219 uint32_t actualAddressBackup = actualAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2220 int i=0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2221 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2222 if(closeSectorAddress != 0) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2223 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2224 /* write some dummy bytes to the sector which is currently used for storing samples. This is done to "hide" problem if function is calles again */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2225 actualAddress = closeSectorAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2226 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2227 wait_chip_not_busy(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2228 write_spi(0x06,RELEASE); /* WREN */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2229 write_spi(0x02,HOLDCS); /* write cmd */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2230 write_address(HOLDCS); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2231 for(i = 0; i<8; i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2232 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2233 write_spi(0xA5,HOLDCS);/* write data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2234 actualAddress++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2235 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2236 /* byte with RELEASE */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2237 write_spi(0xA5,RELEASE);/* write data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2238 actualAddress = actualAddressBackup; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2239 closeSectorAddress = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2240 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2241 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2242 |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2243 /* This function validates a potential jump of sample address by checking the last sector for empty memory cells */ |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2244 uint8_t ext_flash_SampleOverrunValid(void) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2245 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2246 uint8_t jumpvalid = 1; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2247 uint32_t curAddress, actualaddrbackup; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2248 uint8_t tmpBuffer; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2249 uint8_t emptyCellCnt = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2250 |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2251 actualaddrbackup = actualAddress; |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2252 curAddress = SAMPLESTOP - 20; /* check the last 20 bytes of the last sample sector */ |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2253 actualAddress = curAddress; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2254 ext_flash_read_block_start(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2255 while(actualAddress < SAMPLESTOP) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2256 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2257 tmpBuffer = read_spi(HOLDCS);/* read data */ |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2258 if(tmpBuffer == 0xFF) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2259 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2260 emptyCellCnt++; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2261 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2262 actualAddress++; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2263 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2264 ext_flash_read_block_stop(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2265 |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2266 if(emptyCellCnt == 20) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2267 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2268 jumpvalid = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2269 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2270 actualAddress = actualaddrbackup; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2271 return jumpvalid; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2272 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2273 |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2274 uint32_t ext_flash_AnalyseSampleBuffer() |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2275 { |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2276 uint8_t sectorState[192]; /* samples are stored in 192 sector / 64k each */ |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2277 uint32_t curAddress = SAMPLESTART; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2278 uint8_t curSector = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2279 uint8_t samplebuffer[10]; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2280 uint32_t actualAddressBackup = actualAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2281 uint8_t emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2282 uint32_t i = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2283 uint8_t startedSectors = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2284 uint8_t lastSectorInuse = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2285 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2286 /* check if a sector is used till its end */ |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2287 for(curSector = 0; curSector < 192; curSector++) |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2288 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2289 sectorState[curSector] = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2290 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2291 curAddress = SAMPLESTART + (curSector * 0x10000); /* set address to begin of sector and check if it is used */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2292 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2293 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2294 for(uint32_t i=0;i<10;i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2295 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2296 samplebuffer[i] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2297 if(samplebuffer[i] == 0xFF) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2298 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2299 emptyCellCnt++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2300 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2301 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2302 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2303 if(emptyCellCnt == 10) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2304 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2305 sectorState[curSector] = SECTOR_NOTUSED; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2306 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2307 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2308 curAddress = SAMPLESTART + (curSector * 0x10000) + 0xFFF5; /* set address to end of sector and check if it is used */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2309 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2310 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2311 for(i=0;i<10;i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2312 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2313 samplebuffer[i] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2314 if(samplebuffer[i] == 0xFF) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2315 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2316 emptyCellCnt++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2317 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2318 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2319 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2320 if(emptyCellCnt == 10) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2321 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2322 sectorState[curSector] |= SECTOR_INUSE; /* will become SECTOR_EMPTY if start is NOTUSED */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2323 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2324 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2325 |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2326 for(i=0;i<192;i++) |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2327 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2328 if( sectorState[i] == SECTOR_INUSE) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2329 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2330 startedSectors++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2331 lastSectorInuse = i; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2332 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2333 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2334 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2335 if(startedSectors > 1) /* more than one sector is in used => ring buffer corrupted */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2336 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2337 if(startedSectors == 2) /* only fix issue if only two sectors are in used. Otherwise fixing will cause more worries than help */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2338 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2339 /* the logic behind healing of the problem is that the larger address is the oldest one => restore the largest address */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2340 curAddress = SAMPLESTART + (lastSectorInuse * 0x10000); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2341 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2342 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2343 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2344 while((emptyCellCnt < 10) && (actualAddress < curAddress + 0x10000)) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2345 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2346 samplebuffer[0] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2347 if(samplebuffer[0] == 0xFF) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2348 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2349 emptyCellCnt++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2350 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2351 else |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2352 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2353 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2354 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2355 actualAddress++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2356 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2357 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2358 actualAddress -= 10; /* step 10 bytes back to the start of free bytes */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2359 actualPointerSample = actualAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2360 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2361 closeSectorAddress = settingsGetPointer()->logFlashNextSampleStartAddress & 0xFFFF0000; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2362 closeSectorAddress += 0xFFF5; /* to be used once next time a dive is logged. Needed because NextSampleID is derived at every startup */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2363 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; /* store new position to be used for next dive */ |
557
2702bfa7b177
Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents:
538
diff
changeset
|
2364 ext_flash_CloseSector(); |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2365 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2366 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2367 actualAddress = actualAddressBackup; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2368 return startedSectors; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2369 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2370 |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2371 uint32_t ext_flash_read_profilelength_small_header(uint32_t smallHeaderAddr) |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2372 { |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2373 uint32_t profileLength = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2374 actualPointerSample = smallHeaderAddr; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2375 actualAddress = actualPointerSample; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2376 ext_flash_read_block_start(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2377 ext_flash_read_next_sample_part((uint8_t*)&profileLength, 3); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2378 ext_flash_close_read_sample(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2379 return profileLength; |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2380 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2381 |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2382 |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2383 /* |
38 | 2384 uint8_t ext_flash_erase_firmware_if_not_empty(void) |
2385 { | |
2386 const uint8_t TESTSIZE_FW = 4; | |
2387 | |
2388 uint8_t data[TESTSIZE_FW]; | |
2389 uint8_t notEmpty = 0; | |
2390 | |
2391 actualAddress = FWSTART; | |
2392 ext_flash_read_block_start(); | |
2393 for(int i = 0; i < TESTSIZE_FW; i++) | |
2394 { | |
2395 ext_flash_read_block(&data[i], EF_FIRMWARE); | |
2396 if(data[i] != 0xFF) | |
2397 notEmpty = 1; | |
2398 } | |
2399 ext_flash_read_block_stop(); | |
2400 | |
2401 if(notEmpty) | |
2402 { | |
2403 ext_flash_erase_firmware(); | |
2404 return 1; | |
2405 } | |
2406 else | |
2407 return 0; | |
2408 } | |
2409 | |
2410 uint8_t ext_flash_erase_firmware2_if_not_empty(void) | |
2411 { | |
2412 const uint8_t TESTSIZE_FW = 4; | |
2413 | |
2414 uint8_t data[TESTSIZE_FW]; | |
2415 uint8_t notEmpty = 0; | |
2416 | |
2417 actualAddress = FWSTART2; | |
2418 ext_flash_read_block_start(); | |
2419 for(int i = 0; i < TESTSIZE_FW; i++) | |
2420 { | |
2421 ext_flash_read_block(&data[i], EF_FIRMWARE2); | |
2422 if(data[i] != 0xFF) | |
2423 notEmpty = 1; | |
2424 } | |
2425 ext_flash_read_block_stop(); | |
2426 | |
2427 if(notEmpty) | |
2428 { | |
2429 ext_flash_erase_firmware2(); | |
2430 return 1; | |
2431 } | |
2432 else | |
2433 return 0; | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2434 }*/ |