Guest User

Untitled

a guest
Feb 13th, 2021
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.  
  2. int test_reg_for_slowpoke(uint32_t reg, uint8_t bit) {
  3.     uint32_t old = MMIO32(reg);
  4.    
  5.     MMIO32(reg) &= ~(1 << bit);
  6.     MMIO32(reg) |= (1 << bit);
  7.    
  8.     return !(MMIO32(reg) & (1 << bit));
  9. }
  10.  
  11. int test_reg_for_wr(uint32_t reg, uint8_t bit) {
  12.     uint32_t old = MMIO32(reg);
  13.    
  14.     MMIO32(reg) |= (1 << bit);
  15.     delay_ms(2);
  16.     bool a = (MMIO32(reg) & (1 << bit));
  17.    
  18.     MMIO32(reg) &= ~(1 << bit);
  19.     delay_ms(2);
  20.     bool b = (MMIO32(reg) & (1 << bit));
  21.    
  22.     return a != b;
  23. }
  24.  
  25. void test_reg(const char *name, uint32_t reg) {
  26.     printf("%s - 0x%08lX:\r\n", name, reg);
  27.     for (int i = 0; i < 32; i++) {
  28.         bool is_slow = false;
  29.        
  30.         for (int j = 0; j < 100; j++) {
  31.             if (test_reg_for_slowpoke(reg, i))
  32.                 is_slow = true;
  33.         }
  34.        
  35.         bool is_wr = test_reg_for_wr(reg, i);
  36.        
  37.         printf("  -> bit %d ");
  38.        
  39.         if (is_wr) {
  40.             printf(" [wr]");
  41.         } else {
  42.             printf(" [ro]");
  43.         }
  44.        
  45.         if (is_slow && is_wr)
  46.             printf(" [slow]");
  47.        
  48.         printf("\r\n");
  49.     }
  50.    
  51. }
  52.  
  53. int test_sdio(void) {
  54.     test_reg("SDIO_POWER", SDIO1 + 0x00);
  55.     test_reg("SDIO_CLKCR", SDIO1 + 0x04);
  56.     test_reg("SDIO_ARG", SDIO1 + 0x08);
  57.     test_reg("SDIO_CMD", SDIO1 + 0x0C);
  58.     test_reg("SDIO_RESPCMD", SDIO1 + 0x10);
  59.     test_reg("SDIO_RESP1", SDIO1 + 0x14);
  60.     test_reg("SDIO_RESP2", SDIO1 + 0x18);
  61.     test_reg("SDIO_RESP3", SDIO1 + 0x1C);
  62.     test_reg("SDIO_RESP4", SDIO1 + 0x20);
  63.     test_reg("SDIO_DTIMER", SDIO1 + 0x24);
  64.     test_reg("SDIO_DLEN", SDIO1 + 0x28);
  65.     test_reg("SDIO_DCTRL", SDIO1 + 0x2C);
  66.     test_reg("SDIO_DCOUNT", SDIO1 + 0x30);
  67.     test_reg("SDIO_STA", SDIO1 + 0x34);
  68.     test_reg("SDIO_ICR", SDIO1 + 0x38);
  69.     test_reg("SDIO_MASK", SDIO1 + 0x3C);
  70.     test_reg("SDIO_FIFOCNT", SDIO1 + 0x48);
  71.     test_reg("SDIO_FIFO", SDIO1 + 0x80);
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment