/* address entry is not page aligned */ if (addr_t != 0) { num_of_entry_bytes = SPI_FLASH_PAGE_SIZE - addr_t; /* if entry page's remaining space less than bytes to write */ if(len > num_of_entry_bytes) { /* write entry page first */ spi_flash_pagewrite(pBuffer, addr, num_of_entry_bytes);
len -= num_of_entry_bytes; addr += num_of_entry_bytes; pBuffer += num_of_entry_bytes;
/* Below process is same as page aligned*/
num_of_intact_page = len / SPI_FLASH_PAGE_SIZE;
if (num_of_intact_page == 0) { /* write a page at address entry */ spi_flash_pagewrite(pBuffer, addr, len); } else { /* write intact pages */ while (num_of_intact_page--) { spi_flash_pagewrite(pBuffer, addr, SPI_FLASH_PAGE_SIZE); addr += SPI_FLASH_PAGE_SIZE; pBuffer += SPI_FLASH_PAGE_SIZE; }
uint16 num_of_tail_bytes = len % SPI_FLASH_PAGE_SIZE; /* if needed, write the last page*/ if(num_of_tail_bytes != 0) { spi_flash_pagewrite(pBuffer, addr, num_of_tail_bytes); } } } /* if entry page's remaining space covers bytes to write */ else { spi_flash_pagewrite(pBuffer, addr, len); } } /* address entry is page aligned */ else { // num_of_entry_bytes = SPI_FLASH_PAGE_SIZE - addr_t; num_of_intact_page = len / SPI_FLASH_PAGE_SIZE;
if (num_of_intact_page == 0) { /* write a page at address entry */ spi_flash_pagewrite(pBuffer, addr, len); } else { /* write intact pages */ while (num_of_intact_page--) { spi_flash_pagewrite(pBuffer, addr, SPI_FLASH_PAGE_SIZE); addr += SPI_FLASH_PAGE_SIZE; pBuffer += SPI_FLASH_PAGE_SIZE; }
uint16 num_of_tail_bytes = len % SPI_FLASH_PAGE_SIZE; /* if needed, write the last page*/ if(num_of_tail_bytes != 0) { spi_flash_pagewrite(pBuffer, addr, num_of_tail_bytes); } } } }