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