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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [exe/] [main.cpp] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
/*
2
 * This file is subject to the terms and conditions of the BSD License. See
3
 * the file "LICENSE" in the main directory of this archive for more details.
4
 *
5
 * Copyright (C) 2014 Aleksander Osman
6
 */
7
 
8
#include <cstdio>
9
#include <cstring>
10
 
11
#include <io.h>
12
#include <system.h>
13
 
14
int tst_0() {
15
    volatile unsigned char buf[512];
16
 
17
    int status = IORD(DRIVER_SD_0_BASE, 0);
18
 
19
    printf("SD card status: %d\n", status);
20
 
21
    memset((void *)buf, 0, sizeof(buf));
22
 
23
    IOWR(DRIVER_SD_0_BASE, 0, (int)buf);
24
    IOWR(DRIVER_SD_0_BASE, 1, 0);
25
    IOWR(DRIVER_SD_0_BASE, 2, 1);
26
    IOWR(DRIVER_SD_0_BASE, 3, 2); //read
27
 
28
    while(1) {
29
        status = IORD(DRIVER_SD_0_BASE, 0);
30
        printf("SD card status for read: %d\n", status);
31
 
32
        if(status == 2) break;
33
    }
34
 
35
    int i;
36
    for(i=0; i<512; i++) {
37
        if(i > 0 && (i%32) == 0) printf("\n");
38
 
39
        printf("%02x ", buf[i]);
40
    }
41
    printf("\n");
42
 
43
    for(i=0; i<512; i++) if(buf[i] != (unsigned char)i) printf("Not Equal: %d\n", i);
44
 
45
    for(i=0; i<512; i++) buf[i] = i;
46
 
47
    IOWR(DRIVER_SD_0_BASE, 0, (int)buf);
48
    IOWR(DRIVER_SD_0_BASE, 1, 0);
49
    IOWR(DRIVER_SD_0_BASE, 2, 1);
50
    IOWR(DRIVER_SD_0_BASE, 3, 3); //write
51
 
52
    while(1) {
53
        status = IORD(DRIVER_SD_0_BASE, 0);
54
        printf("SD card status for write: %d\n", status);
55
 
56
        if(status == 2) break;
57
    }
58
 
59
    return 0;
60
}
61
 
62
int tst_1() {
63
 
64
        unsigned char buf[1024];
65
 
66
        //IOWR(DRIVER_SD_0_BASE, 3, 1);
67
 
68
        while(IORD(DRIVER_SD_0_BASE, 0) != 2);
69
 
70
        printf("card init\n");
71
 
72
        unsigned char *slow_mem = (unsigned char *)0x08011000;
73
        for(int i=0; i<1024; i++) slow_mem[i] = i*3;
74
 
75
        /*
76
        for(int i=0; i<1024; i++) {
77
                if(i > 0 && (i%16) == 0) printf("\n");
78
                printf("%02x ", slow_mem[i]);
79
        }
80
        printf("\n----------\n");
81
        */
82
 
83
        IOWR(DRIVER_SD_0_BASE, 0, (int)slow_mem);
84
        IOWR(DRIVER_SD_0_BASE, 1, 5859380);
85
        IOWR(DRIVER_SD_0_BASE, 2, 2);
86
        IOWR(DRIVER_SD_0_BASE, 3, 3);
87
 
88
        while(IORD(DRIVER_SD_0_BASE, 0) != 2);
89
 
90
        memset((void *)slow_mem, 0, sizeof(buf));
91
        memset((void *)buf,      0, sizeof(buf));
92
 
93
        for(int i=0; i<2; i++) {
94
                IOWR(DRIVER_SD_0_BASE, 0, (i==0)? (int)buf : (int)slow_mem);
95
                IOWR(DRIVER_SD_0_BASE, 1, 5859380);
96
                IOWR(DRIVER_SD_0_BASE, 2, 2);
97
                IOWR(DRIVER_SD_0_BASE, 3, 2);
98
 
99
                while(IORD(DRIVER_SD_0_BASE, 0) != 2);
100
        }
101
 
102
        if(memcmp((const void*)slow_mem, (const void *)buf, sizeof(buf)) != 0) printf("read mismatch !\n");
103
 
104
        int mismatched = 0;
105
        for(int i=0; i<1024; i++) {
106
                if(buf[i] != ((i*3) & 0xFF)) mismatched++;
107
        }
108
        printf("\nmismatched: %d\n", mismatched);
109
 
110
        if(mismatched > 0) {
111
                for(int i=0; i<1024; i++) {
112
                        if(i > 0 && (i%16) == 0) printf("\n");
113
                        printf("%02x ", slow_mem[i]);
114
                }
115
                printf("\n");
116
                for(int i=0; i<1024; i++) {
117
                        if(i > 0 && (i%16) == 0) printf("\n");
118
                        printf("%02x ", buf[i]);
119
                }
120
        }
121
        printf("\n");
122
 
123
        return 0;
124
}
125
 
126
int main() {
127
 
128
        while(IORD(DRIVER_SD_0_BASE, 0) != 2);
129
 
130
        printf("card init\n");
131
 
132
        tst_0();
133
 
134
        printf("filling memory from sd card...\n");
135
 
136
        unsigned char *sdram_ptr = (unsigned char *)0x00000000;
137
 
138
        IOWR(DRIVER_SD_0_BASE, 0, (int)sdram_ptr);
139
        IOWR(DRIVER_SD_0_BASE, 1, 0);
140
        IOWR(DRIVER_SD_0_BASE, 2, 262144);
141
        IOWR(DRIVER_SD_0_BASE, 3, 2); //read
142
 
143
        while(IORD(DRIVER_SD_0_BASE, 0) != 2);
144
 
145
        printf("done\n");
146
 
147
        return 0;
148
}
149
 
150
 

powered by: WebSVN 2.1.0

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