comparison Discovery/Src/externLogbookFlash.c @ 463:e4f6afd9c96b Improve_Logtansfer

Added function to transfer sample buffer: Command for the transfer of sample raw data added. This may be used, together with the existing raw header transfer, to backup / restore the complete log memory
author ideenmodellierer
date Sun, 12 Apr 2020 21:02:34 +0200
parents 2effe85f1a9b
children 538eb1c976e9
comparison
equal deleted inserted replaced
462:dddfe7917131 463:e4f6afd9c96b
970 ext_flash_read_block_stop(); 970 ext_flash_read_block_stop();
971 } 971 }
972 972
973 973
974 // =============================================================================== 974 // ===============================================================================
975 // ext_flash_read_header_memory 975 // ext_flash_write_header_memory
976 /// @brief This function erases and overwrites the entire logbook header block 976 /// @brief This function erases and overwrites the entire logbook header block
977 /// @date 04-April-2016 977 /// @date 04-April-2016
978 /// 978 ///
979 /// @param *data 256KB input of header memory 1:1 979 /// @param *data 256KB input of header memory 1:1
980 // =============================================================================== 980 // ===============================================================================
981 void ext_flash_write_header_memory(uint8_t *data) 981 void ext_flash_write_header_memory(uint8_t *data)
982 { 982 {
983 actualAddress = HEADERSTART; 983 actualAddress = HEADERSTART;
984 actualPointerHeader = actualAddress; 984 actualPointerHeader = actualAddress;
985 ef_write_block(data, 0x40000, EF_HEADER, 0); 985 ef_write_block(data, 0x40000, EF_HEADER, 0);
986 }
987
988 void ext_flash_read_sample_memory(uint8_t *data,uint16_t blockId)
989 {
990 actualAddress = SAMPLESTART;
991 actualAddress += blockId * 0x8000; /* add 32k Block offset */
992 actualPointerSample = actualAddress;
993 ext_flash_read_block_start();
994 ext_flash_read_block_multi(data, 0x8000, EF_SAMPLE);
995 ext_flash_read_block_stop();
996 }
997
998 void ext_flash_write_sample_memory(uint8_t *data,uint16_t blockId)
999 {
1000 actualAddress = SAMPLESTART;
1001 actualAddress += blockId * 0x8000; /* add 32k Block offset */
1002 actualPointerSample = actualAddress;
1003 ef_write_block(data, 0x8000, EF_SAMPLE,0);
986 } 1004 }
987 1005
988 1006
989 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes) 1007 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes)
990 { 1008 {
1741 1759
1742 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) 1760 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase)
1743 { 1761 {
1744 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; 1762 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end;
1745 uint32_t i=0; 1763 uint32_t i=0;
1764 uint32_t actualAddrBackup = 0;
1746 1765
1747 if(!length) 1766 if(!length)
1748 return; 1767 return;
1749 1768
1750 uint32_t ringStart, ringStop; 1769 uint32_t ringStart, ringStop;
1795 if(actualAddress < ringStart) 1814 if(actualAddress < ringStart)
1796 actualAddress = ringStart; 1815 actualAddress = ringStart;
1797 1816
1798 if(do_not_erase == 0) 1817 if(do_not_erase == 0)
1799 { 1818 {
1819 actualAddrBackup = actualAddress;
1800 if((ext_flash_erase_if_on_page_start()) && (type == EF_SAMPLE)) /* invalidate header sample information if needed */ 1820 if((ext_flash_erase_if_on_page_start()) && (type == EF_SAMPLE)) /* invalidate header sample information if needed */
1801 { 1821 {
1802 ext_flash_invalidate_sample_index(actualAddress); 1822 ext_flash_invalidate_sample_index(actualAddress);
1823 actualAddress = actualAddrBackup;
1803 } 1824 }
1804 } 1825 }
1805 1826
1806 while( i<length) 1827 while( i<length)
1807 { 1828 {
2284 /* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */ 2305 /* In case of a sample ring overrun the headers of the dive which will no longer have sample data needs to be updated */
2285 void ext_flash_invalidate_sample_index(uint32_t sectorStart) 2306 void ext_flash_invalidate_sample_index(uint32_t sectorStart)
2286 { 2307 {
2287 uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */ 2308 uint8_t emptySamples[] = {0,0,0, 0,0,0, 0,0,0}; /* entry of start, stop and length */
2288 uint8_t diveidx; 2309 uint8_t diveidx;
2310 uint8_t index;
2289 2311
2290 uint8_t header1, header2; 2312 uint8_t header1, header2;
2291 2313
2292 SSettings *settings = settingsGetPointer(); 2314 SSettings *settings = settingsGetPointer();
2293 diveidx = settings->lastDiveLogId + 1; 2315 diveidx = settings->lastDiveLogId + 1;
2318 { 2340 {
2319 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET; 2341 actualAddress = HEADERSTART + (0x800 * diveidx) + HEADER2OFFSET;
2320 ext_flash_incf_address(EF_HEADER); /* skip header bytes */ 2342 ext_flash_incf_address(EF_HEADER); /* skip header bytes */
2321 ext_flash_incf_address(EF_HEADER); 2343 ext_flash_incf_address(EF_HEADER);
2322 actualPointerHeader = actualAddress; 2344 actualPointerHeader = actualAddress;
2323 ef_write_block(emptySamples,9,EF_HEADER,1); /* clear start, stop and length data */ 2345
2346 ef_hw_rough_delay_us(5);
2347 wait_chip_not_busy();
2348 write_spi(0x06,RELEASE); /* WREN */
2349 write_spi(0x02,HOLDCS); /* write cmd */
2350 write_address(HOLDCS);
2351 for(index=0; index<8; index++)
2352 {
2353 write_spi(emptySamples[index],HOLDCS);/* write data */
2354 actualAddress++;
2355 }
2356 /* byte with RELEASE */
2357 write_spi(emptySamples[index],RELEASE);/* write data */
2324 actualPointerHeader = HeaderAddrBackup; 2358 actualPointerHeader = HeaderAddrBackup;
2325 } 2359 }
2326 } 2360 }
2327 diveidx++; 2361 diveidx++;
2328 } 2362 }