| 1 |
90 |
jeremybenn |
/* dmatest.c. Test of Or1ksim DMA
|
| 2 |
|
|
|
| 3 |
|
|
Copyright (C) 1999-2006 OpenCores
|
| 4 |
|
|
Copyright (C) 2010 Embecosm Limited
|
| 5 |
|
|
|
| 6 |
|
|
Contributors various OpenCores participants
|
| 7 |
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
| 8 |
|
|
|
| 9 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
| 10 |
|
|
|
| 11 |
|
|
This program is free software; you can redistribute it and/or modify it
|
| 12 |
|
|
under the terms of the GNU General Public License as published by the Free
|
| 13 |
|
|
Software Foundation; either version 3 of the License, or (at your option)
|
| 14 |
|
|
any later version.
|
| 15 |
|
|
|
| 16 |
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
| 17 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 18 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 19 |
|
|
more details.
|
| 20 |
|
|
|
| 21 |
|
|
You should have received a copy of the GNU General Public License along
|
| 22 |
|
|
with this program. If not, see <http: www.gnu.org/licenses/>. */
|
| 23 |
|
|
|
| 24 |
|
|
/* ----------------------------------------------------------------------------
|
| 25 |
|
|
This code is commented throughout for use with Doxygen.
|
| 26 |
|
|
--------------------------------------------------------------------------*/
|
| 27 |
|
|
|
| 28 |
|
|
#include "support.h"
|
| 29 |
|
|
#include "board.h"
|
| 30 |
|
|
|
| 31 |
|
|
/* Includes from main peripheral directory */
|
| 32 |
|
|
#include "fields.h"
|
| 33 |
|
|
#include "dma-defs.h"
|
| 34 |
|
|
|
| 35 |
|
|
typedef volatile unsigned long *DMA_REG;
|
| 36 |
|
|
|
| 37 |
|
|
DMA_REG csr = (unsigned long *)(DMA_BASE + DMA_CSR),
|
| 38 |
|
|
int_msk_a = (unsigned long *)(DMA_BASE + DMA_INT_MSK_A),
|
| 39 |
|
|
int_msk_b = (unsigned long *)(DMA_BASE + DMA_INT_MSK_B),
|
| 40 |
|
|
int_src_a = (unsigned long *)(DMA_BASE + DMA_INT_SRC_A),
|
| 41 |
|
|
int_src_b = (unsigned long *)(DMA_BASE + DMA_INT_SRC_B),
|
| 42 |
|
|
ch0_csr = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_CSR),
|
| 43 |
|
|
ch0_sz = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_SZ),
|
| 44 |
|
|
ch0_a0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A0),
|
| 45 |
|
|
ch0_am0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM0),
|
| 46 |
|
|
ch0_a1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A1),
|
| 47 |
|
|
ch0_am1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM1),
|
| 48 |
|
|
ch0_desc = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_DESC);
|
| 49 |
|
|
|
| 50 |
|
|
struct DMA_DESCRIPTOR
|
| 51 |
|
|
{
|
| 52 |
|
|
unsigned long csr;
|
| 53 |
|
|
unsigned long adr0;
|
| 54 |
|
|
unsigned long adr1;
|
| 55 |
|
|
unsigned long next;
|
| 56 |
|
|
};
|
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
/* Test simplest DMA operation */
|
| 60 |
|
|
int simple( void )
|
| 61 |
|
|
{
|
| 62 |
|
|
int ok;
|
| 63 |
|
|
unsigned long src[2], dst[2];
|
| 64 |
|
|
|
| 65 |
|
|
/* Set transfer Size */
|
| 66 |
|
|
*ch0_sz = 0x00000002;
|
| 67 |
|
|
|
| 68 |
|
|
/* Set addresses */
|
| 69 |
|
|
*ch0_a0 = (unsigned long)src;
|
| 70 |
|
|
*ch0_a1 = (unsigned long)dst;
|
| 71 |
|
|
|
| 72 |
|
|
/* Fill source */
|
| 73 |
|
|
src[0] = 0x01234567LU;
|
| 74 |
|
|
src[1] = 0x89ABCDEFLU;
|
| 75 |
|
|
|
| 76 |
|
|
/* Now set channel CSR */
|
| 77 |
|
|
*ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, INC_SRC ) | FLAG_MASK( DMA_CH_CSR, INC_DST );
|
| 78 |
|
|
|
| 79 |
|
|
/* Wait till the channel finishes */
|
| 80 |
|
|
while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
|
| 81 |
|
|
;
|
| 82 |
|
|
|
| 83 |
|
|
/* Dump contents of memory */
|
| 84 |
|
|
ok = (dst[0] == src[0] && dst[1] == src[1]);
|
| 85 |
|
|
report( ok );
|
| 86 |
|
|
|
| 87 |
|
|
return ok;
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
|
|
|
| 91 |
|
|
/* Test simple transfer with chunks */
|
| 92 |
|
|
int chunks( void )
|
| 93 |
|
|
{
|
| 94 |
|
|
unsigned i, ok;
|
| 95 |
|
|
unsigned long src[6], dst[6];
|
| 96 |
|
|
|
| 97 |
|
|
/* Set transfer size */
|
| 98 |
|
|
*ch0_sz = 6LU | (3LU << DMA_CH_SZ_CHK_SZ_OFFSET);
|
| 99 |
|
|
|
| 100 |
|
|
/* Set addresses */
|
| 101 |
|
|
*ch0_a0 = (unsigned long)src;
|
| 102 |
|
|
*ch0_a1 = (unsigned long)dst;
|
| 103 |
|
|
|
| 104 |
|
|
/* Fill source */
|
| 105 |
|
|
for ( i = 0; i < 6; ++ i )
|
| 106 |
|
|
src[i] = 0xA63F879CLU + i;
|
| 107 |
|
|
|
| 108 |
|
|
/* Now set channel CSR */
|
| 109 |
|
|
*ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, INC_SRC ) | FLAG_MASK( DMA_CH_CSR, INC_DST );
|
| 110 |
|
|
|
| 111 |
|
|
/* Wait till the channel finishes */
|
| 112 |
|
|
while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
|
| 113 |
|
|
;
|
| 114 |
|
|
|
| 115 |
|
|
/* Dump contents of memory */
|
| 116 |
|
|
ok = 1;
|
| 117 |
|
|
for ( i = 0; i < 6 && ok; ++ i )
|
| 118 |
|
|
if ( dst[i] != src[i] )
|
| 119 |
|
|
ok = 0;
|
| 120 |
|
|
report( i );
|
| 121 |
|
|
|
| 122 |
|
|
return ok;
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
/* Test transfer using linked list */
|
| 126 |
|
|
int list( void )
|
| 127 |
|
|
{
|
| 128 |
|
|
struct DMA_DESCRIPTOR desc[2];
|
| 129 |
|
|
unsigned long src[10], dst[10];
|
| 130 |
|
|
unsigned i, ok;
|
| 131 |
|
|
|
| 132 |
|
|
/* Set transfer size for each list element */
|
| 133 |
|
|
desc[0].csr = 6;
|
| 134 |
|
|
desc[1].csr = 4;
|
| 135 |
|
|
|
| 136 |
|
|
/* Set chunk size */
|
| 137 |
|
|
*ch0_sz = 2UL << DMA_CH_SZ_CHK_SZ_OFFSET;
|
| 138 |
|
|
|
| 139 |
|
|
/* Set addresses */
|
| 140 |
|
|
desc[0].adr0 = (unsigned long)src;
|
| 141 |
|
|
desc[0].adr1 = (unsigned long)dst;
|
| 142 |
|
|
desc[1].adr0 = (unsigned long)(src + 6);
|
| 143 |
|
|
desc[1].adr1 = (unsigned long)(dst + 6);
|
| 144 |
|
|
|
| 145 |
|
|
/* Fill source (original code had 0x110bd540fUL as the constant, but that
|
| 146 |
|
|
is more than 32-bits. */
|
| 147 |
|
|
for ( i = 0; i < 10; ++ i )
|
| 148 |
|
|
src[i] = 0x10bd540fUL + i;
|
| 149 |
|
|
|
| 150 |
|
|
/* Set descriptor CSR */
|
| 151 |
|
|
desc[0].csr |= FLAG_MASK( DMA_DESC_CSR, INC_SRC ) | FLAG_MASK( DMA_DESC_CSR, INC_DST );
|
| 152 |
|
|
desc[1].csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC ) | FLAG_MASK( DMA_DESC_CSR, INC_DST );
|
| 153 |
|
|
|
| 154 |
|
|
/* Point channel to descriptor */
|
| 155 |
|
|
*ch0_desc = (unsigned)desc;
|
| 156 |
|
|
|
| 157 |
|
|
/* Link the list */
|
| 158 |
|
|
desc[0].next = (unsigned)&(desc[1]);
|
| 159 |
|
|
desc[1].next = 0xDEADDEADUL;
|
| 160 |
|
|
|
| 161 |
|
|
/* Set channel CSR */
|
| 162 |
|
|
*ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) | FLAG_MASK( DMA_CH_CSR, USE_ED );
|
| 163 |
|
|
|
| 164 |
|
|
/* Wait till the channel finishes */
|
| 165 |
|
|
while ( TEST_FLAG( *ch0_csr, DMA_CH_CSR, BUSY ) )
|
| 166 |
|
|
;
|
| 167 |
|
|
|
| 168 |
|
|
ok = TEST_FLAG( *ch0_csr, DMA_CH_CSR, DONE );
|
| 169 |
|
|
|
| 170 |
|
|
/* Dump contents of memory */
|
| 171 |
|
|
for ( i = 0; i < 10 && ok; ++ i )
|
| 172 |
|
|
if ( dst[i] != src[i] )
|
| 173 |
|
|
ok = 0;
|
| 174 |
|
|
report( i );
|
| 175 |
|
|
|
| 176 |
|
|
return ok;
|
| 177 |
|
|
}
|
| 178 |
|
|
|
| 179 |
|
|
|
| 180 |
|
|
int main()
|
| 181 |
|
|
{
|
| 182 |
|
|
int pass_simple, pass_chunks, pass_list;
|
| 183 |
|
|
printf( "Starting DMA test\n" );
|
| 184 |
|
|
printf( " Simple DMA: " );
|
| 185 |
|
|
printf( (pass_simple = simple()) ? "Passed\n" : "Failed\n" );
|
| 186 |
|
|
printf( " Chunks DMA: " );
|
| 187 |
|
|
printf( (pass_chunks = chunks()) ? "Passed\n" : "Failed\n" );
|
| 188 |
|
|
printf( " List DMA: " );
|
| 189 |
|
|
printf( (pass_list = list()) ? "Passed\n" : "Failed\n" );
|
| 190 |
|
|
|
| 191 |
|
|
printf( "Ending DMA test\n" );
|
| 192 |
|
|
if (pass_simple && pass_chunks && pass_list) {
|
| 193 |
|
|
report (0xdeaddead);
|
| 194 |
|
|
return 0;
|
| 195 |
|
|
} else
|
| 196 |
|
|
return 3 - pass_simple - pass_chunks - pass_list;
|
| 197 |
|
|
}
|
| 198 |
|
|
|
| 199 |
|
|
|