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