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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [or1ksim/] [or1ksim-0.3.0/] [testbench/] [mc_sync.c] - Blame information for rev 783

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jeremybenn
/* mc_sync.c - Memory Controller testbench SYNCdevice test
2
         Copyright (C) 2001 by Ivan Guzvinec, ivang@opencores.org
3
 
4
         This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
         This program is free software; you can redistribute it and/or modify
7
         it under the terms of the GNU General Public License as published by
8
         the Free Software Foundation; either version 2 of the License, or
9
         (at your option) any later version.
10
 
11
         This program is distributed in the hope that it will be useful,
12
         but WITHOUT ANY WARRANTY; without even the implied warranty of
13
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
14
         GNU General Public License for more details.
15
 
16
         You should have received a copy of the GNU General Public License
17
         along with this program; if not, write to the Free Software
18
         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
20
 
21
#include "support.h"
22
 
23
#include "mc_common.h"
24
#include "mc_sync.h"
25
#include "../peripheral/mc.h"
26
#include "../peripheral/gpio.h"
27
#include "../peripheral/fields.h"
28
 
29
typedef volatile unsigned long *REGISTER;
30
 
31
REGISTER mc_poc        = (unsigned long*)(MC_BASE + MC_POC);
32
REGISTER mc_csr        = (unsigned long*)(MC_BASE + MC_CSR);
33
REGISTER mc_ba_mask    = (unsigned long*)(MC_BASE + MC_BA_MASK);
34
 
35
REGISTER rgpio_out     = (unsigned long*)(GPIO_BASE + RGPIO_OUT);
36
REGISTER rgpio_in      = (unsigned long*)(GPIO_BASE + RGPIO_IN);
37
 
38
unsigned long lpoc;
39
unsigned char mc_cs;
40
 
41
unsigned long set_config()
42
{
43
    REGISTER mc_csc;
44
    unsigned char ch;
45
 
46
    lpoc = *mc_poc;
47
 
48
    for (ch=0; ch<8; ch++) {
49
        if (MC_SYNC_CSMASK & (0x01 << ch) ) {
50
            mc_csc = (unsigned long*)(MC_BASE + MC_CSC(ch));
51
            SET_FIELD(*mc_csc, MC_CSC, SEL, mc_sync_cs[ch].M);
52
            SET_FIELD(*mc_csc, MC_CSC, BW,  2);
53
            SET_FLAG(*mc_csc, MC_CSC, EN);
54
            printf ("Channel Config %d - CSC = 0x%08lX\n", ch, *mc_csc);
55
        }
56
    }
57
 
58
    return 0;
59
}
60
 
61
unsigned long get_config()
62
{
63
  REGISTER mc_csc;
64
  REGISTER mc_tms;
65
  unsigned char ch;
66
 
67
  mc_cs = 0;
68
  for (ch=0; ch<8; ch++) {
69
    mc_csc = (unsigned long*)(MC_BASE + MC_CSC(ch));
70
    mc_tms = (unsigned long*)(MC_BASE + MC_TMS(ch));
71
    if ( (GET_FIELD(*mc_csc, MC_CSC, MEMTYPE) == 3) &&
72
         (TEST_FLAG(*mc_csc, MC_CSC, EN) == 1     ) ) {
73
      mc_sync_cs[ch].M  = GET_FIELD(*mc_csc, MC_CSC, SEL);
74
      mc_cs |= (1 << ch);
75
 
76
      printf("get_config(%d) : M=0x%0lx\n", ch,
77
             mc_sync_cs[ch].M);
78
    }
79
  }
80
  printf("get_config() : cs=0x%0x\n", mc_cs);
81
  return 0;
82
}
83
 
84
int main()
85
{
86
    unsigned long ret;
87
    unsigned char ch;
88
 
89
    unsigned long test;
90
    unsigned long gpio_pat = 0;
91
 
92
    unsigned long nAddress;
93
    unsigned long nMemSize;
94
    unsigned long mc_sel;
95
    REGISTER mc_tms;
96
    REGISTER mc_csc;
97
 
98
    *rgpio_out = 0xFFFFFFFF;
99
 
100
#ifdef MC_READ_CONF
101
    if (get_config()) {
102
      printf("Error reading MC configuration.\n");
103
      report(1);
104
      return(1);
105
    }
106
#else
107
    mc_cs = MC_ASYNC_CSMASK;
108
#endif
109
 
110
    *rgpio_out = 0;
111
    for (ch=0; ch<8; ch++) {
112
        if (MC_SYNC_CSMASK & (0x01 << ch) ) {
113
            printf ("--- Begin Test on CS%d ---\n", ch);
114
 
115
            mc_csc = (unsigned long*)(MC_BASE + MC_CSC(ch));
116
            mc_tms = (unsigned long*)(MC_BASE + MC_TMS(ch));
117
            mc_sel = GET_FIELD(*mc_csc, MC_CSC, SEL);
118
 
119
            printf ("CS configuration : CSC - 0x%08lX, TMS - 0x%08lXu\n",
120
                    *mc_csc, *mc_tms);
121
 
122
            for (test=0; test<4; test++) {
123
                /* configure MC*/
124
                CLEAR_FLAG(*mc_csc, MC_CSC, PEN); /* no parity */
125
                CLEAR_FLAG(*mc_csc, MC_CSC, BAS); /* bank after column */
126
                CLEAR_FLAG(*mc_csc, MC_CSC, WP);  /* write enable */
127
 
128
                switch (test) {
129
                case 0:
130
                    if ((MC_SYNC_TESTS & MC_SYNC_TEST0) != MC_SYNC_TEST0)
131
                        continue;
132
                    break;
133
                case 1:
134
                    if ((MC_SYNC_TESTS & MC_SYNC_TEST1) != MC_SYNC_TEST1)
135
                        continue;
136
                    SET_FLAG(*mc_csc, MC_CSC, PEN); /* parity */
137
                    break;
138
                case 2:
139
                    if ((MC_SYNC_TESTS & MC_SYNC_TEST2) != MC_SYNC_TEST2)
140
                        continue;
141
                    SET_FLAG(*mc_csc, MC_CSC, BAS); /* bank after row */
142
                    break;
143
                case 3:
144
                    if ((MC_SYNC_TESTS & MC_SYNC_TEST3) != MC_SYNC_TEST3)
145
                        continue;
146
                    SET_FLAG(*mc_csc, MC_CSC, WP);  /* RO */
147
                    break;
148
                } /*switch test*/
149
 
150
                printf ("Begin TEST %lu : CSC - 0x%08lX, TMS - 0x%08lX\n", test, *mc_csc, *mc_tms);
151
 
152
                nAddress = mc_sel << 21;
153
                nAddress |= MC_MEM_BASE;
154
                nMemSize = ( ((*mc_ba_mask & 0x000000FF) + 1) << 21);
155
 
156
                gpio_pat ^= 0x00000008;
157
                *rgpio_out = gpio_pat;
158
                ret = mc_test_row(nAddress, nAddress + nMemSize, MC_SYNC_FLAGS);
159
 
160
                printf("\trow tested: nAddress = 0x%08lX, ret = 0x%08lX\n", nAddress, ret);
161
 
162
                if (ret) {
163
                    gpio_pat ^= 0x00000080;
164
                    *rgpio_out = gpio_pat;
165
                    report(ret);
166
                    return ret;
167
                }
168
 
169
            } /*for test*/
170
        } /*if*/
171
    } /*for CS*/
172
    printf("--- End SYNC tests ---\n");
173
    report(0xDEADDEAD);
174
 
175
    gpio_pat ^= 0x00000020;
176
    *rgpio_out = gpio_pat;
177
 
178
    return 0;
179
} /* main */

powered by: WebSVN 2.1.0

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