Search
lxdream.org :: lxdream/test/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/asic.c
changeset 185:6755a04c447f
next193:31151fcc3cb7
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
/**
nkeynes@185
     2
 * $Id: asic.c,v 1.1 2006-07-11 01:35:23 nkeynes Exp $
nkeynes@185
     3
 * 
nkeynes@185
     4
 * General ASIC support code
nkeynes@185
     5
 *
nkeynes@185
     6
 * Copyright (c) 2006 Nathan Keynes.
nkeynes@185
     7
 *
nkeynes@185
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@185
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@185
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@185
    11
 * (at your option) any later version.
nkeynes@185
    12
 *
nkeynes@185
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@185
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@185
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@185
    16
 * GNU General Public License for more details.
nkeynes@185
    17
 */
nkeynes@185
    18
nkeynes@185
    19
#include "lib.h"
nkeynes@185
    20
nkeynes@185
    21
#define ASIC_BASE 0xA05F6000
nkeynes@185
    22
#define ASIC_PIRQ(n) (ASIC_BASE + 0x900 + (n<<2))
nkeynes@185
    23
#define ASIC_IRQA(n) (ASIC_BASE + 0x910 + (n<<2))
nkeynes@185
    24
#define ASIC_IRQB(n) (ASIC_BASE + 0x920 + (n<<2))
nkeynes@185
    25
#define ASIC_IRQC(n) (ASIC_BASE + 0x930 + (n<<2))
nkeynes@185
    26
#define TIMEOUT 10000000
nkeynes@185
    27
nkeynes@185
    28
/**
nkeynes@185
    29
 * Wait for an ASIC event. 
nkeynes@185
    30
 * @return 0 if the event occurred, otherwise -1 if the wait timed out.
nkeynes@185
    31
 */
nkeynes@185
    32
int asic_wait( int event )
nkeynes@185
    33
{
nkeynes@185
    34
    int n = event >> 5;
nkeynes@185
    35
    unsigned int mask = (1<< (event&0x1f));
nkeynes@185
    36
    int i;
nkeynes@185
    37
    for( i=0; i<TIMEOUT; i++ ) {
nkeynes@185
    38
	if( long_read(ASIC_PIRQ(n)) & mask ) {
nkeynes@185
    39
	    return 0;
nkeynes@185
    40
	}
nkeynes@185
    41
    }
nkeynes@185
    42
    return -1; /* Timeout */
nkeynes@185
    43
}
nkeynes@185
    44
nkeynes@185
    45
/**
nkeynes@185
    46
 * Clear all asic events
nkeynes@185
    47
 */
nkeynes@185
    48
void asic_clear()
nkeynes@185
    49
{
nkeynes@185
    50
    long_write(ASIC_PIRQ(0), 0xFFFFFFFF);
nkeynes@185
    51
    long_write(ASIC_PIRQ(1), 0xFFFFFFFF);
nkeynes@185
    52
    long_write(ASIC_PIRQ(2), 0xFFFFFFFF);
nkeynes@185
    53
}
nkeynes@185
    54
nkeynes@185
    55
void asic_mask_all()
nkeynes@185
    56
{
nkeynes@185
    57
    long_write(ASIC_IRQA(0), 0);
nkeynes@185
    58
    long_write(ASIC_IRQA(1), 0);
nkeynes@185
    59
    long_write(ASIC_IRQA(2), 0);
nkeynes@185
    60
    long_write(ASIC_IRQB(0), 0);
nkeynes@185
    61
    long_write(ASIC_IRQB(1), 0);
nkeynes@185
    62
    long_write(ASIC_IRQB(2), 0);
nkeynes@185
    63
    long_write(ASIC_IRQC(0), 0);
nkeynes@185
    64
    long_write(ASIC_IRQC(1), 0);
nkeynes@185
    65
    long_write(ASIC_IRQC(2), 0);
nkeynes@185
    66
}
nkeynes@185
    67
nkeynes@185
    68
/**
nkeynes@185
    69
 * Print the contents of the ASIC event registers to the supplied FILE
nkeynes@185
    70
 */
nkeynes@185
    71
void asic_dump( FILE *f )
nkeynes@185
    72
{
nkeynes@185
    73
    int i,j;
nkeynes@185
    74
    fprintf( f, "Events: " );
nkeynes@185
    75
    for( i=0; i<3; i++ ) {
nkeynes@185
    76
	uint32_t val = long_read(ASIC_PIRQ(i));
nkeynes@185
    77
	for( j=0; j<32; j++ ) {
nkeynes@185
    78
	    if( val & (1<<j) ) {
nkeynes@185
    79
		fprintf( f, "%d ", (i<<5)+j );
nkeynes@185
    80
	    }
nkeynes@185
    81
	}
nkeynes@185
    82
    }
nkeynes@185
    83
    fprintf( f, "\n" );
nkeynes@185
    84
}
.