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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [dmatest.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 258 erez
/* DMA test */
2
 
3
#include "support.h"
4 970 simons
#include "board.h"
5 258 erez
#include "../peripheral/fields.h"
6 1355 nogj
#include "../peripheral/dma_defs.h"
7 258 erez
 
8
typedef volatile unsigned long *DMA_REG;
9
 
10
DMA_REG csr = (unsigned long *)(DMA_BASE + DMA_CSR),
11
    int_msk_a = (unsigned long *)(DMA_BASE + DMA_INT_MSK_A),
12
    int_msk_b = (unsigned long *)(DMA_BASE + DMA_INT_MSK_B),
13
    int_src_a = (unsigned long *)(DMA_BASE + DMA_INT_SRC_A),
14
    int_src_b = (unsigned long *)(DMA_BASE + DMA_INT_SRC_B),
15
    ch0_csr = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_CSR),
16
    ch0_sz = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_SZ),
17
    ch0_a0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A0),
18
    ch0_am0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM0),
19
    ch0_a1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A1),
20
    ch0_am1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM1),
21
    ch0_desc = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_DESC);
22
 
23
struct DMA_DESCRIPTOR
24
{
25
    unsigned long csr;
26
    unsigned long adr0;
27
    unsigned long adr1;
28
    unsigned long next;
29
};
30
 
31
 
32
/* Test simplest DMA operation */
33
int simple( void )
34
{
35
    int ok;
36
    unsigned long src[2], dst[2];
37
 
38
    /* Set transfer Size */
39
    *ch0_sz = 0x00000002;
40
 
41
    /* Set addresses */
42
    *ch0_a0 = (unsigned long)src;
43
    *ch0_a1 = (unsigned long)dst;
44
 
45
    /* Fill source */
46
    src[0] = 0x01234567LU;
47
    src[1] = 0x89ABCDEFLU;
48
 
49
    /* Now set channel CSR */
50
    *ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, INC_SRC ) | FLAG_MASK( DMA_CH_CSR, INC_DST );
51
 
52
    /* Wait till the channel finishes */
53
    while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
54
        ;
55
 
56
    /* Dump contents of memory */
57
    ok = (dst[0] == src[0] && dst[1] == src[1]);
58
    report( ok );
59
 
60
    return ok;
61
}
62
 
63
 
64
/* Test simple transfer with chunks */
65
int chunks( void )
66
{
67
    unsigned i, ok;
68
    unsigned long src[6], dst[6];
69
 
70
    /* Set transfer size */
71
    *ch0_sz = 6LU | (3LU << DMA_CH_SZ_CHK_SZ_OFFSET);
72
 
73
    /* Set addresses */
74
    *ch0_a0 = (unsigned long)src;
75
    *ch0_a1 = (unsigned long)dst;
76
 
77
    /* Fill source */
78
    for ( i = 0; i < 6; ++ i )
79
        src[i] = 0xA63F879CLU + i;
80
 
81
    /* Now set channel CSR */
82
    *ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, INC_SRC ) | FLAG_MASK( DMA_CH_CSR, INC_DST );
83
 
84
    /* Wait till the channel finishes */
85
    while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
86
        ;
87
 
88
    /* Dump contents of memory */
89
    ok = 1;
90
    for ( i = 0; i < 6 && ok; ++ i )
91
        if ( dst[i] != src[i] )
92
            ok = 0;
93
    report( i );
94
 
95
    return ok;
96
}
97
 
98
/* Test transfer using linked list */
99
int list( void )
100
{
101
    struct DMA_DESCRIPTOR desc[2];
102
    unsigned long src[10], dst[10];
103
    unsigned i, ok;
104
 
105
    /* Set transfer size for each list element */
106
    desc[0].csr = 6;
107
    desc[1].csr = 4;
108
 
109
    /* Set chunk size */
110
    *ch0_sz = 2UL << DMA_CH_SZ_CHK_SZ_OFFSET;
111
 
112
    /* Set addresses */
113
    desc[0].adr0 = (unsigned long)src;
114
    desc[0].adr1 = (unsigned long)dst;
115
    desc[1].adr0 = (unsigned long)(src + 6);
116
    desc[1].adr1 = (unsigned long)(dst + 6);
117
 
118
    /* Fill source */
119
    for ( i = 0; i < 10; ++ i )
120
        src[i] = 0x110BD540FLU + i;
121
 
122
    /* Set descriptor CSR */
123
    desc[0].csr |= FLAG_MASK( DMA_DESC_CSR, INC_SRC ) | FLAG_MASK( DMA_DESC_CSR, INC_DST );
124
    desc[1].csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC ) | FLAG_MASK( DMA_DESC_CSR, INC_DST );
125
 
126
    /* Point channel to descriptor */
127
    *ch0_desc = (unsigned)desc;
128
 
129
    /* Link the list */
130
    desc[0].next = (unsigned)&(desc[1]);
131
    desc[1].next = 0xDEADDEADUL;
132
 
133
    /* Set channel CSR */
134
    *ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, USE_ED );
135
 
136
    /* Wait till the channel finishes */
137
    while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
138
        ;
139
 
140
    ok = TEST_FLAG( *ch0_csr, DMA_CH_CSR, DONE );
141
 
142
    /* Dump contents of memory */
143
    for ( i = 0; i < 10 && ok; ++ i )
144
        if ( dst[i] != src[i] )
145
            ok = 0;
146
    report( i );
147
 
148
    return ok;
149
}
150
 
151
 
152
int main()
153
{
154 310 markom
    int pass_simple, pass_chunks, pass_list;
155 1024 simons
    printf( "Starting DMA test\n" );
156 258 erez
 
157 1024 simons
    printf( "  Simple DMA: " );
158
    printf( (pass_simple = simple()) ? "Passed\n" : "Failed\n" );
159
    printf( "  Chunks DMA: " );
160
    printf( (pass_chunks = chunks()) ? "Passed\n" : "Failed\n" );
161
    printf( "  List DMA: " );
162
    printf( (pass_list = list()) ? "Passed\n" : "Failed\n" );
163 258 erez
 
164 1024 simons
    printf( "Ending DMA test\n" );
165 310 markom
    if (pass_simple && pass_chunks && pass_list) {
166
        report (0xdeaddead);
167
        return 0;
168
    } else
169
        return 3 - pass_simple - pass_chunks - pass_list;
170 258 erez
}
171
 
172
 

powered by: WebSVN 2.1.0

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