OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_39/] [or1ksim/] [testbench/] [mc_dram.c] - Diff between revs 544 and 552

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 544 Rev 552
Line 24... Line 24...
#include "mc_dram.h"
#include "mc_dram.h"
#include "../peripheral/mc.h"
#include "../peripheral/mc.h"
#include "../peripheral/gpio.h"
#include "../peripheral/gpio.h"
#include "../peripheral/fields.h"
#include "../peripheral/fields.h"
 
 
 
#define T_ROW_SIZE      8
 
#define T_ROW_OFF       5
 
#define T_ROWS          25
 
#define T_GROUPS        3
 
 
typedef volatile unsigned long *REGISTER;
typedef volatile unsigned long *REGISTER;
 
 
unsigned long nRowSize = 0;
/*
unsigned long nColumns = 0;
unsigned long nRowSize = 0;
 
unsigned long nColumns = 0;
 
*/
REGISTER mc_poc        = (unsigned long*)(MC_BASE + MC_POC);
REGISTER mc_poc        = (unsigned long*)(MC_BASE + MC_POC);
REGISTER mc_csr        = (unsigned long*)(MC_BASE + MC_CSR);
REGISTER mc_csr        = (unsigned long*)(MC_BASE + MC_CSR);
REGISTER mc_ba_mask    = (unsigned long*)(MC_BASE + MC_BA_MASK);
REGISTER mc_ba_mask    = (unsigned long*)(MC_BASE + MC_BA_MASK);
 
 
REGISTER rgpio_out     = (unsigned long*)(GPIO_BASE + RGPIO_OUT);
REGISTER rgpio_out     = (unsigned long*)(GPIO_BASE + RGPIO_OUT);
REGISTER rgpio_in      = (unsigned long*)(GPIO_BASE + RGPIO_IN);
REGISTER rgpio_in      = (unsigned long*)(GPIO_BASE + RGPIO_IN);
 
 
unsigned long lpoc;
unsigned long lpoc;
 
unsigned char mc_cs;
 
 
unsigned long set_config()
unsigned long set_config()
{
{
    REGISTER mc_csc;
    REGISTER mc_csc;
    unsigned char ch;
    unsigned char ch;
Line 56... Line 64...
    }
    }
 
 
    return 0;
    return 0;
}
}
 
 
 
unsigned long get_config()
 
{
 
  REGISTER mc_csc;
 
  REGISTER mc_tms;
 
  unsigned char ch;
 
 
 
  mc_cs = 0;
 
  for (ch=0; ch<8; ch++) {
 
    mc_csc = (unsigned long*)(MC_BASE + MC_CSC(ch));
 
    mc_tms = (unsigned long*)(MC_BASE + MC_TMS(ch));
 
    if ( (GET_FIELD(*mc_csc, MC_CSC, MEMTYPE) == 0) &&
 
         (TEST_FLAG(*mc_csc, MC_CSC, EN) == 1     ) ) {
 
      mc_sdram_cs[ch].MS = GET_FIELD(*mc_csc, MC_CSC, MS);
 
      mc_sdram_cs[ch].BW = GET_FIELD(*mc_csc, MC_CSC, BW);
 
      mc_sdram_cs[ch].M  = GET_FIELD(*mc_csc, MC_CSC, SEL);
 
      mc_cs |= (1 << ch);
 
 
 
      printf("get_config(%d) : MS=0x%0lx, BW=0x%0lx, M=0x%0lx\n", ch,
 
             mc_sdram_cs[ch].MS,
 
             mc_sdram_cs[ch].BW,
 
             mc_sdram_cs[ch].M);
 
    }
 
  }
 
  printf("get_config() : cs=0x%0x\n", mc_cs);
 
  return 0;
 
}
 
 
int main()
int main()
{
{
    unsigned long ret;
    unsigned long ret;
    unsigned char ch;
    unsigned char ch;
 
 
Line 69... Line 104...
 
 
    unsigned long nRowSize = 0;
    unsigned long nRowSize = 0;
    unsigned long nRows    = 0;
    unsigned long nRows    = 0;
    unsigned long nRowSh   = 0;
    unsigned long nRowSh   = 0;
    unsigned long nRowGrp  = 0;
    unsigned long nRowGrp  = 0;
    unsigned long nGroups  = 0;
 
 
 
    unsigned long nAddress;
    unsigned long nAddress;
    unsigned long mc_sel;
    unsigned long mc_sel;
    REGISTER mc_tms;
    REGISTER mc_tms;
    REGISTER mc_cs;
    REGISTER mc_csc;
 
 
    *rgpio_out = 0xFFFFFFFF;
    *rgpio_out = 0xFFFFFFFF;
 
 
    /* set configuration */
    /* set configuration */
    randomin(7435);
    randomin(7435);
    lpoc = *mc_poc;
    lpoc = *mc_poc;
    /* MC configuration set in except_mc.S prior to execution of main()
 
    if ( (ret = set_config()) != 0) {
#ifdef MC_READ_CONF
        exit(ret);
    if (get_config()) {
    }
      printf("Error reading MC configuration\n");
    */
      report(0x00000001);
 
      return(1);
 
    }
 
#else
 
    mc_cs = MC_SDRAM_CSMASK;
 
#endif
 
 
    for (ch=0; ch<8; ch++) {
    for (ch=0; ch<8; ch++) {
        if (MC_SDRAM_CSMASK & (0x01 << ch) ) {
        if (mc_cs & (0x01 << ch) ) {
            printf ("--- Begin Test on CS%d ---\n", ch);
            printf ("--- Begin Test on CS%d ---\n", ch);
 
 
            mc_cs  = (unsigned long*)(MC_BASE + MC_CSC(ch));
            mc_csc = (unsigned long*)(MC_BASE + MC_CSC(ch));
            mc_tms = (unsigned long*)(MC_BASE + MC_TMS(ch));
            mc_tms = (unsigned long*)(MC_BASE + MC_TMS(ch));
            mc_sel = GET_FIELD(*mc_cs, MC_CSC, SEL);
            mc_sel = GET_FIELD(*mc_csc, MC_CSC, SEL);
 
 
            SET_FIELD(*mc_tms, MC_TMS_SDRAM, OM, 0); /*normal op*/
            SET_FIELD(*mc_tms, MC_TMS_SDRAM, OM, 0); /*normal op*/
            SET_FIELD(*mc_tms, MC_TMS_SDRAM, CL, 3); /*CAS*/
            SET_FIELD(*mc_tms, MC_TMS_SDRAM, CL, 3); /*CAS*/
 
 
            switch ( mc_sdram_cs[ch].BW + (3 * mc_sdram_cs[ch].MS) ) {
            switch ( mc_sdram_cs[ch].BW + (3 * mc_sdram_cs[ch].MS) ) {
Line 131... Line 171...
                nRows    = MC_SDRAM_ROWS_8;
                nRows    = MC_SDRAM_ROWS_8;
                nRowSh   = MC_SDRAM_ROWSH_8; break;
                nRowSh   = MC_SDRAM_ROWSH_8; break;
            }
            }
 
 
            printf ("CS configuration : CSC - 0x%08lX, TMS - 0x%08lX, rs = %lu, nr = %lu, sh = %lu, sel = %lu\n",
            printf ("CS configuration : CSC - 0x%08lX, TMS - 0x%08lX, rs = %lu, nr = %lu, sh = %lu, sel = %lu\n",
                    *mc_cs, *mc_tms, nRowSize, nRows, nRowSh, mc_sel);
                    *mc_csc, *mc_tms, nRowSize, nRows, nRowSh, mc_sel);
 
 
            nRows -= MC_SDRAM_ROW_OFF;
            /*nRows -= MC_SDRAM_ROW_OFF;*/
            for (test=0; test<16; test++) {
            for (test=0; test<16; test++) {
                /* configure MC*/
                /* configure MC*/
                CLEAR_FLAG(*mc_cs, MC_CSC, PEN); /* no parity */
                CLEAR_FLAG(*mc_csc, MC_CSC, PEN); /* no parity */
                CLEAR_FLAG(*mc_cs, MC_CSC, KRO); /* close row */
                CLEAR_FLAG(*mc_csc, MC_CSC, KRO); /* close row */
                CLEAR_FLAG(*mc_cs, MC_CSC, BAS); /* bank after column */
                CLEAR_FLAG(*mc_csc, MC_CSC, BAS); /* bank after column */
                CLEAR_FLAG(*mc_cs, MC_CSC, WP);  /* write enable */
                CLEAR_FLAG(*mc_csc, MC_CSC, WP);  /* write enable */
                SET_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* single loc access */
                SET_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* single loc access */
                CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, BT); /* sequential burst */
                CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, BT); /* sequential burst */
                SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 0); /* 1 */
                SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 0); /* 1 */
                switch (test) {
                switch (test) {
                case 0:
                case 0:
Line 151... Line 191...
                        continue;
                        continue;
                    break;
                    break;
                case 1:
                case 1:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST1) != MC_SDRAM_TEST1)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST1) != MC_SDRAM_TEST1)
                        continue;
                        continue;
                    SET_FLAG(*mc_cs, MC_CSC, PEN); /* parity */
                    SET_FLAG(*mc_csc, MC_CSC, PEN); /* parity */
                    break;
                    break;
                case 2:
                case 2:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST2) != MC_SDRAM_TEST2)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST2) != MC_SDRAM_TEST2)
                        continue;
                        continue;
                    SET_FLAG(*mc_cs, MC_CSC, KRO); /* keep row */
                    SET_FLAG(*mc_csc, MC_CSC, KRO); /* keep row */
                    break;
                    break;
                case 3:
                case 3:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST3) != MC_SDRAM_TEST3)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST3) != MC_SDRAM_TEST3)
                        continue;
                        continue;
                    SET_FLAG(*mc_cs, MC_CSC, BAS); /* bank after row*/
                    SET_FLAG(*mc_csc, MC_CSC, BAS); /* bank after row*/
                    break;
                    break;
                case 4:
                case 4:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST4) != MC_SDRAM_TEST4)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST4) != MC_SDRAM_TEST4)
                        continue;
                        continue;
                    SET_FLAG(*mc_cs, MC_CSC, WP);  /* RO */
                    SET_FLAG(*mc_csc, MC_CSC, WP);  /* RO */
                    break;
                    break;
                case 5:
                case 5:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST5) != MC_SDRAM_TEST5)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST5) != MC_SDRAM_TEST5)
                        continue;
                        continue;
                    CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* burst */
                    CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* burst */
Line 234... Line 274...
                    SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 7); /* fullrow */
                    SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 7); /* fullrow */
                    break;
                    break;
                case 15:
                case 15:
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST15) != MC_SDRAM_TEST15)
                    if ((MC_SDRAM_TESTS & MC_SDRAM_TEST15) != MC_SDRAM_TEST15)
                        continue;
                        continue;
                    SET_FLAG(*mc_cs, MC_CSC, KRO);  /* keep row */
                    SET_FLAG(*mc_csc, MC_CSC, KRO);  /* keep row */
                    CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* burst */
                    CLEAR_FLAG(*mc_tms, MC_TMS_SDRAM, WBL); /* burst */
                    SET_FLAG(*mc_tms, MC_TMS_SDRAM, BT); /* interleaved burst */
                    SET_FLAG(*mc_tms, MC_TMS_SDRAM, BT); /* interleaved burst */
                    SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 1); /* 2 */
                    SET_FIELD(*mc_tms, MC_TMS_SDRAM, BL, 1); /* 2 */
                    break;
                    break;
                } /*switch test*/
                } /*switch test*/
 
 
                printf ("Begin TEST %lu : CSC - 0x%08lX, TMS - 0x%08lX\n", test, *mc_cs, *mc_tms);
                printf ("Begin TEST %lu : CSC - 0x%08lX, TMS - 0x%08lX\n", test, *mc_csc, *mc_tms);
 
 
                if (MC_SDRAM_ACC & MC_SDRAM_SROW) {
                if (MC_SDRAM_ACC & MC_SDRAM_SROW) {
                    /* perform sequential row access */
                    /* perform sequential row access */
                    printf("Seuential Row\n");
                    printf("Seuential Row\n");
                    for (j=MC_SDRAM_ROW_OFF; j<nRows/2; j++) {
                    for (j=0; j<T_ROWS; j++) {
                        nAddress  = mc_sel << 21;
                        nAddress  = mc_sel << 21;
                        nAddress |= MC_MEM_BASE;
                        nAddress |= MC_MEM_BASE;
                        nAddress += (j << nRowSh);
                        nAddress += ( (j + T_ROW_OFF) << nRowSh);
 
 
                        gpio_pat ^= 0x00000008;
                        gpio_pat ^= 0x00000008;
                        *rgpio_out = gpio_pat;
                        *rgpio_out = gpio_pat;
                        ret = mc_test_row(nAddress, nAddress + nRowSize, MC_SDRAM_FLAGS);
                        ret = mc_test_row(nAddress, nAddress + T_ROW_SIZE, MC_SDRAM_FLAGS);
 
 
                        printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
                        printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
 
 
                        if (ret) {
                        if (ret) {
                            gpio_pat ^= 0x00000080;
                            gpio_pat ^= 0x00000080;
Line 269... Line 309...
                }
                }
 
 
                if (MC_SDRAM_ACC & MC_SDRAM_RROW) {
                if (MC_SDRAM_ACC & MC_SDRAM_RROW) {
                    /* perform random row access */
                    /* perform random row access */
                    printf("Random Row\n");
                    printf("Random Row\n");
                    for (j=MC_SDRAM_ROW_OFF; j<nRows/2; j++) {
                    for (j=0; j<T_ROWS; j++) {
                        nAddress = mc_sel << 21;
                        nAddress = mc_sel << 21;
                        nAddress |= MC_MEM_BASE;
                        nAddress |= MC_MEM_BASE;
                        nAddress += ( (MC_SDRAM_ROW_OFF + random(nRows)) << nRowSh);
                        nAddress += ( (T_ROW_OFF + random(nRows)) << nRowSh);
 
 
                        gpio_pat ^= 0x00000008;
                        gpio_pat ^= 0x00000008;
                        *rgpio_out = gpio_pat;
                        *rgpio_out = gpio_pat;
                        ret = mc_test_row(nAddress, nAddress + nRowSize, MC_SDRAM_FLAGS);
                        ret = mc_test_row(nAddress, nAddress + T_ROW_SIZE, MC_SDRAM_FLAGS);
 
 
                        printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
                        printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
 
 
                        if (ret) {
                        if (ret) {
                            gpio_pat ^= 0x00000080;
                            gpio_pat ^= 0x00000080;
                            *rgpio_out = gpio_pat;
                            *rgpio_out = gpio_pat;
 
                            report(ret);
                            return ret;
                            return ret;
                        }
                        }
                    }
                    }
                }
                }
 
 
                if (MC_SDRAM_ACC & MC_SDRAM_SGRP) {
                if (MC_SDRAM_ACC & MC_SDRAM_SGRP) {
                    /* perform sequential row in group access */
                    /* perform sequential row in group access */
                    printf("Sequential Group ");
                    printf("Sequential Group ");
 
 
                    nGroups = MC_SDRAM_GROUPSIZE;
                    printf("Group Size = %d\n", MC_SDRAM_GROUPSIZE);
                    printf("Group Size = %lu\n", nGroups);
                    for (i=0; i<T_GROUPS; i++) {
                    for (i=nRows/nGroups-1; i<nRows/nGroups; i++) {
                        nRowGrp = random(nRows - MC_SDRAM_GROUPSIZE) + T_ROW_OFF;
                        nRowGrp = random(nRows - nGroups) + MC_SDRAM_ROW_OFF;
                        for (j=0; j<MC_SDRAM_GROUPSIZE; j++) {
                        for (j=0; j<nGroups; j++) {
 
                            nAddress = mc_sel << 21;
                            nAddress = mc_sel << 21;
                            nAddress |= MC_MEM_BASE;
                            nAddress |= MC_MEM_BASE;
                            nAddress += ((nRowGrp+j) << nRowSh);
                            nAddress += ((nRowGrp+j) << nRowSh);
 
 
                            gpio_pat ^= 0x00000008;
                            gpio_pat ^= 0x00000008;
                            *rgpio_out = gpio_pat;
                            *rgpio_out = gpio_pat;
                            ret = mc_test_row(nAddress, nAddress + nRowSize, MC_SDRAM_FLAGS);
                            ret = mc_test_row(nAddress, nAddress + T_ROW_SIZE, MC_SDRAM_FLAGS);
 
 
                            printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
                            printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
 
 
                            if (ret) {
                            if (ret) {
                                gpio_pat ^= 0x00000080;
                                gpio_pat ^= 0x00000080;
Line 321... Line 361...
 
 
                if (MC_SDRAM_ACC & MC_SDRAM_RGRP) {
                if (MC_SDRAM_ACC & MC_SDRAM_RGRP) {
                    /* perform random row in group access */
                    /* perform random row in group access */
                    printf("Random Group ");
                    printf("Random Group ");
 
 
                    nGroups = MC_SDRAM_GROUPSIZE;
                    printf("Group Size = %d\n", MC_SDRAM_GROUPSIZE);
                    printf("Group Size = %lu\n", nGroups);
                    for (i=0; i<T_GROUPS; i++) {
                    for (i=(nRows/nGroups)-1; i<nRows/nGroups; i++) {
                        nRowGrp = random(nRows - T_GROUPS) + T_ROW_OFF;
                        nRowGrp = random(nRows - nGroups) + MC_SDRAM_ROW_OFF;
                        for (j=0; j<MC_SDRAM_GROUPSIZE; j++) {
                        for (j=0; j<nGroups; j++) {
 
                            nAddress = mc_sel << 21;
                            nAddress = mc_sel << 21;
                            nAddress |= MC_MEM_BASE;
                            nAddress |= MC_MEM_BASE;
                            nAddress += ((nRowGrp + random(nGroups)) << nRowSh);
                            nAddress += ((nRowGrp + random(MC_SDRAM_GROUPSIZE)) << nRowSh);
 
 
                            gpio_pat ^= 0x00000008;
                            gpio_pat ^= 0x00000008;
                            *rgpio_out = gpio_pat;
                            *rgpio_out = gpio_pat;
                            ret = mc_test_row(nAddress, nAddress + nRowSize, MC_SDRAM_FLAGS);
                            ret = mc_test_row(nAddress, nAddress + T_ROW_SIZE, MC_SDRAM_FLAGS);
 
 
                            printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
                            printf("\trow - %lu: nAddress = 0x%08lX, ret = 0x%08lX\n", j, nAddress, ret);
 
 
                            if (ret) {
                            if (ret) {
                                gpio_pat ^= 0x00000080;
                                gpio_pat ^= 0x00000080;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.