Search
lxdream.org :: lxdream/test/testide.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/testide.c
changeset 185:6755a04c447f
next248:f8022f2ef2a2
author nkeynes
date Tue Jul 11 01:35:27 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change First commit of system test framework. 3 initial test cases (incomplete):
testide, testmath, and testta
file annotate diff log raw
nkeynes@185
     1
#include <assert.h>
nkeynes@185
     2
#include <ctype.h>
nkeynes@185
     3
#include "ide.h"
nkeynes@185
     4
void debug_dump_buffer(char *buf, int length)
nkeynes@185
     5
{
nkeynes@185
     6
    int i,j;
nkeynes@185
     7
    for( i=0; i<length; i+=16 ) {
nkeynes@185
     8
	printf( "%08X: ", i );
nkeynes@185
     9
        for( j=0; j<16 && i+j < length; j+=4 ) {
nkeynes@185
    10
	    unsigned int val = *((volatile unsigned int *)(buf+i+j));
nkeynes@185
    11
	    printf( "%02X %02X %02X %02X  ", val&0xFF, (val>>8)&0xFF, (val>>16)&0xFF, (val>>24)&0xFF );
nkeynes@185
    12
        }
nkeynes@185
    13
	for( j=0; j<16 && i+j < length; j++ ) {
nkeynes@185
    14
	    printf( "%c", isprint(buf[i+j]) ? buf[i+j] : '.' );
nkeynes@185
    15
	}
nkeynes@185
    16
	printf("\n");
nkeynes@185
    17
    }
nkeynes@185
    18
}
nkeynes@185
    19
nkeynes@185
    20
void debug_dump_int_buffer(volatile char *buf, int length)
nkeynes@185
    21
{
nkeynes@185
    22
    int i,j;
nkeynes@185
    23
    for( i=0; i<length; i+=16 ) {
nkeynes@185
    24
	printf( "%08X:", i );
nkeynes@185
    25
        for( j=0; j<16 && i+j < length; j+=4 ) {
nkeynes@185
    26
	    printf( " %08X", *((volatile unsigned int *)(buf+i+j)) );
nkeynes@185
    27
        }
nkeynes@185
    28
	printf( "\n" );
nkeynes@185
    29
    }
nkeynes@185
    30
}
nkeynes@185
    31
nkeynes@185
    32
nkeynes@185
    33
char buf[2048*7 + 32];
nkeynes@185
    34
nkeynes@185
    35
int test_ide_read_bootstrap()
nkeynes@185
    36
{
nkeynes@185
    37
    struct gdrom_session session;
nkeynes@185
    38
    int length;
nkeynes@185
    39
    char *p;
nkeynes@185
    40
nkeynes@185
    41
    ide_init();
nkeynes@185
    42
nkeynes@185
    43
    if( ide_test_ready() != 0 ) {
nkeynes@185
    44
	printf( "ERROR - Test ready failed\n" );
nkeynes@185
    45
	return -1;
nkeynes@185
    46
    }
nkeynes@185
    47
nkeynes@185
    48
    if( ide_spinup() != 0 ) {
nkeynes@185
    49
	printf( "ERROR - Spinup failed\n" );
nkeynes@185
    50
	return -1;
nkeynes@185
    51
    }
nkeynes@185
    52
nkeynes@185
    53
    /*
nkeynes@185
    54
    length = ide_unknown71( buf, sizeof(buf) );
nkeynes@185
    55
    if( length == -1 ) {
nkeynes@185
    56
	printf( "ERROR - 0x71 failed\n" );
nkeynes@185
    57
	ide_print_sense_error();
nkeynes@185
    58
	return -1;
nkeynes@185
    59
    }
nkeynes@185
    60
    debug_dump_buffer(buf,length);
nkeynes@185
    61
    */
nkeynes@185
    62
    if( ide_get_session( 0, &session ) == -1 ) {
nkeynes@185
    63
	printf( "ERROR - Get session(0) failed\n" );
nkeynes@185
    64
	return -1;
nkeynes@185
    65
    }
nkeynes@185
    66
    if( ide_get_session( session.track, &session ) == -1 ) {
nkeynes@185
    67
	printf( "ERROR - Get session(%d) failed\n", session.track );
nkeynes@185
    68
	return -1;
nkeynes@185
    69
    }
nkeynes@185
    70
nkeynes@185
    71
    p = (char *)((((unsigned int)buf) & 0xFFFFFFE0) + 0x20);
nkeynes@185
    72
    printf( "--- DMA buffer: %08X\n",  p );
nkeynes@185
    73
    length = ide_read_sector_dma( session.lba, 2, 0x28, p, 2048*2 );
nkeynes@185
    74
    if( length != 2048*2 ) {
nkeynes@185
    75
	printf( "ERROR - Got incorrect read length, expected %d but was %d\n", 2048, length );
nkeynes@185
    76
	return -1;
nkeynes@185
    77
    }
nkeynes@185
    78
    debug_dump_buffer( p, 2048*2 );
nkeynes@185
    79
    
nkeynes@185
    80
    return 0;
nkeynes@185
    81
}
nkeynes@185
    82
nkeynes@185
    83
nkeynes@185
    84
int main( int argc, char *argv[] )
nkeynes@185
    85
{
nkeynes@185
    86
    ide_dump_registers();
nkeynes@185
    87
    ide_spinup();
nkeynes@185
    88
    ide_read_something();
nkeynes@185
    89
//    test_ide_read_bootstrap();
nkeynes@185
    90
}
.