Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void iap_copy_to_flash (uint8_t* buff, uint32_t flash_addr, uint32_t num_bytes)
- {
- uint32_t ram_addr;
- uint8_t sector;
- uint16_t bytes_to_copy, bytes_copied=0;
- uint16_t i, eror=0;
- uint8_t *ext_ram_addr;
- ram_addr = (uint32_t)buff;
- sector = iap_find_sector (flash_addr);
- prepare_sector (sector, sector);
- erase_sector (sector, sector); //48000 - takt
- while (num_bytes)
- {
- if (num_bytes > sector_offset_to_end)
- bytes_to_copy = sector_offset_to_end;
- else
- bytes_to_copy = num_bytes;
- if (bytes_to_copy > 4096)
- bytes_to_copy = 4096;
- prepare_sector (sector, sector);
- bytes_copied = 0;
- if ( (uint32_t) buff >= 0x80000000 )
- {
- ext_ram_addr = (uint8_t *)buff;
- for (i = 0; i < bytes_to_copy; i++)
- {
- temporary[i] = *ext_ram_addr++ ;
- if (temporary[i] != (uint8_t) i)
- eror++;
- }
- copy_ram_to_flash (flash_addr, (uint32_t)(&temporary[0]), bytes_to_copy);
- }
- else
- copy_ram_to_flash (flash_addr, ram_addr, bytes_to_copy);
- bytes_copied += bytes_to_copy;
- num_bytes -= bytes_copied;
- sector_offset_to_end -= bytes_copied;
- flash_addr += bytes_copied;
- ram_addr += bytes_copied;
- if (num_bytes && sector_offset_to_end == 0)
- {
- if (sector == 29)
- {
- return;
- }
- sector = iap_find_sector (flash_addr);
- prepare_sector (sector, sector);
- erase_sector (sector, sector);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement