Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. void readHiRomBanks( unsigned int start, unsigned int total, SdFile *file)
  2. {
  3.   byte buffer[1024];
  4.  
  5.   delay(1000);  // let previous message show before starting
  6.   display_Clear();
  7.  
  8.   unsigned long startTimeBank = millis();
  9.   unsigned long startTimeAllBanks = millis();
  10.   uint16_t c = 0;
  11.   uint16_t currByte = 0;
  12.  
  13.   for (int currBank = start; currBank < total; currBank++) {
  14.     startTimeBank = millis();
  15.     PORTL = currBank;
  16.     currByte = 0;
  17.     while (1) {
  18.       c = 0;
  19.       while (c < 1024) {
  20.         PORTF = (currByte & 0xFF);
  21.         PORTK = ((currByte >> 8) & 0xFF);
  22.  
  23.         // Wait for the Byte to appear on the data bus
  24.         // Arduino running at 16Mhz -> one nop = 62.5ns
  25.         // slowRom is <= 200ns, fastRom is <= 120ns, S-CPU max read speed: 3.57MHz / 280ns
  26.         __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); // using 5 x 62.5 = 312.5ns
  27.        
  28.         buffer[c] = PINC;
  29.         c++;
  30.         currByte++;
  31.       }
  32.       file->write(buffer, 1024);
  33.  
  34.       // exit while(1) loop once the uint16_t currByte overflows to 0 > this bank is done
  35.       if (currByte == 0) break;
  36.     }
  37.    
  38.     println_Msg(millis() - startTimeBank);
  39.     display_Update();
  40.     if (currBank % 8 == 0) display_Clear();
  41.   }
  42.  
  43.   display_Clear();
  44.   print_Msg(F("Time spent: "));
  45.   println_Msg(millis() - startTimeAllBanks);
  46.   display_Update();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement