Mercurial > public > ostc4
annotate Discovery/Src/externLogbookFlash.c @ 529:0e1db77b2aca
Added skip condition in custom view selection:
Decoplan may be selected even nothing was shown due to certain display conditions. These conditions have now been added to selection function to show deco plan only if data is available for visualization.
author | Ideenmodellierer |
---|---|
date | Tue, 15 Sep 2020 20:52:39 +0200 |
parents | 538eb1c976e9 |
children | b1eee27cd02b |
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; | |
571 uint8_t *pData; | |
572 const uint16_t lengthStandardNow = sizeof(SSettings); | |
573 uint8_t length_lo, length_hi; | |
574 uint16_t lengthOnEEPROM; | |
575 uint32_t header; | |
576 SSettings *pSettings = settingsGetPointer(); | |
577 | |
578 actualAddress = SETTINGSSTART; | |
579 | |
580 ext_flash_read_block_start(); | |
581 ext_flash_read_block(&length_lo, EF_SETTINGS); | |
582 ext_flash_read_block(&length_hi, EF_SETTINGS); | |
583 | |
427 | 584 while ((length_lo != 0xFF) && (length_hi != 0xFF)) /* get the latest stored setting block */ |
38 | 585 { |
427 | 586 lengthOnEEPROM = length_hi * 256; |
587 lengthOnEEPROM += length_lo; | |
588 if(lengthOnEEPROM <= lengthStandardNow) | |
38 | 589 { |
427 | 590 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); |
591 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) | |
592 { | |
593 returnValue = HAL_OK; | |
594 pSettings->header = header; | |
595 pData = (uint8_t *)pSettings + 4; /* header */ | |
596 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++) | |
597 ext_flash_read_block(&pData[i], EF_SETTINGS); | |
598 } | |
599 else | |
600 { | |
601 returnValue = HAL_ERROR; | |
602 } | |
38 | 603 } |
427 | 604 ext_flash_read_block(&length_lo, EF_SETTINGS); |
605 ext_flash_read_block(&length_hi, EF_SETTINGS); | |
606 } | |
607 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */ | |
608 ext_flash_decf_address_ring(EF_SETTINGS); | |
609 ext_flash_read_block_stop(); | |
610 | |
611 if(actualAddress > actualPointerSettings) /* the write pointer has not yet been set up probably */ | |
612 { | |
613 actualPointerSettings = actualAddress; | |
38 | 614 } |
615 ext_flash_read_block_stop(); | |
616 return returnValue; | |
617 } | |
618 | |
619 | |
620 | |
621 | |
622 /* ext_flash_start_new_dive_log_and_set_actualPointerSample | |
623 * prepares the write sample pointer | |
624 * to be used by ext_flash_write_sample() | |
625 * to be set in the * pHeaderPreDive | |
626 * for write with ext_flash_create_new_dive_log() and ext_flash_close_new_dive_log() | |
627 */ | |
628 void ext_flash_start_new_dive_log_and_set_actualPointerSample(uint8_t *pHeaderPreDive) | |
629 { | |
630 convert_Type data; | |
631 SSettings *settings = settingsGetPointer(); | |
632 | |
633 /* new 5. Jan. 2015 */ | |
634 actualPointerSample = settings->logFlashNextSampleStartAddress; | |
635 | |
636 if(!ext_flash_test_remaining_space_of_page_empty(actualPointerSample, 4)) | |
637 ext_flash_set_to_begin_of_next_page(&actualPointerSample, EF_SAMPLE); | |
638 | |
639 if((actualPointerSample < SAMPLESTART) || (actualPointerSample > SAMPLESTOP)) | |
640 actualPointerSample = SAMPLESTART; | |
641 | |
642 data.u32bit = actualPointerSample; | |
643 pHeaderPreDive[2] = data.u8bit.byteLow; | |
644 pHeaderPreDive[3] = data.u8bit.byteMidLow; | |
645 pHeaderPreDive[4] = data.u8bit.byteMidHigh; | |
646 /* to start sample writing and header etc. pp. */ | |
647 ext_flash_disable_protection_for_logbook(); | |
648 } | |
649 | |
650 | |
651 /* ext_flash_create_new_dive_log | |
652 * uses the first header without HEADER2OFFSET | |
653 * for the header it is not important to be complete | |
654 * and can be reconstructed | |
655 * ext_flash_start_new_dive_log_and_set_actualPointerSample() | |
656 * has to be called before to set the actualPointerSample | |
657 * in the header | |
658 * the following func writes to header to the ext_flash | |
659 */ | |
660 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive) | |
661 { | |
662 SSettings *settings; | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
663 uint8_t id; |
38 | 664 uint8_t header1, header2; |
665 | |
666 settings = settingsGetPointer(); | |
667 id = settings->lastDiveLogId; | |
668 | |
669 actualAddress = HEADERSTART + (0x800 * id); | |
670 ext_flash_read_block_start(); | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
671 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
|
672 ext_flash_read_block(&header2, EF_SAMPLE); /* does not matter because actual address is reset in write_block call */ |
38 | 673 ext_flash_read_block_stop(); |
674 | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
675 /* 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
|
676 /* the implementation fixes an issue which might happen at Cleanup_Ref_1 (in case of more then 254 dives) */ |
38 | 677 if((header1 == 0xFA) && (header2 == 0xFA)) |
678 { | |
679 id += 1; /* 0-255, auto rollover */ | |
680 if(id & 1) | |
681 { | |
682 actualAddress = HEADERSTART + (0x800 * id); | |
683 ext_flash_read_block_start(); | |
684 ext_flash_read_block(&header1, EF_SAMPLE); | |
685 ext_flash_read_block(&header2, EF_SAMPLE); | |
686 ext_flash_read_block_stop(); | |
687 if((header1 == 0xFA) && (header2 == 0xFA)) | |
688 id += 1; | |
689 } | |
690 } | |
691 else | |
692 { | |
693 id = 0; | |
694 } | |
695 | |
696 settings->lastDiveLogId = id; | |
697 actualPointerHeader = HEADERSTART + (0x800 * id); | |
698 | |
699 if(pHeaderPreDive != 0) | |
700 ef_write_block(pHeaderPreDive,HEADERSIZE, EF_HEADER, 0); | |
701 } | |
702 | |
703 | |
704 void ext_flash_close_new_dive_log(uint8_t *pHeaderPostDive ) | |
705 { | |
706 SSettings * settings = settingsGetPointer(); | |
707 uint8_t id; | |
708 convert_Type startAddress; | |
709 convert_Type data; | |
710 uint32_t backup; | |
711 | |
712 uint8_t sampleData[3]; | |
713 actualAddress = actualPointerSample; | |
714 sampleData[0] = 0xFD; | |
715 sampleData[1] = 0xFD; | |
716 ext_flash_write_sample(sampleData, 2); | |
717 | |
718 /* end of sample data, pointing to the last sample 0xFD | |
719 */ | |
720 actualAddress = actualPointerSample; // change hw 17.09.2015 | |
721 ext_flash_decf_address_ring(EF_SAMPLE); // 17.09.2015: this decf actualAddress only!! | |
722 actualPointerSample = actualAddress; // change hw 17.09.2015 | |
723 data.u32bit = actualPointerSample; | |
724 | |
725 pHeaderPostDive[5] = data.u8bit.byteLow; | |
726 pHeaderPostDive[6] = data.u8bit.byteMidLow; | |
727 pHeaderPostDive[7] = data.u8bit.byteMidHigh; | |
728 | |
729 /* take data written before, calculate length and write | |
730 SLogbookHeader has different order: length (byte# 8,9,10) prior to profile version (byte# 11) | |
731 */ | |
732 startAddress.u8bit.byteLow = pHeaderPostDive[2]; | |
733 startAddress.u8bit.byteMidLow = pHeaderPostDive[3]; | |
734 startAddress.u8bit.byteMidHigh = pHeaderPostDive[4]; | |
735 startAddress.u8bit.byteHigh = 0; | |
736 | |
737 if(startAddress.u32bit < actualPointerSample) | |
738 data.u32bit = 1 + actualPointerSample - startAddress.u32bit; | |
739 else | |
740 data.u32bit = 2 + (actualPointerSample - SAMPLESTART) + (SAMPLESTOP - startAddress.u32bit); | |
741 | |
742 pHeaderPostDive[8] = data.u8bit.byteLow; | |
743 pHeaderPostDive[9] = data.u8bit.byteMidLow; | |
744 pHeaderPostDive[10] = data.u8bit.byteMidHigh; | |
745 | |
746 /* set id and write post-dive-header | |
747 */ | |
748 id = settings->lastDiveLogId; | |
749 actualPointerHeader = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
750 | |
751 ef_write_block(pHeaderPostDive,HEADERSIZE, EF_HEADER, 0); | |
752 | |
753 /* write length at beginning of sample | |
754 and write proper beginning for next dive to actualPointerSample | |
755 */ | |
756 backup = actualPointerSample; | |
757 actualPointerSample = startAddress.u32bit; // is still 0xFF | |
758 sampleData[0] = data.u8bit.byteLow; | |
759 sampleData[1] = data.u8bit.byteMidLow; | |
760 sampleData[2] = data.u8bit.byteMidHigh; | |
761 ext_flash_overwrite_sample_without_erase(sampleData, 3); | |
762 | |
763 actualAddress = backup; | |
764 ext_flash_incf_address(EF_SAMPLE); | |
765 actualPointerSample = actualAddress; | |
766 ext_flash_enable_protection(); | |
767 } | |
768 | |
769 | |
770 void ext_flash_write_sample(uint8_t *pSample, uint16_t length) | |
771 { | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
772 uint32_t actualAdressBackup = 0; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
773 |
38 | 774 ef_write_block(pSample,length, EF_SAMPLE, 0); |
775 | |
776 SSettings *settings = settingsGetPointer(); | |
777 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
778 |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
779 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
|
780 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
781 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
|
782 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
783 actualAdressBackup = actualAddress; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
784 actualAddress = (actualAddress & 0xFFFF0000) + 0x00010000; /* Set to start of next 64k sector */ |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
785 if(actualAddress >= SAMPLESTOP) |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
786 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
787 actualAddress = SAMPLESTART; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
788 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
789 preparedPageAddress = actualAddress; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
790 ext_flash_erase64kB(); |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
791 actualAddress = actualAdressBackup; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
792 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
793 } |
38 | 794 } |
795 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
796 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length) |
38 | 797 { |
798 ef_write_block(pSample,length, EF_SAMPLE, 1); | |
799 } | |
800 | |
801 | |
802 uint8_t ext_flash_count_dive_headers(void) | |
803 { | |
804 uint8_t id = 0; | |
805 uint8_t counter = 0; | |
806 uint16_t headerStartData = 0x0000; | |
807 | |
808 id = settingsGetPointer()->lastDiveLogId; | |
809 | |
810 do | |
811 { | |
812 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
813 ext_flash_read_block_start(); | |
814 ext_flash_read_block_multi((uint8_t *)&headerStartData, 2, EF_HEADER); | |
815 ext_flash_read_block_stop(); | |
816 counter++; | |
817 id -=1; | |
818 } while((headerStartData == 0xFAFA) && (counter < 255)); | |
819 return (counter - 1); | |
820 } | |
821 | |
822 | |
823 void ext_flash_read_dive_header(uint8_t *pHeaderToFill, uint8_t StepBackwards) | |
824 { | |
825 SSettings *settings; | |
826 uint8_t id; | |
827 uint16_t i; | |
828 | |
829 settings = settingsGetPointer(); | |
830 id = settings->lastDiveLogId; | |
831 id -= StepBackwards; /* 0-255, auto rollover */ | |
832 | |
833 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
834 ext_flash_read_block_start(); | |
835 for(i = 0; i < HEADERSIZE; i++) | |
836 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
837 ext_flash_read_block_stop(); | |
838 | |
839 } | |
840 | |
841 void ext_flash_read_dive_header2(uint8_t *pHeaderToFill, uint8_t id, _Bool bOffset) | |
842 { | |
843 | |
844 uint16_t i; | |
845 actualAddress = HEADERSTART + (0x800 * id) ; | |
846 | |
847 if(bOffset) | |
848 actualAddress += HEADER2OFFSET; | |
849 ext_flash_read_block_start(); | |
850 for(i = 0; i < HEADERSIZE; i++) | |
851 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER); | |
852 ext_flash_read_block_stop(); | |
853 } | |
854 | |
855 | |
856 uint32_t ext_flash_read_dive_raw_with_double_header_1K(uint8_t *data, uint32_t max_size, uint8_t StepBackwards) | |
857 { | |
858 if(max_size < 0x800) | |
859 return 0; | |
860 | |
861 uint8_t id; | |
862 convert_Type dataStart, dataEnd; | |
863 uint32_t LengthAll = 0; | |
864 | |
865 id = settingsGetPointer()->lastDiveLogId; | |
866 id -= StepBackwards; /* 0-255, auto rollover */ | |
867 | |
868 // clear data | |
869 for(int i=0;i<0x800;i++) | |
870 data[i] = 0xFF; | |
871 | |
872 // copy primary/pre-dive | |
873 actualAddress = HEADERSTART + (0x800 * id); | |
874 ext_flash_read_block_start(); | |
875 for(int i = 0; i < HEADERSIZE; i++) | |
876 ext_flash_read_block(&data[i], EF_HEADER); | |
877 ext_flash_read_block_stop(); | |
878 | |
879 // copy main/secondary/post-dive | |
880 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
881 ext_flash_read_block_start(); | |
882 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
883 ext_flash_read_block(&data[i], EF_HEADER); | |
884 ext_flash_read_block_stop(); | |
885 | |
886 // data | |
887 | |
888 dataStart.u8bit.byteHigh = 0; | |
889 dataStart.u8bit.byteLow = data[0x402]; | |
890 dataStart.u8bit.byteMidLow = data[0x403]; | |
891 dataStart.u8bit.byteMidHigh = data[0x404]; | |
892 | |
893 dataEnd.u8bit.byteHigh = 0; | |
894 dataEnd.u8bit.byteLow = data[0x405]; | |
895 dataEnd.u8bit.byteMidLow = data[0x406]; | |
896 dataEnd.u8bit.byteMidHigh = data[0x407]; | |
897 | |
898 actualPointerSample = dataStart.u32bit; | |
899 if(dataEnd.u32bit >= dataStart.u32bit) | |
900 LengthAll = 1 + dataEnd.u32bit - dataStart.u32bit; | |
901 else | |
902 LengthAll = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
903 | |
904 LengthAll += 0x800; | |
905 | |
906 if(LengthAll > max_size) | |
907 return 0x800; | |
908 | |
909 actualAddress = actualPointerSample; | |
910 ext_flash_read_block_start(); | |
911 for(uint32_t i = 0x800; i < LengthAll; i++) | |
912 ext_flash_read_block(&data[i], EF_SAMPLE); | |
913 ext_flash_read_block_stop(); | |
914 return LengthAll; | |
915 } | |
916 | |
917 void ext_flash_write_dive_raw_with_double_header_1K(uint8_t *data, uint32_t length) | |
918 { | |
919 convert_Type dataStart, dataEnd; | |
920 SLogbookHeader headerTemp; | |
921 | |
922 // set actualPointerSample and get pointer to sample storage and disable flash write protect | |
923 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t *)&headerTemp); | |
924 | |
925 dataStart.u8bit.byteHigh = 0; | |
926 dataStart.u8bit.byteLow = headerTemp.pBeginProfileData[0]; | |
927 dataStart.u8bit.byteMidLow = headerTemp.pBeginProfileData[1]; | |
928 dataStart.u8bit.byteMidHigh = headerTemp.pBeginProfileData[2]; | |
929 | |
930 dataEnd.u32bit = dataStart.u32bit + length - 0x801; | |
931 if(dataEnd.u32bit > SAMPLESTOP) | |
932 dataEnd.u32bit -= SAMPLESTOP + SAMPLESTART - 1; | |
933 | |
934 data[0x002] = data[0x402] = dataStart.u8bit.byteLow; | |
935 data[0x003] = data[0x403] = dataStart.u8bit.byteMidLow; | |
936 data[0x004] = data[0x404] = dataStart.u8bit.byteMidHigh; | |
937 data[0x005] = data[0x405] = dataEnd.u8bit.byteLow; | |
938 data[0x006] = data[0x406] = dataEnd.u8bit.byteMidLow; | |
939 data[0x007] = data[0x407] = dataEnd.u8bit.byteMidHigh; | |
940 | |
941 // set actualPointerHeader to next free header and update lastDiveLogId | |
942 ext_flash_create_new_dive_log(0); | |
943 | |
944 // copy header data | |
945 ef_write_block(data,0x800,EF_HEADER, 1); | |
946 | |
947 // copy sample data | |
948 ef_write_block(&data[0x800], length-0x800, EF_SAMPLE, 1); | |
949 | |
950 // update logFlashNextSampleStartAddress | |
951 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; | |
952 } | |
953 | |
954 | |
955 // =============================================================================== | |
956 // ext_flash_read_header_memory | |
957 /// @brief This function returns the entire header space 1:1 | |
958 /// @date 04-April-2016 | |
959 /// | |
960 /// @param *data 256KB output | |
961 // =============================================================================== | |
962 void ext_flash_read_header_memory(uint8_t *data) | |
963 { | |
964 actualAddress = HEADERSTART; | |
965 actualPointerHeader = actualAddress; | |
966 ext_flash_read_block_start(); | |
967 for(int i=0;i<8;i++) | |
968 ext_flash_read_block_multi(&data[0x8000 * i], 0x8000, EF_HEADER); | |
969 ext_flash_read_block_stop(); | |
970 } | |
971 | |
972 | |
973 // =============================================================================== | |
463 | 974 // ext_flash_write_header_memory |
38 | 975 /// @brief This function erases and overwrites the entire logbook header block |
976 /// @date 04-April-2016 | |
977 /// | |
978 /// @param *data 256KB input of header memory 1:1 | |
979 // =============================================================================== | |
980 void ext_flash_write_header_memory(uint8_t *data) | |
981 { | |
982 actualAddress = HEADERSTART; | |
983 actualPointerHeader = actualAddress; | |
984 ef_write_block(data, 0x40000, EF_HEADER, 0); | |
985 } | |
986 | |
463 | 987 void ext_flash_read_sample_memory(uint8_t *data,uint16_t blockId) |
988 { | |
989 actualAddress = SAMPLESTART; | |
990 actualAddress += blockId * 0x8000; /* add 32k Block offset */ | |
991 actualPointerSample = actualAddress; | |
992 ext_flash_read_block_start(); | |
993 ext_flash_read_block_multi(data, 0x8000, EF_SAMPLE); | |
994 ext_flash_read_block_stop(); | |
995 } | |
996 | |
997 void ext_flash_write_sample_memory(uint8_t *data,uint16_t blockId) | |
998 { | |
999 actualAddress = SAMPLESTART; | |
1000 actualAddress += blockId * 0x8000; /* add 32k Block offset */ | |
1001 actualPointerSample = actualAddress; | |
1002 ef_write_block(data, 0x8000, EF_SAMPLE,0); | |
1003 } | |
1004 | |
38 | 1005 |
1006 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes) | |
1007 { | |
1008 SSettings *settings = settingsGetPointer(); | |
1009 uint8_t id; | |
1010 convert_Type dataStart, dataEnd; | |
1011 uint8_t header1, header2; | |
1012 | |
1013 id = settings->lastDiveLogId; | |
1014 id -= StepBackwards; /* 0-255, auto rollover */ | |
1015 # | |
1016 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1017 actualPointerHeader = actualAddress; | |
1018 | |
1019 ext_flash_read_block_start(); | |
1020 /* little endian */ | |
1021 ext_flash_read_block(&header1, EF_HEADER); | |
1022 ext_flash_read_block(&header2, EF_HEADER); | |
1023 dataStart.u8bit.byteHigh = 0; | |
1024 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1025 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1026 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1027 dataEnd.u8bit.byteHigh = 0; | |
1028 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
1029 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
1030 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
1031 ext_flash_read_block_stop(); | |
1032 | |
1033 actualPointerSample = dataStart.u32bit; | |
1034 if(dataEnd.u32bit >= dataStart.u32bit) | |
1035 LengthLeftSampleRead = 1 + dataEnd.u32bit - dataStart.u32bit; | |
1036 else | |
1037 LengthLeftSampleRead = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit); | |
1038 *totalNumberOfBytes = LengthLeftSampleRead; | |
1039 | |
1040 actualAddress = actualPointerSample; | |
1041 ext_flash_read_block_start(); | |
1042 } | |
1043 | |
1044 | |
1045 void ext_flash_read_next_sample_part(uint8_t *pSample, uint8_t length) | |
1046 { | |
1047 for(uint16_t i = 0; i < length; i++) | |
1048 ext_flash_read_block(&pSample[i], EF_SAMPLE); | |
1049 } | |
1050 | |
1051 | |
1052 void ext_flash_close_read_sample(void) | |
1053 { | |
1054 actualPointerSample = actualAddress; | |
1055 ext_flash_read_block_stop(); | |
1056 } | |
1057 | |
1058 | |
1059 void ext_flash_set_entry_point(void) | |
1060 { | |
1061 entryPoint = actualAddress; | |
1062 } | |
1063 | |
1064 | |
1065 void ext_flash_reopen_read_sample_at_entry_point(void) | |
1066 { | |
1067 error_led_on(); | |
1068 chip_unselect(); | |
1069 wait_chip_not_busy(); | |
1070 | |
1071 actualAddress = entryPoint; | |
1072 ext_flash_read_block_start(); | |
1073 error_led_off(); | |
1074 } | |
1075 | |
1076 /* | |
1077 uint8_t ext_flash_point_to_64k_block_in_headerSpace(uint8_t logId) | |
1078 { | |
1079 uint32_t pointerToData = logId * 0x800; | |
1080 | |
1081 return pointerToData / 0x10000; | |
1082 } | |
1083 */ | |
1084 | |
1085 | |
1086 // =============================================================================== | |
1087 // ext_flash_repair_dive_numbers_starting_count_helper | |
1088 /// @brief | |
1089 /// @date 22-June-2016 | |
1090 | |
1091 // =============================================================================== | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1092 static uint16_t ext_flash_repair_dive_numbers_starting_count_helper(uint8_t *data, uint8_t *change64k, uint16_t startNumber, uint8_t lastLogId) |
38 | 1093 { |
1094 const uint32_t headerStep = 0x800; | |
1095 uint8_t actualLogId = 0; | |
1096 uint16_t oldNumber = 0; | |
1097 uint16_t actualNumber = 0; | |
1098 SLogbookHeader *ptrLogbookHeader = 0; | |
1099 | |
1100 if(startNumber == 0) | |
1101 return 0; | |
1102 | |
1103 actualNumber = startNumber - 1; | |
1104 | |
282 | 1105 // where is the oldest dive (Which is now getting startNumber) |
38 | 1106 // use first header for ease (without HEADER2OFFSET for end of dive header) |
1107 // compare for lastLogId to prevent endless loop | |
1108 | |
1109 if(*(uint16_t*)&data[lastLogId * headerStep] != 0xFAFA) | |
1110 return 0; | |
1111 | |
1112 actualLogId = lastLogId - 1; | |
1113 while((*(uint16_t*)&data[actualLogId * headerStep] == 0xFAFA) && (actualLogId != lastLogId)) | |
1114 { | |
1115 actualLogId--; | |
1116 } | |
1117 | |
1118 // now pointing to one behind the last | |
1119 while(actualLogId != lastLogId) | |
1120 { | |
1121 actualLogId++; | |
1122 actualNumber++; | |
1123 ptrLogbookHeader = (SLogbookHeader *)&data[actualLogId * headerStep]; | |
1124 | |
1125 oldNumber = ptrLogbookHeader->diveNumber; | |
1126 if(oldNumber != actualNumber) | |
1127 { | |
1128 // change64k[ext_flash_point_to_64k_block_in_headerSpace(actualLogId )] = 1; | |
1129 change64k[(actualLogId * 0x800)/0x10000] = 1; | |
1130 ptrLogbookHeader->diveNumber = actualNumber; | |
1131 ptrLogbookHeader = (SLogbookHeader *)(&data[actualLogId * headerStep] + HEADER2OFFSET); | |
1132 ptrLogbookHeader->diveNumber = actualNumber; | |
1133 } | |
1134 } | |
1135 | |
1136 return actualNumber; | |
1137 } | |
1138 | |
1139 // =============================================================================== | |
1140 // ext_flash_repair_SPECIAL_dive_numbers_starting_count_with | |
1141 /// @brief This function | |
1142 /// @date 04-April-2016 | |
282 | 1143 /// problem (160621): 64K blocks (32 dives) in the new flash memory chip |
1144 /// This block needs to be deleted | |
1145 /// these where only 4KB block before | |
38 | 1146 /// @output endCount, last diveNumber |
1147 | |
1148 // =============================================================================== | |
1149 uint16_t ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) | |
1150 { | |
1151 uint32_t logCopyDataPtr = 0; | |
1152 uint8_t *data; | |
1153 uint16_t lastCount; | |
282 | 1154 uint8_t listOfChanged64kBlocks[8]; // 32 dives each 64K |
38 | 1155 |
1156 logCopyDataPtr = getFrame(97); | |
1157 data = (uint8_t *)logCopyDataPtr; | |
1158 | |
1159 for(int i=0;i<8;i++) | |
1160 listOfChanged64kBlocks[i] = 0; | |
1161 | |
1162 actualAddress = HEADERSTART; | |
1163 ext_flash_read_block_start(); | |
1164 ext_flash_read_block_multi(data,0x100000,EF_HEADER); | |
1165 ext_flash_read_block_stop(); | |
1166 | |
1167 lastCount = ext_flash_repair_dive_numbers_starting_count_helper(data, listOfChanged64kBlocks, startCount, settingsGetPointer()->lastDiveLogId); | |
1168 | |
1169 for(int i=0;i<8;i++) | |
1170 { | |
1171 if(listOfChanged64kBlocks[i] != 0) | |
1172 { | |
1173 actualPointerHeader = HEADERSTART + (i * 0x10000); | |
1174 ef_write_block(&data[i * 0x10000], 0x10000, EF_HEADER, 0); | |
1175 } | |
1176 } | |
1177 | |
1178 releaseFrame(97,logCopyDataPtr); | |
1179 if(settingsGetPointer()->totalDiveCounter < lastCount) | |
1180 { | |
1181 settingsGetPointer()->totalDiveCounter = lastCount; | |
1182 } | |
1183 return lastCount; | |
1184 } | |
1185 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1186 /* |
38 | 1187 void OLD_ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount) |
1188 { | |
1189 uint16_t counterStorage[256]; | |
1190 uint8_t start = 0xFF; | |
1191 uint32_t logCopyDataPtr = 0; | |
1192 uint8_t *data; | |
1193 uint8_t startAbsolute = 0; | |
1194 int16_t count = 0; | |
1195 _Bool repair = 0; | |
1196 uint8_t startBackup = 0; | |
1197 | |
1198 SLogbookHeader tempLogbookHeader; | |
1199 SLogbookHeader *ptrHeaderInData1a; | |
1200 SLogbookHeader *ptrHeaderInData1b; | |
1201 SLogbookHeader *ptrHeaderInData2a; | |
1202 SLogbookHeader *ptrHeaderInData2b; | |
1203 | |
1204 logCopyDataPtr = getFrame(97); | |
1205 data = (uint8_t *)logCopyDataPtr; | |
1206 ptrHeaderInData1a = (SLogbookHeader *)logCopyDataPtr; | |
1207 ptrHeaderInData1b = (SLogbookHeader *)(logCopyDataPtr + HEADER2OFFSET); | |
1208 ptrHeaderInData2a = (SLogbookHeader *)(logCopyDataPtr + 0x800); | |
1209 ptrHeaderInData2b = (SLogbookHeader *)(logCopyDataPtr + 0x800 + HEADER2OFFSET); | |
1210 | |
1211 // get data | |
1212 for(int StepBackwards = 0; StepBackwards < 255; StepBackwards++) | |
1213 { | |
1214 logbook_getHeader(StepBackwards, &tempLogbookHeader); | |
1215 counterStorage[StepBackwards+1] = tempLogbookHeader.diveNumber; | |
1216 if(tempLogbookHeader.diveHeaderStart == 0xFAFA) | |
1217 start = StepBackwards; | |
1218 else | |
1219 break; | |
1220 } | |
1221 | |
1222 if(start == 0xFF) | |
1223 return; | |
1224 | |
1225 count = start + 1; | |
1226 startAbsolute = settingsGetPointer()->lastDiveLogId; | |
1227 | |
1228 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1229 |
38 | 1230 if(start%2) |
1231 { | |
1232 if(counterStorage[start] != startCount) | |
1233 { | |
1234 // clear data | |
1235 for(int i=0;i<0x800*2;i++) | |
1236 data[i] = 0xFF; | |
1237 | |
1238 uint8_t id = settingsGetPointer()->lastDiveLogId; | |
1239 id -= start; // 0-255, auto rollover | |
1240 | |
1241 // copy primary/pre-dive | |
1242 actualAddress = HEADERSTART + (0x800 * id); | |
1243 ext_flash_read_block_start(); | |
1244 for(int i = 0; i < HEADERSIZE; i++) | |
1245 ext_flash_read_block(&data[i], EF_HEADER); | |
1246 ext_flash_read_block_stop(); | |
1247 | |
1248 // copy main/secondary/post-dive | |
1249 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1250 ext_flash_read_block_start(); | |
1251 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1252 ext_flash_read_block(&data[i], EF_HEADER); | |
1253 ext_flash_read_block_stop(); | |
1254 | |
1255 // repair | |
1256 ptrHeaderInData2a->diveNumber = startCount; | |
1257 ptrHeaderInData2b->diveNumber = startCount; | |
1258 startCount++; | |
1259 | |
1260 // write | |
1261 actualAddress = HEADERSTART + (0x800 * (id-1)); | |
1262 ef_write_block(data,0x800*2,EF_HEADER, 0); | |
1263 } | |
1264 start--; | |
1265 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1266 |
38 | 1267 // for(int count = start; count > -1; count -= 2) |
1268 | |
1269 while(count > 0) | |
1270 { | |
1271 // clear data | |
1272 for(int i=0;i<0x1000;i++) | |
1273 data[i] = 0xFF; | |
1274 | |
1275 repair = 0; | |
1276 | |
1277 startBackup = startAbsolute; | |
1278 | |
1279 if(startAbsolute%2) // 0x800 to 0x1000 | |
1280 { | |
1281 // copy second pre-dive | |
1282 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1283 ext_flash_read_block_start(); | |
1284 for(int i = 0x800; i < HEADERSIZE+0x800; i++) | |
1285 ext_flash_read_block(&data[i], EF_HEADER); | |
1286 ext_flash_read_block_stop(); | |
1287 | |
1288 // copy second post-dive | |
1289 actualAddress = HEADERSTART + HEADER2OFFSET + (0x800 * startAbsolute); | |
1290 ext_flash_read_block_start(); | |
1291 for(int i = 0xC00; i < HEADERSIZE+0xC00; i++) | |
1292 ext_flash_read_block(&data[i], EF_HEADER); | |
1293 ext_flash_read_block_stop(); | |
1294 | |
1295 if(counterStorage[count] != startCount) | |
1296 { | |
1297 ptrHeaderInData2a->diveNumber = startCount; | |
1298 ptrHeaderInData2b->diveNumber = startCount; | |
1299 repair = 1; | |
1300 } | |
1301 startCount += 1; | |
1302 | |
1303 startAbsolute -= 1; | |
1304 count -= 1; | |
1305 | |
1306 if(count > 0) | |
1307 { | |
1308 // copy first pre-dive | |
1309 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1310 ext_flash_read_block_start(); | |
1311 for(int i = 0; i < HEADERSIZE; i++) | |
1312 ext_flash_read_block(&data[i], EF_HEADER); | |
1313 ext_flash_read_block_stop(); | |
1314 | |
1315 // copy first post-dive | |
1316 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1317 ext_flash_read_block_start(); | |
1318 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1319 ext_flash_read_block(&data[i], EF_HEADER); | |
1320 ext_flash_read_block_stop(); | |
1321 | |
1322 if(counterStorage[count] != startCount) | |
1323 { | |
1324 ptrHeaderInData1a->diveNumber = startCount; | |
1325 ptrHeaderInData1b->diveNumber = startCount; | |
1326 repair = 1; | |
1327 } | |
1328 startCount += 1; | |
1329 | |
1330 startAbsolute -= 1; | |
1331 count -= 1; | |
1332 } | |
1333 } | |
1334 else | |
1335 { | |
1336 // copy first pre-dive | |
1337 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1338 ext_flash_read_block_start(); | |
1339 for(int i = 0; i < HEADERSIZE; i++) | |
1340 ext_flash_read_block(&data[i], EF_HEADER); | |
1341 ext_flash_read_block_stop(); | |
1342 | |
1343 // copy first post-dive | |
1344 actualAddress = HEADERSTART + (0x800 * startAbsolute); | |
1345 ext_flash_read_block_start(); | |
1346 for(int i = 0x400; i < HEADERSIZE+0x400; i++) | |
1347 ext_flash_read_block(&data[i], EF_HEADER); | |
1348 ext_flash_read_block_stop(); | |
1349 | |
1350 if(counterStorage[count] != startCount) | |
1351 { | |
1352 ptrHeaderInData1a->diveNumber = startCount; | |
1353 ptrHeaderInData1b->diveNumber = startCount; | |
1354 repair = 1; | |
1355 } | |
1356 startCount += 1; | |
1357 | |
1358 startAbsolute -= 1; | |
1359 count -= 1; | |
1360 } | |
1361 | |
1362 // write | |
1363 if(repair) | |
1364 { | |
1365 actualPointerHeader = HEADERSTART + (0x1000 * startBackup%2); | |
1366 ef_write_block(data,0x1000,EF_HEADER, 0); | |
1367 } | |
1368 } | |
1369 releaseFrame(97,logCopyDataPtr); | |
1370 settingsGetPointer()->totalDiveCounter = startCount; | |
1371 } | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1372 */ |
38 | 1373 |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1374 uint8_t ext_dive_log_consistent(void) |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1375 { |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1376 uint8_t ret = 0; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1377 uint8_t header1, header2; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1378 uint8_t id; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1379 convert_Type dataStart; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1380 |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1381 SSettings *settings = settingsGetPointer(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1382 id = settings->lastDiveLogId; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1383 |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1384 actualAddress = HEADERSTART + (0x800 * id); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1385 ext_flash_read_block_start(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1386 ext_flash_read_block(&header1, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1387 ext_flash_read_block(&header2, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1388 dataStart.u8bit.byteHigh = 0; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1389 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1390 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1391 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1392 ext_flash_read_block_stop(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1393 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */ |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1394 { |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1395 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1396 ext_flash_read_block_start(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1397 ext_flash_read_block(&header1, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1398 ext_flash_read_block(&header2, EF_HEADER); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1399 ext_flash_read_block_stop(); |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1400 if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */ |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1401 { |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1402 ret = 1; /* => lastDiveLogID points to a valid dive entry */ |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1403 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1404 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1405 return ret; |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1406 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1407 |
38 | 1408 // =============================================================================== |
1409 // ext_flash_repair_dive_log | |
1410 /// @brief This function | |
1411 /// does set | |
1412 /// logFlashNextSampleStartAddress | |
1413 /// and | |
1414 /// lastDiveLogId | |
1415 /// | |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
1416 |
38 | 1417 void ext_flash_repair_dive_log(void) |
1418 { | |
1419 uint8_t header1, header2; | |
1420 convert_Type dataStart; | |
1421 | |
1422 for(int id = 0; id < 255;id++) | |
1423 { | |
1424 actualAddress = HEADERSTART + (0x800 * id); | |
1425 ext_flash_read_block_start(); | |
1426 ext_flash_read_block(&header1, EF_HEADER); | |
1427 ext_flash_read_block(&header2, EF_HEADER); | |
1428 dataStart.u8bit.byteHigh = 0; | |
1429 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1430 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1431 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1432 ext_flash_read_block_stop(); | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1433 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */ |
38 | 1434 { |
1435 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1436 ext_flash_read_block_start(); | |
1437 ext_flash_read_block(&header1, EF_HEADER); | |
1438 ext_flash_read_block(&header2, EF_HEADER); | |
1439 ext_flash_read_block_stop(); | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1440 if((header1 != 0xFA) || (header2 != 0xFA)) /* Secondary header was not written at the end of a dive */ |
38 | 1441 { |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
1442 actualPointerSample = dataStart.u32bit; /* Set datapointer to position stored in header written at beginning of dive */ |
38 | 1443 actualAddress = actualPointerSample; |
1444 logbook_recover_brokenlog(id); | |
1445 SSettings *settings = settingsGetPointer(); | |
1446 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1447 } | |
1448 } | |
1449 } | |
1450 ext_flash_find_start(); | |
1451 } | |
1452 | |
1453 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1454 static void ext_flash_find_start(void) |
38 | 1455 { |
1456 uint8_t id; | |
1457 uint8_t header1, header2; | |
1458 convert_Type dataStart, dataEnd; | |
1459 | |
429
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
1460 /* TODO Cleanup_Ref_1: cleanup logFlashNextSampleStartAddress and lastDiveLogId */ |
7f351c25608a
Marked possible code improvment for future activities:
ideenmodellierer
parents:
427
diff
changeset
|
1461 /* 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
|
1462 /* This is avoided by Cleanup_Ref2 */ |
441
9a9e4908ce2e
fix potential issue with >255 dives in the logbook
heinrichsweikamp
parents:
429
diff
changeset
|
1463 for(id = 0; id <= 255;id++) |
38 | 1464 { |
1465 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1466 ext_flash_read_block_start(); | |
1467 ext_flash_read_block(&header1, EF_HEADER); | |
1468 ext_flash_read_block(&header2, EF_HEADER); | |
1469 dataStart.u8bit.byteHigh = 0; | |
1470 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1471 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1472 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1473 ext_flash_read_block_stop(); | |
1474 if((header1 == 0xFF) && (header2 == 0xFF)) | |
1475 { | |
1476 break; | |
1477 } | |
1478 } | |
1479 id--; | |
1480 SSettings *settings = settingsGetPointer(); | |
1481 settings->lastDiveLogId = id; | |
1482 | |
1483 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET; | |
1484 actualPointerHeader = actualAddress; | |
1485 | |
1486 ext_flash_read_block_start(); | |
1487 | |
1488 ext_flash_read_block(&header1, EF_HEADER); | |
1489 ext_flash_read_block(&header2, EF_HEADER); | |
1490 dataStart.u8bit.byteHigh = 0; | |
1491 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER); | |
1492 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER); | |
1493 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER); | |
1494 dataEnd.u8bit.byteHigh = 0; | |
1495 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER); | |
1496 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER); | |
1497 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER); | |
1498 ext_flash_read_block_stop(); | |
1499 | |
1500 //Find free space | |
1501 if((header1 == 0xFA) && (header2 == 0xFA)) | |
1502 { | |
1503 uint8_t uiRead = 0; | |
1504 int countFF = 0; | |
1505 //End of last complete dive | |
1506 actualPointerSample = dataEnd.u32bit ; | |
1507 actualAddress = actualPointerSample; | |
1508 //Check if there are samples of dives with less than half a minute | |
1509 while(true) | |
1510 { | |
1511 ext_flash_read_block_start(); | |
1512 ext_flash_read_block(&uiRead, EF_SAMPLE); | |
1513 if(uiRead == 0xFF) | |
1514 countFF++; | |
1515 else | |
1516 countFF = 0; | |
1517 | |
1518 | |
1519 | |
1520 if(countFF == 10) | |
1521 { | |
1522 actualAddress -= 10; | |
1523 break; | |
1524 } | |
1525 | |
1526 //New page: clear | |
1527 if(ext_flash_erase_if_on_page_start()) | |
1528 break; | |
1529 } | |
1530 // Set new start address | |
1531 actualPointerSample = actualAddress; | |
1532 settings->logFlashNextSampleStartAddress = actualPointerSample; | |
1533 } | |
1534 else | |
1535 { | |
1536 settings->logFlashNextSampleStartAddress = SAMPLESTART; | |
1537 } | |
1538 } | |
1539 | |
1540 | |
1541 #endif | |
1542 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1543 static void ext_flash_disable_protection(void) |
38 | 1544 { |
1545 /* | |
1546 extFlashStatusBit8_Type status; | |
1547 | |
1548 status.uw = 0; | |
1549 | |
1550 wait_chip_not_busy(); | |
1551 write_spi(0x50,RELEASE); // EWSR | |
1552 write_spi(0x01,HOLDCS); // WRSR | |
1553 write_spi(status.uw,RELEASE); // new status | |
1554 */ | |
1555 } | |
1556 | |
1557 | |
1558 void ext_flash_disable_protection_for_logbook(void) | |
1559 { | |
1560 /* | |
1561 extFlashStatusBit8_Type status; | |
1562 | |
1563 status.uw = 0; | |
1564 status.ub.BlockProtect0 = 1; | |
1565 status.ub.BlockProtect1 = 0; | |
1566 status.ub.BlockProtect2 = 1; | |
1567 status.ub.BlockProtect3 = 0; // not set in OSTC3. Why? | |
1568 | |
1569 wait_chip_not_busy(); | |
1570 write_spi(0x50,RELEASE); // EWSR | |
1571 write_spi(0x01,HOLDCS); // WRSR | |
1572 write_spi(status.uw,RELEASE); // new status | |
1573 */ | |
1574 } | |
1575 | |
1576 | |
1577 void ext_flash_enable_protection(void) | |
1578 { | |
1579 /* | |
1580 extFlashStatusBit8_Type status; | |
1581 | |
1582 status.uw = 0; | |
1583 status.ub.BlockProtect0 = 1; | |
1584 status.ub.BlockProtect1 = 1; | |
1585 status.ub.BlockProtect2 = 1; | |
1586 status.ub.BlockProtect3 = 1; // not set in OSTC3. Why? | |
1587 | |
1588 wait_chip_not_busy(); | |
1589 write_spi(0x50,RELEASE); // EWSR | |
1590 write_spi(0x01,HOLDCS); // WRSR | |
1591 write_spi(status.uw,RELEASE); // new status | |
1592 */ | |
1593 } | |
1594 | |
1595 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1596 /*void ext_flash_erase_chip(void) |
38 | 1597 { |
1598 wait_chip_not_busy(); | |
1599 write_spi(0x06,RELEASE); | |
1600 write_spi(0x60,RELEASE); | |
1601 wait_chip_not_busy(); | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1602 }*/ |
38 | 1603 |
1604 void ext_flash_erase_firmware(void) | |
1605 { | |
1606 uint32_t size, blocks_64k; | |
1607 | |
1608 actualAddress = FWSTART; | |
1609 size = 1 + FWSTOP - FWSTART; | |
1610 blocks_64k = size / 0x10000; | |
1611 ef_erase_64K(blocks_64k); | |
1612 } | |
1613 | |
1614 void ext_flash_erase_firmware2(void) | |
1615 { | |
1616 uint32_t size, blocks_64k; | |
1617 | |
1618 actualAddress = FWSTART2; | |
1619 size = 1 + FWSTOP2 - FWSTART2; | |
1620 blocks_64k = size / 0x10000; | |
1621 ef_erase_64K(blocks_64k); | |
1622 } | |
1623 | |
1624 | |
1625 | |
1626 void ext_flash_erase_logbook(void) | |
1627 { | |
1628 uint32_t size, blocks_64k; | |
1629 | |
1630 ext_flash_disable_protection_for_logbook(); | |
1631 | |
1632 actualAddress = SAMPLESTART; | |
1633 size = 1 + SAMPLESTOP - SAMPLESTART; | |
1634 blocks_64k = size / 0x10000; | |
1635 ef_erase_64K(blocks_64k); | |
1636 | |
1637 actualAddress = HEADERSTART; | |
1638 size = 1 + HEADERSTOP - HEADERSTART; | |
1639 blocks_64k = size / 0x10000; | |
1640 ef_erase_64K(blocks_64k); | |
1641 | |
1642 ext_flash_enable_protection(); | |
1643 } | |
1644 | |
1645 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1646 static void ext_flash_erase4kB(void) |
38 | 1647 { |
1648 wait_chip_not_busy(); | |
1649 write_spi(0x06,RELEASE);/* WREN */ | |
1650 write_spi(0x20,HOLDCS);/* sector erase cmd */ | |
1651 write_address(RELEASE); | |
1652 } | |
1653 | |
282 | 1654 /* be careful - might not work with entire family and other products |
38 | 1655 * see page 14 of LOGBOOK_V3_S25FS-S_00-271247.pdf |
1656 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1657 static void ext_flash_erase32kB(void) |
38 | 1658 { |
1659 uint32_t actualAddress_backup; | |
1660 | |
1661 actualAddress_backup = actualAddress; | |
1662 actualAddress = 0; | |
1663 wait_chip_not_busy(); | |
1664 write_spi(0x06,RELEASE);/* WREN */ | |
1665 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1666 write_address(RELEASE); | |
1667 actualAddress = actualAddress_backup; | |
1668 } | |
1669 | |
1670 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1671 static void ext_flash_erase64kB(void) |
38 | 1672 { |
1673 wait_chip_not_busy(); | |
1674 write_spi(0x06,RELEASE);/* WREN */ | |
1675 write_spi(0xD8,HOLDCS);/* sector erase cmd */ | |
1676 write_address(RELEASE); | |
1677 } | |
1678 | |
1679 | |
1680 void ext_flash_read_block_start(void) | |
1681 { | |
1682 wait_chip_not_busy(); | |
1683 write_spi(0x03,HOLDCS); /* WREN */ | |
1684 write_address(HOLDCS); | |
1685 } | |
1686 | |
1687 /* 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
|
1688 static uint8_t ext_flash_erase_if_on_page_start(void) |
38 | 1689 { |
1690 if(actualAddress < 0x00008000) | |
1691 { | |
1692 /* 4K Byte is 0x1000 */ | |
1693 if((actualAddress & 0xFFF) == 0) | |
1694 { | |
1695 ext_flash_erase4kB(); | |
1696 return 1; | |
1697 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1698 } |
38 | 1699 else |
1700 if(actualAddress < 0x00010000) | |
1701 { | |
1702 /* 32K Byte is only one page */ | |
1703 if(actualAddress == 0x00010000) | |
1704 { | |
1705 ext_flash_erase32kB(); | |
1706 return 1; | |
1707 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1708 } |
38 | 1709 else |
1710 { | |
1711 /* 64K Byte is 0x10000 */ | |
1712 if((actualAddress & 0xFFFF) == 0) | |
1713 { | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1714 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
|
1715 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1716 preparedPageAddress = 0; |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1717 |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1718 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1719 else |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1720 { |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1721 ext_flash_erase64kB(); |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1722 } |
38 | 1723 return 1; |
1724 } | |
423
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1725 } |
a560afdaadbf
ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents:
421
diff
changeset
|
1726 |
38 | 1727 return 0; |
1728 } | |
1729 | |
1730 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1731 static void ext_flash_read_block(uint8_t *getByte, uint8_t type) |
38 | 1732 { |
1733 *getByte = read_spi(HOLDCS);/* read data */ | |
1734 ext_flash_incf_address(type); | |
1735 } | |
1736 | |
1737 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1738 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type) |
38 | 1739 { |
1740 uint8_t *data; | |
1741 data = getByte; | |
1742 | |
1743 for(uint32_t i=0;i<size;i++) | |
1744 { | |
1745 data[i] = read_spi(HOLDCS);/* read data */ | |
1746 ext_flash_incf_address(type); | |
1747 } | |
1748 } | |
1749 | |
1750 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1751 static void ext_flash_read_block_stop(void) |
38 | 1752 { |
1753 chip_unselect(); | |
1754 } | |
1755 | |
1756 | |
1757 /* Private functions ---------------------------------------------------------*/ | |
1758 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1759 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) |
38 | 1760 { |
1761 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; | |
420 | 1762 uint32_t i=0; |
1763 | |
38 | 1764 if(!length) |
1765 return; | |
1766 | |
1767 uint32_t ringStart, ringStop; | |
1768 | |
1769 switch(type) | |
1770 { | |
1771 case EF_HEADER: | |
1772 actualAddress = actualPointerHeader; | |
1773 ringStart = HEADERSTART; | |
1774 ringStop = HEADERSTOP; | |
1775 break; | |
1776 case EF_SAMPLE: | |
1777 actualAddress = actualPointerSample; | |
1778 ringStart = SAMPLESTART; | |
1779 ringStop = SAMPLESTOP; | |
1780 break; | |
1781 case EF_DEVICEDATA: | |
1782 actualAddress = actualPointerDevicedata; | |
1783 ringStart = DDSTART; | |
1784 ringStop = DDSTOP; | |
1785 break; | |
1786 case EF_VPMDATA: | |
1787 actualAddress = actualPointerVPM; | |
1788 ringStart = VPMSTART; | |
1789 ringStop = VPMSTOP; | |
1790 break; | |
1791 case EF_SETTINGS: | |
1792 actualAddress = actualPointerSettings; | |
1793 ringStart = SETTINGSSTART; | |
1794 ringStop = SETTINGSSTOP; | |
1795 break; | |
1796 case EF_FIRMWARE: | |
1797 actualAddress = actualPointerFirmware; | |
1798 ringStart = FWSTART; | |
1799 ringStop = FWSTOP; | |
1800 break; | |
1801 case EF_FIRMWARE2: | |
1802 actualAddress = actualPointerFirmware2; | |
1803 ringStart = FWSTART2; | |
1804 ringStop = FWSTOP2; | |
1805 break; | |
1806 default: | |
1807 ringStart = FLASHSTART; | |
1808 ringStop = FLASHSTOP; | |
1809 break; | |
1810 } | |
1811 /* safety */ | |
1812 if(actualAddress < ringStart) | |
1813 actualAddress = ringStart; | |
1814 | |
1815 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
|
1816 { |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
1817 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
|
1818 } |
38 | 1819 |
420 | 1820 while( i<length) |
38 | 1821 { |
1822 ef_hw_rough_delay_us(5); | |
1823 wait_chip_not_busy(); | |
1824 write_spi(0x06,RELEASE); /* WREN */ | |
1825 write_spi(0x02,HOLDCS); /* write cmd */ | |
1826 write_address(HOLDCS); | |
1827 | |
1828 remaining_length = length - i; | |
420 | 1829 remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1; |
38 | 1830 remaining_space_to_ring_end = ringStop - actualAddress; |
1831 | |
420 | 1832 if(remaining_length >= 256) |
1833 { | |
1834 remaining_length = 255; /* up to 256 bytes may be written in one burst. Last byte is written with release */ | |
1835 } | |
1836 else | |
38 | 1837 { |
420 | 1838 remaining_length--; /* last byte needed for release */ |
1839 } | |
1840 if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */ | |
1841 { | |
1842 remaining_length = remaining_page_size - 1; | |
1843 } | |
1844 if( (remaining_space_to_ring_end >= 256)) | |
1845 { | |
1846 for(int j=0; j<remaining_length; j++) | |
38 | 1847 { |
1848 write_spi(sendByte[i],HOLDCS);/* write data */ | |
1849 actualAddress++; | |
1850 i++; | |
1851 } | |
1852 } | |
1853 /* byte with RELEASE */ | |
1854 write_spi(sendByte[i],RELEASE);/* write data */ | |
1855 actualAddress++; | |
420 | 1856 i++; |
1857 | |
38 | 1858 if(actualAddress > ringStop) |
1859 actualAddress = ringStart; | |
420 | 1860 |
38 | 1861 if(do_not_erase == 0) |
1862 ext_flash_erase_if_on_page_start(); | |
1863 } | |
1864 switch(type) | |
1865 { | |
1866 case EF_HEADER: | |
1867 actualPointerHeader = actualAddress; | |
1868 break; | |
1869 case EF_SAMPLE: | |
1870 actualPointerSample = actualAddress; | |
1871 break; | |
1872 case EF_DEVICEDATA: | |
1873 actualPointerDevicedata = actualAddress; | |
1874 break; | |
1875 case EF_VPMDATA: | |
1876 actualPointerVPM = actualAddress; | |
1877 break; | |
1878 case EF_SETTINGS: | |
1879 actualPointerSettings = actualAddress; | |
1880 break; | |
1881 case EF_FIRMWARE: | |
1882 actualPointerFirmware = actualAddress; | |
1883 break; | |
1884 case EF_FIRMWARE2: | |
1885 actualPointerFirmware2 = actualAddress; | |
1886 break; | |
1887 default: | |
1888 break; | |
1889 } | |
1890 } | |
1891 | |
1892 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1893 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length) |
38 | 1894 { |
1895 if((pointer & 0xFFF) == 0) | |
1896 return 1; | |
1897 | |
1898 uint32_t backup = actualAddress; | |
1899 uint8_t data; | |
1900 uint32_t size_to_page_end; | |
1901 | |
1902 size_to_page_end = 0x1000 - (pointer & 0xFFF); | |
1903 if(length > size_to_page_end) | |
1904 length = size_to_page_end; | |
1905 | |
1906 actualAddress = pointer; | |
1907 ext_flash_read_block_start(); | |
1908 | |
1909 for(uint16_t i = 0; i<length; i++) | |
1910 { | |
1911 ext_flash_read_block(&data, 255); // 255 = ENTIRE FLASH | |
1912 if(data != 0xFF) | |
1913 { | |
1914 ext_flash_read_block_stop(); | |
1915 actualAddress = backup; | |
1916 return 0; | |
1917 } | |
1918 } | |
1919 ext_flash_read_block_stop(); | |
1920 actualAddress = backup; | |
1921 return 1; | |
1922 } | |
1923 | |
1924 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1925 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type) |
38 | 1926 { |
1927 uint32_t ringStart, ringStop; | |
1928 | |
1929 switch(type) | |
1930 { | |
1931 case EF_HEADER: | |
1932 ringStart = HEADERSTART; | |
1933 ringStop = HEADERSTOP; | |
1934 break; | |
1935 case EF_SAMPLE: | |
1936 ringStart = SAMPLESTART; | |
1937 ringStop = SAMPLESTOP; | |
1938 break; | |
1939 case EF_DEVICEDATA: | |
1940 ringStart = DDSTART; | |
1941 ringStop = DDSTOP; | |
1942 break; | |
1943 case EF_VPMDATA: | |
1944 ringStart = VPMSTART; | |
1945 ringStop = VPMSTOP; | |
1946 break; | |
1947 case EF_SETTINGS: | |
1948 ringStart = SETTINGSSTART; | |
1949 ringStop = SETTINGSSTOP; | |
1950 break; | |
1951 default: | |
1952 ringStart = FLASHSTART; | |
1953 ringStop = FLASHSTOP; | |
1954 break; | |
1955 } | |
1956 | |
1957 *pointer = (*pointer & 0xFFF) + 0x1000; | |
1958 | |
1959 if((*pointer < ringStart) || (*pointer >= ringStop)) | |
1960 *pointer = ringStart; | |
1961 } | |
1962 | |
1963 | |
1964 static void ef_erase_64K(uint32_t blocks) | |
1965 { | |
1966 for(uint32_t i = 0; i < blocks; i++) | |
1967 { | |
1968 wait_chip_not_busy(); | |
1969 write_spi(0x06,RELEASE);/* WREN */ | |
1970 write_spi(0xD8,HOLDCS);/* 64k erase cmd */ | |
1971 write_address(RELEASE); | |
1972 actualAddress += 0x10000; | |
1973 HAL_Delay(25); | |
1974 } | |
1975 } | |
1976 | |
1977 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1978 static void chip_unselect(void) |
38 | 1979 { |
1980 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_SET); // chip select | |
1981 } | |
1982 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1983 static void chip_select(void) |
38 | 1984 { |
1985 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select | |
1986 } | |
1987 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1988 static void error_led_on(void) |
38 | 1989 { |
1990 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); | |
1991 } | |
1992 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1993 static void error_led_off(void) |
38 | 1994 { |
1995 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); | |
1996 } | |
1997 | |
1998 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1999 static uint8_t read_spi(uint8_t unselect_CS_afterwards) |
38 | 2000 { |
2001 uint8_t byte; | |
2002 | |
2003 chip_select(); | |
2004 | |
2005 if(HAL_SPI_Receive(&hspiDisplay, &byte, 1, 10000) != HAL_OK) | |
2006 Error_Handler_extflash(); | |
2007 | |
2008 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
2009 { | |
2010 } | |
2011 if(unselect_CS_afterwards) | |
2012 chip_unselect(); | |
2013 | |
2014 return byte; | |
2015 } | |
2016 | |
2017 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2018 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards) |
38 | 2019 { |
2020 chip_select(); | |
2021 | |
2022 if(HAL_SPI_Transmit(&hspiDisplay, &data, 1, 10000) != HAL_OK) | |
2023 Error_Handler_extflash(); | |
2024 | |
2025 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
2026 { | |
2027 } | |
2028 if(unselect_CS_afterwards) | |
2029 chip_unselect(); | |
2030 } | |
2031 | |
2032 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2033 static void write_address(uint8_t unselect_CS_afterwards) |
38 | 2034 { |
2035 uint8_t hi, med ,lo; | |
2036 | |
2037 hi = (actualAddress >> 16) & 0xFF; | |
2038 med = (actualAddress >> 8) & 0xFF; | |
2039 lo = actualAddress & 0xFF; | |
2040 | |
2041 write_spi(hi, HOLDCS); | |
2042 write_spi(med, HOLDCS); | |
2043 write_spi(lo, unselect_CS_afterwards); | |
2044 } | |
2045 | |
2046 | |
2047 static void wait_chip_not_busy(void) | |
2048 { | |
2049 uint8_t status; | |
2050 | |
2051 chip_unselect(); | |
2052 | |
2053 write_spi(0x05,HOLDCS); /* RDSR */ | |
2054 status = read_spi(HOLDCS);/* read status */ | |
2055 while(status & 0x01) | |
2056 { | |
2057 HAL_Delay(1); | |
2058 status = read_spi(HOLDCS);/* read status */ | |
2059 } | |
2060 chip_unselect(); | |
2061 } | |
2062 | |
2063 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2064 static void ext_flash_incf_address(uint8_t type) |
38 | 2065 { |
2066 uint32_t ringStart, ringStop; | |
2067 | |
2068 actualAddress += 1; | |
2069 | |
2070 switch(type) | |
2071 { | |
2072 case EF_HEADER: | |
2073 ringStart = HEADERSTART; | |
2074 ringStop = HEADERSTOP; | |
2075 break; | |
2076 case EF_SAMPLE: | |
2077 ringStart = SAMPLESTART; | |
2078 ringStop = SAMPLESTOP; | |
2079 break; | |
2080 case EF_DEVICEDATA: | |
2081 ringStart = DDSTART; | |
2082 ringStop = DDSTOP; | |
2083 break; | |
2084 case EF_VPMDATA: | |
2085 ringStart = VPMSTART; | |
2086 ringStop = VPMSTOP; | |
2087 break; | |
2088 case EF_SETTINGS: | |
2089 ringStart = SETTINGSSTART; | |
2090 ringStop = SETTINGSSTOP; | |
2091 break; | |
2092 case EF_FIRMWARE: | |
2093 ringStart = FWSTART; | |
2094 ringStop = FWSTOP; | |
2095 break; | |
2096 case EF_FIRMWARE2: | |
2097 ringStart = FWSTART2; | |
2098 ringStop = FWSTOP2; | |
2099 break; | |
2100 default: | |
2101 ringStart = FLASHSTART; | |
2102 ringStop = FLASHSTOP; | |
2103 break; | |
2104 } | |
2105 | |
2106 if((actualAddress < ringStart) || (actualAddress > ringStop)) | |
2107 actualAddress = ringStart; | |
2108 } | |
2109 | |
2110 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
2111 static void ext_flash_decf_address_ring(uint8_t type) |
38 | 2112 { |
2113 uint32_t ringStart, ringStop; | |
2114 | |
2115 switch(type) | |
2116 { | |
2117 case EF_HEADER: | |
2118 ringStart = HEADERSTART; | |
2119 ringStop = HEADERSTOP; | |
2120 break; | |
2121 case EF_SAMPLE: | |
2122 ringStart = SAMPLESTART; | |
2123 ringStop = SAMPLESTOP; | |
2124 break; | |
2125 case EF_DEVICEDATA: | |
2126 ringStart = DDSTART; | |
2127 ringStop = DDSTOP; | |
2128 break; | |
2129 case EF_VPMDATA: | |
2130 ringStart = VPMSTART; | |
2131 ringStop = VPMSTOP; | |
2132 break; | |
2133 case EF_SETTINGS: | |
2134 ringStart = SETTINGSSTART; | |
2135 ringStop = SETTINGSSTOP; | |
2136 break; | |
2137 case EF_FIRMWARE: | |
2138 ringStart = FWSTART; | |
2139 ringStop = FWSTOP; | |
2140 break; | |
2141 case EF_FIRMWARE2: | |
2142 ringStart = FWSTART2; | |
2143 ringStop = FWSTOP2; | |
2144 break; | |
2145 default: | |
2146 ringStart = FLASHSTART; | |
2147 ringStop = FLASHSTOP; | |
2148 break; | |
2149 } | |
2150 | |
2151 if((actualAddress <= ringStart) || (actualAddress > ringStop)) | |
2152 actualAddress = ringStop; | |
2153 else | |
2154 actualAddress -= 1; | |
2155 } | |
2156 | |
2157 | |
2158 static void ef_hw_rough_delay_us(uint32_t delayUs) | |
2159 { | |
2160 if(!delayUs) | |
2161 return; | |
2162 delayUs*= 12; | |
2163 while(delayUs--); | |
2164 return; | |
2165 } | |
2166 | |
2167 static void Error_Handler_extflash(void) | |
2168 { | |
2169 while(1) | |
2170 { | |
2171 } | |
2172 } | |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2173 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2174 void ext_flash_CloseSector(void) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2175 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2176 uint32_t actualAddressBackup = actualAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2177 int i=0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2178 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2179 if(closeSectorAddress != 0) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2180 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2181 /* 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
|
2182 actualAddress = closeSectorAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2183 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2184 wait_chip_not_busy(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2185 write_spi(0x06,RELEASE); /* WREN */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2186 write_spi(0x02,HOLDCS); /* write cmd */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2187 write_address(HOLDCS); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2188 for(i = 0; i<8; i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2189 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2190 write_spi(0xA5,HOLDCS);/* write data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2191 actualAddress++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2192 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2193 /* byte with RELEASE */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2194 write_spi(0xA5,RELEASE);/* write data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2195 actualAddress = actualAddressBackup; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2196 closeSectorAddress = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2197 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2198 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2199 |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2200 /* 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
|
2201 uint8_t ext_flash_SampleOverrunValid(void) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2202 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2203 uint8_t jumpvalid = 1; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2204 uint32_t curAddress, actualaddrbackup; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2205 uint8_t tmpBuffer; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2206 uint8_t emptyCellCnt = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2207 |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2208 actualaddrbackup = actualAddress; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2209 curAddress = SAMPLESTOP - 20; /* check the last 10 bytes of the last sample sector */ |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2210 actualAddress = curAddress; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2211 ext_flash_read_block_start(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2212 while(actualAddress < SAMPLESTOP) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2213 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2214 tmpBuffer = read_spi(HOLDCS);/* read data */ |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2215 if(tmpBuffer == 0xFF) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2216 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2217 emptyCellCnt++; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2218 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2219 actualAddress++; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2220 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2221 ext_flash_read_block_stop(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2222 |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2223 if(emptyCellCnt == 20) |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2224 { |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2225 jumpvalid = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2226 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2227 actualAddress = actualaddrbackup; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2228 return jumpvalid; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2229 } |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2230 |
425
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2231 uint32_t ext_flash_AnalyseSampleBuffer(char *pstrResult) |
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 uint8_t sectorState[16]; /* samples are stored in 16 sector / 64k each */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2234 uint32_t curAddress = SAMPLESTART; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2235 uint8_t curSector = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2236 uint8_t samplebuffer[10]; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2237 uint32_t actualAddressBackup = actualAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2238 uint8_t emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2239 uint32_t i = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2240 uint8_t startedSectors = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2241 uint8_t lastSectorInuse = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2242 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2243 /* check if a sector is used till its end */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2244 for(curSector = 0; curSector < 16; curSector++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2245 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2246 sectorState[curSector] = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2247 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2248 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
|
2249 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2250 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2251 for(uint32_t i=0;i<10;i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2252 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2253 samplebuffer[i] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2254 if(samplebuffer[i] == 0xFF) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2255 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2256 emptyCellCnt++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2257 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2258 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2259 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2260 if(emptyCellCnt == 10) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2261 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2262 sectorState[curSector] = SECTOR_NOTUSED; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2263 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2264 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2265 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
|
2266 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2267 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2268 for(i=0;i<10;i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2269 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2270 samplebuffer[i] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2271 if(samplebuffer[i] == 0xFF) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2272 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2273 emptyCellCnt++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2274 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2275 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2276 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2277 if(emptyCellCnt == 10) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2278 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2279 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
|
2280 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2281 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2282 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2283 for(i=0;i<16;i++) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2284 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2285 if( sectorState[i] == SECTOR_INUSE) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2286 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2287 startedSectors++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2288 lastSectorInuse = i; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2289 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2290 *(pstrResult+i) = sectorState[i] + 48; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2291 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2292 |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2293 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
|
2294 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2295 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
|
2296 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2297 /* 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
|
2298 curAddress = SAMPLESTART + (lastSectorInuse * 0x10000); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2299 emptyCellCnt = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2300 actualAddress = curAddress; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2301 ext_flash_read_block_start(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2302 while((emptyCellCnt < 10) && (actualAddress < curAddress + 0x10000)) |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2303 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2304 samplebuffer[0] = read_spi(HOLDCS);/* read data */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2305 if(samplebuffer[0] == 0xFF) |
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++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2308 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2309 else |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2310 { |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2311 emptyCellCnt = 0; |
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 actualAddress++; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2314 } |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2315 ext_flash_read_block_stop(); |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2316 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
|
2317 actualPointerSample = actualAddress; |
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 closeSectorAddress = settingsGetPointer()->logFlashNextSampleStartAddress & 0xFFFF0000; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2320 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
|
2321 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; /* store new position to be used for next dive */ |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2322 } |
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 actualAddress = actualAddressBackup; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2325 *(pstrResult+i) = 0; |
86fcac4cc43a
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
423
diff
changeset
|
2326 return startedSectors; |
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 |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2329 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
|
2330 { |
466
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2331 uint32_t profileLength = 0; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2332 actualPointerSample = smallHeaderAddr; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2333 actualAddress = actualPointerSample; |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2334 ext_flash_read_block_start(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2335 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
|
2336 ext_flash_close_read_sample(); |
538eb1c976e9
Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents:
463
diff
changeset
|
2337 return profileLength; |
452
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2338 } |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2339 |
b90ddf57f7f1
Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents:
429
diff
changeset
|
2340 |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2341 /* |
38 | 2342 uint8_t ext_flash_erase_firmware_if_not_empty(void) |
2343 { | |
2344 const uint8_t TESTSIZE_FW = 4; | |
2345 | |
2346 uint8_t data[TESTSIZE_FW]; | |
2347 uint8_t notEmpty = 0; | |
2348 | |
2349 actualAddress = FWSTART; | |
2350 ext_flash_read_block_start(); | |
2351 for(int i = 0; i < TESTSIZE_FW; i++) | |
2352 { | |
2353 ext_flash_read_block(&data[i], EF_FIRMWARE); | |
2354 if(data[i] != 0xFF) | |
2355 notEmpty = 1; | |
2356 } | |
2357 ext_flash_read_block_stop(); | |
2358 | |
2359 if(notEmpty) | |
2360 { | |
2361 ext_flash_erase_firmware(); | |
2362 return 1; | |
2363 } | |
2364 else | |
2365 return 0; | |
2366 } | |
2367 | |
2368 uint8_t ext_flash_erase_firmware2_if_not_empty(void) | |
2369 { | |
2370 const uint8_t TESTSIZE_FW = 4; | |
2371 | |
2372 uint8_t data[TESTSIZE_FW]; | |
2373 uint8_t notEmpty = 0; | |
2374 | |
2375 actualAddress = FWSTART2; | |
2376 ext_flash_read_block_start(); | |
2377 for(int i = 0; i < TESTSIZE_FW; i++) | |
2378 { | |
2379 ext_flash_read_block(&data[i], EF_FIRMWARE2); | |
2380 if(data[i] != 0xFF) | |
2381 notEmpty = 1; | |
2382 } | |
2383 ext_flash_read_block_stop(); | |
2384 | |
2385 if(notEmpty) | |
2386 { | |
2387 ext_flash_erase_firmware2(); | |
2388 return 1; | |
2389 } | |
2390 else | |
2391 return 0; | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
2392 }*/ |