tstsdram.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:8k
源码类别:

DVD

开发平台:

C/C++

  1. #include "config.h"
  2. #include "regmap.h"
  3. #include "global.h"
  4. #include "cpu.h"
  5. #include "uart.h"
  6. static inline void flush_lbc(void)
  7. {
  8.     int o_md;
  9.     regs0->lbc_control = 3;
  10.     for (o_md=0;o_md<10000;o_md++) if ((regs0->lbc_control&1)==0) break;
  11. }
  12. #define REPORT_ONLY_PASS
  13. //#define TSTART  0x180000                      // start from 1.5MB 
  14. //#define TLEN    0x40000                    // test 1MB
  15. #define TSTART  (128*1024)                      // from 128k
  16. #define TLEN    (2048*1024 - TSTART)
  17. void  
  18. test_sdram(void)
  19. {
  20.     int o_md,o_dly,i_md,i_dly;
  21.     int hwd_drv, bt1_drv, bt0_drv, ctl_drv, clko_drv;
  22.     int i_bypass;
  23.     UINT32 *p;
  24.     cpu_intr_disable();
  25.     UART0_puts("sdram_testn");
  26.     o_md = regs0->hw_cfg;
  27.     UART0_puts("hwcfg mode:"); UART0_puthex(o_md); UART0_puts("n");
  28.     o_md = regs0->sysclk_sel; o_dly = regs0->sysclk_div_sel;
  29.     UART0_puts("pllsel mode:"); UART0_puthex4(o_md); UART0_puts(" "); UART0_puthex4(o_dly); UART0_puts("n");
  30.     UART0_puts("test from $"); UART0_puthex(TSTART); UART0_puts("n");
  31.     UART0_puts("test leng $"); UART0_puthex(TLEN); UART0_puts("n");
  32.     regs0->sdram_clko_cfg  = 0x33;                       // 05    5      (0014)  
  33.     regs0->sdram_clki_cfg  = 0x0;                        // 06    6      (0018)
  34.     regs0->sdram_clki_dly_cfg = 0x80;                    // 07    7      (001c)
  35.     regs0->pad_ctrl = 0xaaff; // all 20mA drive
  36. //    regs0->pad_ctrl = 0xaaaa; // all 12mA drive
  37. //    regs0->pad_ctrl = 0x5555; // all 8mA drive
  38.   //   regs0->pad_ctrl = 0x555B; // all 8mA drive
  39.     p = (UINT32 *)(0xa0000000 + TSTART);
  40. //    for (hwd_drv=1;hwd_drv<=3;hwd_drv++)
  41. //    {
  42. //    for (bt1_drv=1;bt1_drv<=3;bt1_drv++)
  43. //    {
  44. //    for (bt0_drv=1;bt0_drv<=3;bt0_drv++)
  45. //    {
  46. //    for (ctl_drv=1;ctl_drv<=3;ctl_drv++)
  47. //    {
  48. //    for (clko_drv=1;clko_drv<=3;clko_drv++)
  49. //    {
  50.     
  51.           hwd_drv = 1;
  52.           bt1_drv = 1;
  53.           bt0_drv = 1;
  54.           ctl_drv = 2;
  55.           clko_drv = 3;
  56. //            regs0->pad_ctrl = 0x5000 | 
  57.             regs0->pad_ctrl = 0x5000 | 
  58.              (hwd_drv<<10) |
  59.              (hwd_drv<<8) |
  60.              (bt1_drv<<6) |
  61.              (bt0_drv<<4) |
  62.              (ctl_drv<<2) |
  63.               clko_drv; 
  64. //regs0->pad_ctrl = 0xaaff;
  65.             UART0_puts("nhwd-bt1-bt0-ctl-clko drv = ");
  66.             UART0_puthex4(hwd_drv);UART0_puts("-");
  67.             UART0_puthex4(bt1_drv);UART0_puts("-");
  68.             UART0_puthex4(bt0_drv);UART0_puts("-");
  69.             UART0_puthex4(ctl_drv);UART0_puts("-");
  70.             UART0_puthex4(clko_drv);UART0_puts(" ");
  71.             UART0_puthex4(regs0->pad_ctrl);UART0_puts("n");
  72. //    for (i_bypass=0; i_bypass<2; i_bypass++)
  73.     for (i_bypass=1; i_bypass<2; i_bypass++)
  74.     {
  75.     for (o_md=0;o_md<=5;o_md++)
  76.     {
  77.     for (o_dly=0;o_dly<16;o_dly++)
  78.     {
  79.         int j_pass=0;
  80.         // OUT: o_dly:o_md
  81.         if (o_md!=0 && o_md!=1) continue;
  82.         for (i_md=0;i_md<8;i_md++)
  83.         {
  84.             if (i_md==2) continue;
  85.             if (i_md==3) continue;
  86.             if (i_md==4) continue;
  87.             if (i_md==5) continue;
  88.         for (i_dly=0;i_dly<16;i_dly++)
  89.         {
  90.             // IN: i_dly:i_md
  91.             int tst, failed, failed_total;
  92.             failed_total = 0;
  93.             UART0_puts("r");
  94.             UART0_puthex4(o_dly); UART0_puthex4(o_md);
  95.             UART0_puthex4(i_dly); UART0_puthex4(i_md);
  96. #ifndef REPORT_ONLY_PASS
  97.             UART0_puts("rsdram_test");
  98.             UART0_puts(" OUT ");
  99.             UART0_puthex4(o_dly); UART0_puts("-"); UART0_puthex4(o_md);
  100.             UART0_puts(" IN ");
  101.             UART0_puthex4(i_dly); UART0_puts("-"); UART0_puthex4(i_md);
  102.             UART0_puts("n");
  103. #endif
  104. o_md = 0;
  105.             regs0->sdram_clko_cfg       = (o_dly<<3)|(o_md);
  106.             if (i_bypass==0) {
  107.                 regs0->sdram_clki_cfg       = (i_dly<<3)|(i_md);
  108.             } else {
  109.                 regs0->sdram_clki_dly_cfg   = (1<<7) | (i_dly<<3)|(i_md);
  110.             }
  111.             regs0->sdctrl_mrs       = 1;
  112.             for (tst=0;tst<1024;tst++) asm volatile ("nop");
  113.             for (tst=0;tst<TLEN/4;tst++) p[tst] = 0;
  114.             // write 0
  115.             for (tst=0;tst<TLEN/4;tst++) p[tst] = 0x00000000;
  116.             flush_lbc();
  117.             for (tst=failed=0;tst<TLEN/4;tst++) if (p[tst]!=0x00000000) {
  118.                 failed++;}
  119. #ifdef REPORT_ONLY_PASS
  120.             if (failed!=0) continue;
  121. #else
  122.             if (failed!=0) {
  123.                 UART0_puts("ttst0 failed "); UART0_puthex(failed);
  124.                 UART0_puts("n");
  125.             }
  126. //            else UART0_puts("ttst0 okn");
  127. #endif
  128.             failed_total += failed;
  129.             // write 00000000-ffffffff
  130.             for (tst=0;tst<TLEN/4;tst+=2) {
  131.                 p[tst+0] = 0xffffffff;
  132.                 p[tst+1] = 0x00000000;
  133.             }
  134.             flush_lbc();
  135.             for (tst=failed=0;tst<TLEN/4;tst+=2) {
  136.                 if (p[tst+0]!=0xffffffff) {failed++;}
  137.                 if (p[tst+1]!=0x00000000) {failed++;}
  138.             }
  139. #ifdef REPORT_ONLY_PASS
  140.             if (failed!=0) continue;
  141. #else
  142.             if (failed!=0) {
  143.                 UART0_puts("ttst1 failed "); UART0_puthex(failed);
  144.                 UART0_puts("n");
  145.             }
  146. //            else UART0_puts("ttst1 okn");
  147. #endif
  148.             failed_total += failed;
  149.             // write 5555aaaa
  150.             for (tst=0;tst<TLEN/4;tst+=2) {
  151.                 p[tst+0] = 0x5555aaaa;
  152.                 p[tst+1] = 0xffff0000;
  153.             }
  154.             flush_lbc();
  155.             for (tst=failed=0;tst<TLEN/4;tst+=2) {
  156.                 if (p[tst+0]!=0x5555aaaa) {failed++;}
  157.                 if (p[tst+1]!=0xffff0000) {failed++;}
  158.             }
  159. #ifdef REPORT_ONLY_PASS
  160.             if (failed!=0) continue;
  161. #else
  162.             if (failed!=0) {
  163.                 UART0_puts("ttst2 failed "); UART0_puthex(failed);
  164.                 UART0_puts("n");
  165.             }
  166. //            else UART0_puts("ttst2 okn");
  167. #endif
  168.             failed_total += failed;
  169.             // write sequential number
  170.             for (tst=0;tst<TLEN/4;tst++) p[tst] = tst;
  171.             flush_lbc();
  172.             for (tst=failed=0;tst<TLEN/4;tst++) if (p[tst]!=(UINT32)tst) {failed++;}
  173. #ifdef REPORT_ONLY_PASS
  174.             if (failed!=0) continue;
  175. #else
  176.             if (failed!=0) {
  177.                 UART0_puts("ttst3 failed "); UART0_puthex(failed);
  178.                 UART0_puts("n");
  179.             }
  180. //            else UART0_puts("ttst3 okn");
  181. #endif
  182.             failed_total += failed;
  183.             // write sequential number and toggle pattern
  184.             for (tst=0;tst<TLEN/4;tst++) p[tst] = (tst<<16)|(0x55aa);
  185.             flush_lbc();
  186.             for (tst=failed=0;tst<TLEN/4;tst++) if (p[tst]!=(((UINT32)tst<<16)|(0x55aa))) {failed++;}
  187. #ifdef REPORT_ONLY_PASS
  188.             if (failed!=0) continue;
  189. #else
  190.             if (failed!=0) {
  191.                 UART0_puts("ttst4 failed "); UART0_puthex(failed);
  192.                 UART0_puts("n");
  193.             }
  194. //            else UART0_puts("ttst4 okn");
  195. #endif
  196.             failed_total += failed;
  197. #ifdef REPORT_ONLY_PASS
  198.             if (failed_total==0)
  199. #endif
  200.             {
  201.                 UART0_puts("r    sdram_test config ");
  202.                 if (i_bypass) UART0_puts("bypass ");
  203.                 UART0_puts(" OUT ");
  204.                 UART0_puthex4(o_dly); UART0_puts("-"); UART0_puthex4(o_md);
  205.                 UART0_puts(" IN ");
  206.                 UART0_puthex4(i_dly); UART0_puts("-"); UART0_puthex4(i_md);
  207.                 if (failed_total)
  208.                     UART0_puts(" failedn");
  209.                 else
  210.                     UART0_puts(" passedn");
  211.             }
  212.             if (failed_total==0)
  213.                 j_pass++;
  214.         }
  215.         }
  216. #ifdef REPORT_ONLY_PASS
  217.         if (j_pass)
  218. #endif
  219.         {
  220.             UART0_puts("r    sdram_test config ");
  221.             UART0_puts(" OUT ");
  222.             UART0_puthex4(o_dly); UART0_puts("-"); UART0_puthex4(o_md);
  223.             UART0_puts(" passed ");
  224.             UART0_puthex4(j_pass); 
  225.             UART0_puts("n");
  226.         }
  227.     }
  228.     }
  229.     }
  230. //    }
  231. //    }
  232. //    }
  233. //    }
  234. //    }
  235.     UART0_puts("sdram test finishedn");
  236.     while (1);
  237. }