Advertisement
Guest User

Untitled

a guest
May 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. void cfOptimizeCycleTime()
  2. {
  3. int cycletime = 40;
  4.  
  5. // first sector MUST already be loaded into buffer
  6.  
  7. // the algorithm is as follow:
  8. // first the cycletime is high, for slow access.
  9. // repeatedly set the cycletime smaller (for faster)
  10. // stop once the data doesn't match what you got for the first read.
  11.  
  12. while(1)
  13. {
  14. cfReadSector(fat_buffer, 0);
  15.  
  16. if(memcmp(fat_buffer, buffer, 512) != 0)
  17. {
  18. // newly read buffer differs from original! must be corrupted, slow back down
  19. cycletime += 5;
  20. cfSetCycleTime(cycletime);
  21. return;
  22. }
  23. // otherwise trim it down a bit
  24. cycletime -= 5;
  25.  
  26. if(cycletime <= 5)
  27. {
  28. // never let it go below 5
  29. cfSetCycleTime(5);
  30. return;
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement