Mercurial > public > ostc4
comparison Discovery/Src/externLogbookFlash.c @ 420:2174fb133dbe ImprovmentNVM_2
Optimize ef_write_block function:
The function did single byte writing until a start of a page was detected. Only in that case a multi byte write was used. According to the manual page write is not limited to 256 byte. Multiple bytes may be written until the end of the page is reached
=> Changed implementation to always use multi byte writes which increases the performance of the write block function
author | ideenmodellierer |
---|---|
date | Mon, 10 Feb 2020 19:15:27 +0100 |
parents | c7e665e0b08f |
children | 3f7d80f37bfc |
comparison
equal
deleted
inserted
replaced
419:c2264ce139cb | 420:2174fb133dbe |
---|---|
1631 /* Private functions ---------------------------------------------------------*/ | 1631 /* Private functions ---------------------------------------------------------*/ |
1632 | 1632 |
1633 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) | 1633 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase) |
1634 { | 1634 { |
1635 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; | 1635 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end; |
1636 | 1636 uint32_t i=0; |
1637 | |
1637 if(!length) | 1638 if(!length) |
1638 return; | 1639 return; |
1639 | 1640 |
1640 uint32_t ringStart, ringStop; | 1641 uint32_t ringStart, ringStop; |
1641 | 1642 |
1686 actualAddress = ringStart; | 1687 actualAddress = ringStart; |
1687 | 1688 |
1688 if(do_not_erase == 0) | 1689 if(do_not_erase == 0) |
1689 ext_flash_erase_if_on_page_start(); | 1690 ext_flash_erase_if_on_page_start(); |
1690 | 1691 |
1691 for(uint32_t i=0;i<length;i++) | 1692 while( i<length) |
1692 { | 1693 { |
1693 ef_hw_rough_delay_us(5); | 1694 ef_hw_rough_delay_us(5); |
1694 wait_chip_not_busy(); | 1695 wait_chip_not_busy(); |
1695 write_spi(0x06,RELEASE); /* WREN */ | 1696 write_spi(0x06,RELEASE); /* WREN */ |
1696 write_spi(0x02,HOLDCS); /* write cmd */ | 1697 write_spi(0x02,HOLDCS); /* write cmd */ |
1697 write_address(HOLDCS); | 1698 write_address(HOLDCS); |
1698 | 1699 |
1699 remaining_length = length - i; | 1700 remaining_length = length - i; |
1700 remaining_page_size = actualAddress & 0xFF; | 1701 remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1; |
1701 remaining_space_to_ring_end = ringStop - actualAddress; | 1702 remaining_space_to_ring_end = ringStop - actualAddress; |
1702 | 1703 |
1703 if((remaining_page_size == 0) && (remaining_length >= 256) && (remaining_space_to_ring_end >= 256)) | 1704 if(remaining_length >= 256) |
1704 { | 1705 { |
1705 for(int j=0; j<255; j++) | 1706 remaining_length = 255; /* up to 256 bytes may be written in one burst. Last byte is written with release */ |
1707 } | |
1708 else | |
1709 { | |
1710 remaining_length--; /* last byte needed for release */ | |
1711 } | |
1712 if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */ | |
1713 { | |
1714 remaining_length = remaining_page_size - 1; | |
1715 } | |
1716 if( (remaining_space_to_ring_end >= 256)) | |
1717 { | |
1718 for(int j=0; j<remaining_length; j++) | |
1706 { | 1719 { |
1707 write_spi(sendByte[i],HOLDCS);/* write data */ | 1720 write_spi(sendByte[i],HOLDCS);/* write data */ |
1708 actualAddress++; | 1721 actualAddress++; |
1709 i++; | 1722 i++; |
1710 } | 1723 } |
1711 } | 1724 } |
1712 /* byte with RELEASE */ | 1725 /* byte with RELEASE */ |
1713 write_spi(sendByte[i],RELEASE);/* write data */ | 1726 write_spi(sendByte[i],RELEASE);/* write data */ |
1714 actualAddress++; | 1727 actualAddress++; |
1728 i++; | |
1729 | |
1715 if(actualAddress > ringStop) | 1730 if(actualAddress > ringStop) |
1716 actualAddress = ringStart; | 1731 actualAddress = ringStart; |
1732 | |
1717 if(do_not_erase == 0) | 1733 if(do_not_erase == 0) |
1718 ext_flash_erase_if_on_page_start(); | 1734 ext_flash_erase_if_on_page_start(); |
1719 } | 1735 } |
1720 switch(type) | 1736 switch(type) |
1721 { | 1737 { |