comparison Discovery/Src/externLogbookFlash.c @ 421:3f7d80f37bfc ImprovmentNVM_2

Enable sequentionel writing of device data: DeviceData was always written to the start of the the DD ringbuffer causing everytime a sector erase delay (~200ms). To avoid this the ring buffer functionality has been activated. To be backward compatible the latest DD set will be written to DD ring buffer start at shutdown time. In case of a reset the firmware scans for the latest DD block and restores its content giving the same data consistency intervall (10 minutes) as the previous implementation without having the 200ms penality for sector erases
author ideenmodellierer
date Mon, 10 Feb 2020 19:25:09 +0100
parents 2174fb133dbe
children a560afdaadbf
comparison
equal deleted inserted replaced
420:2174fb133dbe 421:3f7d80f37bfc
119 static uint32_t entryPoint = 0; 119 static uint32_t entryPoint = 0;
120 120
121 static uint32_t actualPointerHeader = 0; 121 static uint32_t actualPointerHeader = 0;
122 static uint32_t actualPointerSample = 0; 122 static uint32_t actualPointerSample = 0;
123 static uint32_t LengthLeftSampleRead = 0; 123 static uint32_t LengthLeftSampleRead = 0;
124 static uint32_t actualPointerDevicedata = 0; 124 static uint32_t actualPointerDevicedata = DDSTART;
125 static uint32_t actualPointerDevicedata_Read = DDSTART;
125 static uint32_t actualPointerVPM = 0; 126 static uint32_t actualPointerVPM = 0;
126 static uint32_t actualPointerSettings = 0; 127 static uint32_t actualPointerSettings = 0;
127 static uint32_t actualPointerFirmware = 0; 128 static uint32_t actualPointerFirmware = 0;
128 static uint32_t actualPointerFirmware2 = 0; 129 static uint32_t actualPointerFirmware2 = 0;
129 130
390 } 391 }
391 392
392 393
393 #ifndef BOOTLOADER_STANDALONE 394 #ifndef BOOTLOADER_STANDALONE
394 395
395 void ext_flash_write_devicedata(void) 396 void ext_flash_write_devicedata(uint8_t resetRing)
396 { 397 {
397 uint8_t *pData; 398 uint8_t *pData;
398 const uint16_t length = sizeof(SDevice); 399 const uint16_t length = sizeof(SDevice);
399 uint8_t length_lo, length_hi; 400 uint8_t length_lo, length_hi;
400 uint8_t dataLength[2] = { 0 }; 401 uint8_t dataLength[2] = { 0 };
402 uint32_t tmpBlockStart;
401 403
402 ext_flash_disable_protection(); 404 ext_flash_disable_protection();
403 405
404 pData = (uint8_t *)stateDeviceGetPointer(); 406 pData = (uint8_t *)stateDeviceGetPointer();
405 407
406 actualPointerDevicedata = DDSTART; 408 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */
409 if((resetRing) || ((actualPointerDevicedata + length) >= DDSTOP))
410 {
411 actualPointerDevicedata = DDSTART;
412 }
413 tmpBlockStart = actualPointerDevicedata;
407 414
408 length_lo = (uint8_t)(length & 0xFF); 415 length_lo = (uint8_t)(length & 0xFF);
409 length_hi = (uint8_t)(length >> 8); 416 length_hi = (uint8_t)(length >> 8);
410 dataLength[0] = length_lo; 417 dataLength[0] = length_lo;
411 dataLength[1] = length_hi; 418 dataLength[1] = length_hi;
412 419
413 ef_write_block(dataLength,2, EF_DEVICEDATA, 0); 420 ef_write_block(dataLength,2, EF_DEVICEDATA, 0);
414 ef_write_block(pData,length, EF_DEVICEDATA, 0); 421 ef_write_block(pData,length, EF_DEVICEDATA, 0);
422
423 actualPointerDevicedata_Read = tmpBlockStart;
424
415 } 425 }
416 426
417 427
418 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length) 428 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length)
419 { 429 {
420 uint16_t length; 430 uint16_t length;
421 uint8_t length_lo, length_hi; 431 uint8_t length_lo, length_hi;
422 432
423 actualAddress = DDSTART; 433 actualAddress = actualPointerDevicedata_Read;
424 434
435 length = 0;
436 length_lo = 0;
437 length_hi = 0;
425 ext_flash_read_block_start(); 438 ext_flash_read_block_start();
439
440
426 ext_flash_read_block(&length_lo, EF_DEVICEDATA); 441 ext_flash_read_block(&length_lo, EF_DEVICEDATA);
427 ext_flash_read_block(&length_hi, EF_DEVICEDATA); 442 ext_flash_read_block(&length_hi, EF_DEVICEDATA);
428 443
429 length = (length_hi * 256) + length_lo; 444 while ((length_lo != 0xFF) && (length_hi != 0xFF))
430 445 {
431 if(length > max_length) 446 length = (length_hi * 256) + length_lo;
432 return 0; 447
433 448 if(length > max_length)
434 ext_flash_read_block_multi(buffer,length,EF_DEVICEDATA); 449 return 0;
450
451 ext_flash_read_block_multi(buffer,length,EF_DEVICEDATA);
452
453 ext_flash_read_block(&length_lo, EF_DEVICEDATA); /* check if another devicedata set is available */
454 ext_flash_read_block(&length_hi, EF_DEVICEDATA); /* length will be 0xFFFF if a empty memory is read */
455 }
456 ext_flash_decf_address_ring(EF_DEVICEDATA); /* set pointer back to empty address */
457 ext_flash_decf_address_ring(EF_DEVICEDATA);
435 ext_flash_read_block_stop(); 458 ext_flash_read_block_stop();
436 459
460 if(actualAddress > actualPointerDevicedata) /* the write pointer has not yet been set up probably */
461 {
462 actualPointerDevicedata = actualAddress;
463 }
437 return length; 464 return length;
438 } 465 }
439 466
440 467
441 void ext_flash_write_vpm(SVpm *vpmInput) 468 void ext_flash_write_vpm(SVpm *vpmInput)