Search
lxdream.org :: lxdream/test/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/asic.c
changeset 561:533f6b478071
prev193:31151fcc3cb7
next753:1fe39c3a9bbc
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@185
     1
/**
nkeynes@561
     2
 * $Id$
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@193
    55
int asic_check( int event ) 
nkeynes@193
    56
{
nkeynes@193
    57
    int n = event >> 5;
nkeynes@193
    58
    unsigned int mask = (1<< (event&0x1f));
nkeynes@193
    59
    return (long_read(ASIC_PIRQ(n)) & mask) != 0;
nkeynes@193
    60
}
nkeynes@193
    61
nkeynes@185
    62
void asic_mask_all()
nkeynes@185
    63
{
nkeynes@185
    64
    long_write(ASIC_IRQA(0), 0);
nkeynes@185
    65
    long_write(ASIC_IRQA(1), 0);
nkeynes@185
    66
    long_write(ASIC_IRQA(2), 0);
nkeynes@185
    67
    long_write(ASIC_IRQB(0), 0);
nkeynes@185
    68
    long_write(ASIC_IRQB(1), 0);
nkeynes@185
    69
    long_write(ASIC_IRQB(2), 0);
nkeynes@185
    70
    long_write(ASIC_IRQC(0), 0);
nkeynes@185
    71
    long_write(ASIC_IRQC(1), 0);
nkeynes@185
    72
    long_write(ASIC_IRQC(2), 0);
nkeynes@185
    73
}
nkeynes@185
    74
nkeynes@185
    75
/**
nkeynes@185
    76
 * Print the contents of the ASIC event registers to the supplied FILE
nkeynes@185
    77
 */
nkeynes@185
    78
void asic_dump( FILE *f )
nkeynes@185
    79
{
nkeynes@185
    80
    int i,j;
nkeynes@185
    81
    fprintf( f, "Events: " );
nkeynes@185
    82
    for( i=0; i<3; i++ ) {
nkeynes@185
    83
	uint32_t val = long_read(ASIC_PIRQ(i));
nkeynes@185
    84
	for( j=0; j<32; j++ ) {
nkeynes@185
    85
	    if( val & (1<<j) ) {
nkeynes@185
    86
		fprintf( f, "%d ", (i<<5)+j );
nkeynes@185
    87
	    }
nkeynes@185
    88
	}
nkeynes@185
    89
    }
nkeynes@185
    90
    fprintf( f, "\n" );
nkeynes@185
    91
}
.