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

Subversion Repositories pci

[/] [pci/] [tags/] [working_demo/] [apps/] [sw/] [driver/] [sdram_test.c] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
#include <sys/types.h>        
2
#include <sys/stat.h>        
3
#include <fcntl.h>  
4
#include <malloc.h>
5
#include <unistd.h>
6
#include <stdio.h>
7
#include <spartan_kint.h>
8
#include <sys/ioctl.h>
9
 
10
int main()
11
{
12
        int result ;
13
        int fd ;
14
        unsigned long *buf ;
15
        unsigned long value ;
16
        unsigned long base ;
17
        unsigned long base_size ;
18
 
19
        fd = open("/dev/spartan", O_RDWR) ;
20
 
21
        if (fd < 0)
22
                return fd ;
23
 
24
        buf = (void *)malloc(4) ;
25
 
26
        if (buf == NULL)
27
                return -1 ;
28
 
29
        // probe driver
30
        result = ioctl(fd, SPARTAN_IOC_CURRESGET) ;
31
 
32
        if (result > 0)
33
                printf("Driver reports enabled resource although it was not enabled through ioctl yet\n!") ;
34
 
35
        result = ioctl(fd, SPARTAN_IOC_NUMOFRES) ;
36
        if (result != 2)
37
                printf("SDRAM reference design implements 2 BARs, driver reported %d!\n", result) ;
38
 
39
        result = ioctl(fd, SPARTAN_IOC_CURBASE, &base) ;
40
        if (base)
41
                printf("Driver reports base address resource selected although it was not yet initialized!\n") ;
42
 
43
        result = ioctl(fd, SPARTAN_IOC_CURBASEMAP, &base) ;
44
 
45
        if (base)
46
                printf("Driver reports base address remaped although it was not yet initialized!\n") ;
47
 
48
        result = ioctl(fd, SPARTAN_IOC_CURBASESIZE, &base_size) ;
49
        if (base_size)
50
                printf("Driver reports base address range non-zero although it was not yet initialized!\n") ;
51
 
52
        // activate resource 1
53
        value = 0x00000001 ;
54
        result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ;
55
 
56
        if (result)
57
                 printf("Driver reported failure to intialize resource 1 !\n") ;
58
 
59
        // activate resource 2
60
        value = 0x00000002 ;
61
        result = ioctl(fd, SPARTAN_IOC_CURRESSET, value) ;
62
 
63
        if (result)
64
                 printf("Driver reported failure to intialize resource 2!\n") ;
65
 
66
        // check if ioctl returns any meaningful values!
67
        result = ioctl(fd, SPARTAN_IOC_CURRESGET) ;
68
 
69
        if (result != 2)
70
                printf("Resource 2 was enabled, driver reports resurce %d active!\n", result) ;
71
 
72
        result = ioctl(fd, SPARTAN_IOC_CURBASE, &base) ;
73
        if (!base)
74
                printf("Driver should report non-zero base address when resource is selected!\n") ;
75
        else
76
                printf("Driver reports SDRAM at address %X\n", base) ;
77
 
78
        result = ioctl(fd, SPARTAN_IOC_CURBASEMAP, &base) ;
79
 
80
        if (!base)
81
                printf("Driver reports zero page base address although resource 2 is supposed to be enabled!\n") ;
82
        else
83
                printf("Driver reports SDRAM at remaped address %X\n", base) ;
84
 
85
        result = ioctl(fd, SPARTAN_IOC_CURBASESIZE, &base_size) ;
86
        if (!base_size)
87
                printf("Driver reports zero base address range although resource is supposed to be enabled\n") ;
88
        else
89
                printf("Driver reports SDRAM size %li\n", base_size) ;
90
 
91
        value  = 0x00000001 ;
92
        *(buf) = value ;
93
        while ((result = write(fd, buf, 4)) > 0)
94
        {
95
                value = value + 1 ;
96
                *(buf) = value ;
97
        }
98
 
99
        printf("%li writes succesfull!\n", value-1) ;
100
 
101
        // go back to start of image
102
        value = lseek(fd, 0, 0) ;
103
        if (result != 0)
104
        {
105
                printf("Seek didn't reset offset to 0i\n") ;
106
                return -1 ;
107
        }
108
        value = 0x00000001 ;
109
        while ((result = read(fd, buf, 4)) > 0)
110
        {
111
                if (value != *buf)
112
                        printf("Expected value was %X, actually read value was %X\n", value, *buf) ;
113
 
114
                value = value + 1 ;
115
        }
116
 
117
        printf("%li reads done!\n", value-1) ;
118
        close(fd) ;
119
        return result ;
120
}

powered by: WebSVN 2.1.0

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