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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [testbench/] [dmatest.c] - Blame information for rev 258

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

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

powered by: WebSVN 2.1.0

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