Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. void iap_copy_to_flash (uint8_t* buff, uint32_t flash_addr, uint32_t num_bytes)
  2. {
  3. uint32_t ram_addr;
  4. uint8_t sector;
  5. uint16_t bytes_to_copy, bytes_copied=0;
  6. uint16_t i, eror=0;
  7. uint8_t *ext_ram_addr;
  8.  
  9. ram_addr = (uint32_t)buff;
  10.  
  11. sector = iap_find_sector (flash_addr);
  12.  
  13. prepare_sector (sector, sector);
  14. erase_sector (sector, sector); //48000 - takt
  15.  
  16.  
  17. while (num_bytes)
  18. {
  19. if (num_bytes > sector_offset_to_end)
  20. bytes_to_copy = sector_offset_to_end;
  21. else
  22. bytes_to_copy = num_bytes;
  23.  
  24.  
  25. if (bytes_to_copy > 4096)
  26. bytes_to_copy = 4096;
  27.  
  28. prepare_sector (sector, sector);
  29. bytes_copied = 0;
  30.  
  31. if ( (uint32_t) buff >= 0x80000000 )
  32. {
  33. ext_ram_addr = (uint8_t *)buff;
  34. for (i = 0; i < bytes_to_copy; i++)
  35. {
  36. temporary[i] = *ext_ram_addr++ ;
  37. if (temporary[i] != (uint8_t) i)
  38. eror++;
  39. }
  40. copy_ram_to_flash (flash_addr, (uint32_t)(&temporary[0]), bytes_to_copy);
  41. }
  42. else
  43. copy_ram_to_flash (flash_addr, ram_addr, bytes_to_copy);
  44.  
  45. bytes_copied += bytes_to_copy;
  46.  
  47. num_bytes -= bytes_copied;
  48. sector_offset_to_end -= bytes_copied;
  49. flash_addr += bytes_copied;
  50. ram_addr += bytes_copied;
  51.  
  52. if (num_bytes && sector_offset_to_end == 0)
  53. {
  54. if (sector == 29)
  55. {
  56. return;
  57. }
  58. sector = iap_find_sector (flash_addr);
  59. prepare_sector (sector, sector);
  60. erase_sector (sector, sector);
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement